Hotfix on repairs

This commit is contained in:
Ben Sarmiento
2023-12-06 00:49:11 +01:00
parent de868d97c2
commit 121a28d46f
4 changed files with 44 additions and 38 deletions

2
.gitignore vendored
View File

@@ -37,3 +37,5 @@ error_codes.json
memlog.sh
stressTestAddRemove.py
*.zip
pkg/anidb/

View File

@@ -3,6 +3,7 @@ package config
import "math/rand"
type ConfigInterface interface {
GetConfig() ZurgConfig
GetVersion() string
GetToken() string
GetNumOfWorkers() int
@@ -26,24 +27,28 @@ type ConfigInterface interface {
}
type ZurgConfig struct {
Version string `yaml:"zurg"`
Token string `yaml:"token"`
Host string `yaml:"host"`
Port string `yaml:"port"`
NumOfWorkers int `yaml:"concurrent_workers"`
RefreshEverySeconds int `yaml:"check_for_changes_every_secs"`
CanRepair bool `yaml:"enable_repair"`
OnLibraryUpdate string `yaml:"on_library_update"`
NetworkBufferSize int `yaml:"network_buffer_size"`
RateLimitSleepSeconds int `yaml:"rate_limit_sleep_secs"`
RetainFolderNameExtension bool `yaml:"retain_folder_name_extension"`
RetainRDTorrentName bool `yaml:"retain_rd_torrent_name"`
PreferredHosts []string `yaml:"preferred_hosts"`
ServeFromRclone bool `yaml:"serve_from_rclone"`
ForceIPv6 bool `yaml:"force_ipv6"`
RealDebridTimeout int `yaml:"realdebrid_timeout_secs"`
RetriesUntilFailed int `yaml:"retries_until_failed"`
UseDownloadCache bool `yaml:"use_download_cache"`
Version string `yaml:"zurg" json:"-"`
Token string `yaml:"token" json:"-"`
Host string `yaml:"host" json:"host"`
Port string `yaml:"port" json:"port"`
NumOfWorkers int `yaml:"concurrent_workers" json:"concurrent_workers"`
RefreshEverySeconds int `yaml:"check_for_changes_every_secs" json:"check_for_changes_every_secs"`
CanRepair bool `yaml:"enable_repair" json:"enable_repair"`
OnLibraryUpdate string `yaml:"on_library_update" json:"on_library_update"`
NetworkBufferSize int `yaml:"network_buffer_size" json:"network_buffer_size"`
RateLimitSleepSeconds int `yaml:"rate_limit_sleep_secs" json:"rate_limit_sleep_secs"`
RetainFolderNameExtension bool `yaml:"retain_folder_name_extension" json:"retain_folder_name_extension"`
RetainRDTorrentName bool `yaml:"retain_rd_torrent_name" json:"retain_rd_torrent_name"`
PreferredHosts []string `yaml:"preferred_hosts" json:"preferred_hosts"`
ServeFromRclone bool `yaml:"serve_from_rclone" json:"serve_from_rclone"`
ForceIPv6 bool `yaml:"force_ipv6" json:"force_ipv6"`
RealDebridTimeout int `yaml:"realdebrid_timeout_secs" json:"realdebrid_timeout_secs"`
RetriesUntilFailed int `yaml:"retries_until_failed" json:"retries_until_failed"`
UseDownloadCache bool `yaml:"use_download_cache" json:"use_download_cache"`
}
func (z *ZurgConfig) GetConfig() ZurgConfig {
return *z
}
func (z *ZurgConfig) GetToken() string {

View File

@@ -183,18 +183,19 @@ type SponsorResponse struct {
Paypal string `json:"paypal"`
}
type RootResponse struct {
Version string `json:"version"`
BuiltAt string `json:"built_at"`
GitCommit string `json:"git_commit"`
Dav string `json:"dav"`
Html string `json:"html"`
UserInfo *realdebrid.User `json:"user_info"` // Replace UserInfoType with the actual type
MemAlloc uint64 `json:"mem_alloc"` // Memory allocation in MB
TotalAlloc uint64 `json:"total_alloc"` // Total memory allocated in MB
Sys uint64 `json:"sys"` // System memory in MB
NumGC uint32 `json:"num_gc"` // Number of completed GC cycles
PID int `json:"pid"` // Process ID
Sponsor SponsorResponse `json:"sponsor_zurg"` // Sponsorship links
Version string `json:"version"`
BuiltAt string `json:"built_at"`
GitCommit string `json:"git_commit"`
Dav string `json:"dav"`
Html string `json:"html"`
UserInfo *realdebrid.User `json:"user_info"` // Replace UserInfoType with the actual type
MemAlloc uint64 `json:"mem_alloc"` // Memory allocation in MB
TotalAlloc uint64 `json:"total_alloc"` // Total memory allocated in MB
Sys uint64 `json:"sys"` // System memory in MB
NumGC uint32 `json:"num_gc"` // Number of completed GC cycles
PID int `json:"pid"` // Process ID
Sponsor SponsorResponse `json:"sponsor_zurg"` // Sponsorship links
Config config.ZurgConfig `json:"config"`
}
func (zr *ZurgRouter) rootHandler(resp http.ResponseWriter, req *http.Request, params httprouter.Params) {
@@ -224,6 +225,7 @@ func (zr *ZurgRouter) rootHandler(resp http.ResponseWriter, req *http.Request, p
Github: "https://github.com/sponsors/debridmediamanager",
Paypal: "https://paypal.me/yowmamasita",
},
Config: zr.cfg.GetConfig(),
}
if err := json.NewEncoder(resp).Encode(response); err != nil {

View File

@@ -581,13 +581,13 @@ func (t *TorrentManager) repair(torrent *Torrent) {
return
}
// first solution: add the same selection, maybe it can be fixed by reinsertion?
// first solution: reinsert with same selection
if t.reinsertTorrent(torrent, "") {
t.log.Infof("Successfully downloaded torrent %s to repair it", torrent.AccessKey)
return
}
// if all the selected files are missing but there are other streamable files
// second solution: add only the missing files
var missingFiles []File
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
if !strings.HasPrefix(file.Link, "http") {
@@ -629,14 +629,11 @@ func (t *TorrentManager) reinsertTorrent(torrent *Torrent, missingFiles string)
if missingFiles == "" {
tmpSelection := ""
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
if !strings.HasPrefix(file.Link, "http") {
tmpSelection += fmt.Sprintf("%d,", file.ID)
}
tmpSelection += fmt.Sprintf("%d,", file.ID) // select all files
})
if tmpSelection == "" {
return false
}
if len(tmpSelection) > 0 {
return true // nothing to repair
} else {
missingFiles = tmpSelection[:len(tmpSelection)-1]
}
}