- Fix nil checks
- Enable add arr to config page - Other minor fixes
This commit is contained in:
@@ -621,13 +621,12 @@ func (c *Cache) GetClient() types.Client {
|
||||
}
|
||||
|
||||
func (c *Cache) DeleteTorrent(id string) error {
|
||||
c.logger.Info().Msgf("Deleting torrent %s from cache", id)
|
||||
c.torrentsRefreshMu.Lock()
|
||||
defer c.torrentsRefreshMu.Unlock()
|
||||
|
||||
if c.deleteTorrent(id, true) {
|
||||
c.RefreshListings(true)
|
||||
c.logger.Info().Msgf("Torrent %s deleted successfully", id)
|
||||
c.logger.Trace().Msgf("Torrent %s deleted successfully", id)
|
||||
return nil
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -55,12 +55,16 @@ func (c *Cache) IsTorrentBroken(t *CachedTorrent, filenames []string) bool {
|
||||
// Check if file is missing
|
||||
if f.Link == "" {
|
||||
// refresh torrent and then break
|
||||
t = c.refreshTorrent(t)
|
||||
break
|
||||
if newT := c.refreshTorrent(t); newT != nil {
|
||||
t = newT
|
||||
} else {
|
||||
c.logger.Error().Str("torrentId", t.Torrent.Id).Msg("Failed to refresh torrent")
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if t == nil || t.Torrent == nil {
|
||||
if t.Torrent == nil {
|
||||
c.logger.Error().Str("torrentId", t.Torrent.Id).Msg("Failed to refresh torrent")
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -222,39 +222,44 @@ func (q *QBit) createSymlinks(debridTorrent *debrid.Torrent, rclonePath, torrent
|
||||
return "", fmt.Errorf("failed to create directory: %s: %v", symlinkPath, err)
|
||||
}
|
||||
|
||||
pending := make(map[string]debrid.File)
|
||||
remainingFiles := make(map[string]debrid.File)
|
||||
for _, file := range files {
|
||||
pending[file.Path] = file
|
||||
remainingFiles[file.Path] = file
|
||||
}
|
||||
ticker := time.NewTicker(10 * time.Millisecond)
|
||||
defer ticker.Stop()
|
||||
filePaths := make([]string, 0, len(pending))
|
||||
|
||||
for len(pending) > 0 {
|
||||
<-ticker.C
|
||||
for path, file := range pending {
|
||||
fullFilePath := filepath.Join(rclonePath, file.Name)
|
||||
if _, err := os.Stat(fullFilePath); !os.IsNotExist(err) {
|
||||
q.logger.Info().Msgf("File is ready: %s", file.Name)
|
||||
fileSymlinkPath := filepath.Join(symlinkPath, file.Name)
|
||||
if err := os.Symlink(fullFilePath, fileSymlinkPath); err != nil && !os.IsExist(err) {
|
||||
q.logger.Debug().Msgf("Failed to create symlink: %s: %v", fileSymlinkPath, err)
|
||||
}
|
||||
filePaths = append(filePaths, fileSymlinkPath)
|
||||
delete(pending, path)
|
||||
} else if file.Name != file.Path {
|
||||
// This is likely alldebrid nested files(not using webdav)
|
||||
fullFilePath = filepath.Join(rclonePath, file.Path)
|
||||
if _, err := os.Stat(fullFilePath); !os.IsNotExist(err) {
|
||||
q.logger.Info().Msgf("File is ready: %s", file.Path)
|
||||
fileSymlinkPath := filepath.Join(symlinkPath, file.Path)
|
||||
ticker := time.NewTicker(100 * time.Millisecond)
|
||||
defer ticker.Stop()
|
||||
timeout := time.After(30 * time.Minute)
|
||||
filePaths := make([]string, 0, len(files))
|
||||
|
||||
for len(remainingFiles) > 0 {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
entries, err := os.ReadDir(rclonePath)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
// Check which files exist in this batch
|
||||
for _, entry := range entries {
|
||||
filename := entry.Name()
|
||||
if file, exists := remainingFiles[filename]; exists {
|
||||
fullFilePath := filepath.Join(rclonePath, filename)
|
||||
fileSymlinkPath := filepath.Join(symlinkPath, file.Name)
|
||||
|
||||
if err := os.Symlink(fullFilePath, fileSymlinkPath); err != nil && !os.IsExist(err) {
|
||||
q.logger.Debug().Msgf("Failed to create symlink: %s: %v", fileSymlinkPath, err)
|
||||
} else {
|
||||
filePaths = append(filePaths, fileSymlinkPath)
|
||||
delete(remainingFiles, filename)
|
||||
q.logger.Info().Msgf("File is ready: %s", file.Name)
|
||||
}
|
||||
filePaths = append(filePaths, fileSymlinkPath)
|
||||
delete(pending, path)
|
||||
}
|
||||
}
|
||||
|
||||
case <-timeout:
|
||||
q.logger.Warn().Msgf("Timeout waiting for files, %d files still pending", len(remainingFiles))
|
||||
return symlinkPath, fmt.Errorf("timeout waiting for files")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -267,10 +272,9 @@ func (q *QBit) createSymlinks(debridTorrent *debrid.Torrent, rclonePath, torrent
|
||||
if err := q.preCacheFile(debridTorrent.Name, filePaths); err != nil {
|
||||
q.logger.Error().Msgf("Failed to pre-cache file: %s", err)
|
||||
} else {
|
||||
q.logger.Debug().Msgf("Pre-cached %d files", len(filePaths))
|
||||
q.logger.Trace().Msgf("Pre-cached %d files", len(filePaths))
|
||||
}
|
||||
}() // Pre-cache the files in the background
|
||||
// Pre-cache the first 256KB and 1MB of the file
|
||||
return symlinkPath, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -103,8 +103,6 @@ func (q *QBit) ProcessFiles(torrent *Torrent, debridTorrent *debrid.Torrent, arr
|
||||
)
|
||||
debridTorrent.Arr = arr
|
||||
|
||||
// File is done downloading at this stage
|
||||
|
||||
// Check if debrid supports webdav by checking cache
|
||||
if isSymlink {
|
||||
cache, ok := svc.Debrid.Caches[debridTorrent.Debrid]
|
||||
|
||||
@@ -241,6 +241,7 @@ func (ui *Handler) handleUpdateConfig(w http.ResponseWriter, r *http.Request) {
|
||||
DownloadUncached: a.DownloadUncached,
|
||||
})
|
||||
}
|
||||
currentConfig.Arrs = updatedConfig.Arrs
|
||||
if err := currentConfig.Save(); err != nil {
|
||||
http.Error(w, "Error saving config: "+err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
|
||||
@@ -228,7 +228,7 @@
|
||||
<div class="setup-step d-none" id="step4">
|
||||
<div class="section mb-5">
|
||||
<div id="arrConfigs"></div>
|
||||
<div class="mb-3 d-none">
|
||||
<div class="mb-3">
|
||||
<button type="button" id="addArrBtn" class="btn btn-secondary">
|
||||
<i class="bi bi-plus"></i> Add New Arr
|
||||
</button>
|
||||
|
||||
Reference in New Issue
Block a user