Delete if everything is unselected

This commit is contained in:
Ben Sarmiento
2023-11-21 14:16:53 +01:00
parent 0f336c15df
commit 48ad2bc3bf
6 changed files with 36 additions and 22 deletions

View File

@@ -26,13 +26,18 @@ jobs:
- name: Prepare artifacts - name: Prepare artifacts
run: | run: |
mkdir artifacts mkdir artifacts
mv zurg-* artifacts/ mv github.com/debridmediamanager.com/zurg/cmd/zurg-* artifacts/
# New step for compressing artifacts
- name: Compress artifacts
run: |
tar -czvf artifacts.tar.gz -C artifacts .
- name: Upload artifacts to workflow - name: Upload artifacts to workflow
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v3
with: with:
name: compiled-binaries name: compiled-binaries
path: artifacts/ path: artifacts.tar.gz
release: release:
needs: build needs: build
@@ -54,12 +59,13 @@ jobs:
draft: false draft: false
prerelease: false prerelease: false
# Ensure the asset_path matches the compressed file name
- name: Upload binaries to release - name: Upload binaries to release
uses: actions/upload-release-asset@v1 uses: actions/upload-release-asset@v1
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with: with:
upload_url: ${{ steps.create_release.outputs.upload_url }} upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./zurg-* asset_path: ./artifacts.tar.gz
asset_name: zurg-${{ github.run_number }}-${{ github.sha }} asset_name: zurg-${{ github.run_number }}-${{ github.sha }}.tar.gz
asset_content_type: application/octet-stream asset_content_type: application/gzip

View File

@@ -82,7 +82,8 @@ func handleDeleteFile(w http.ResponseWriter, segments []string, t *torrent.Torre
return fmt.Errorf("cannot find file %s", filepath) return fmt.Errorf("cannot find file %s", filepath)
} }
file.Link = "-" file.Link = "unselect"
t.SetChecksum("")
w.WriteHeader(http.StatusNoContent) w.WriteHeader(http.StatusNoContent)
return nil return nil
} }

View File

@@ -43,7 +43,7 @@ func Router(mux *http.ServeMux, c config.ConfigInterface, t *torrent.TorrentMana
case "PROPFIND": case "PROPFIND":
dav.HandlePropfindRequest(w, r, t, davlog) dav.HandlePropfindRequest(w, r, t, davlog)
case "DELETE": case http.MethodDelete:
dav.HandleDeleteRequest(w, r, t, davlog) dav.HandleDeleteRequest(w, r, t, davlog)
case http.MethodGet: case http.MethodGet:

View File

@@ -535,16 +535,24 @@ func (t *TorrentManager) repairAll() {
return return
} }
forRepair := false forRepair := false
unselected := 0
torrent.SelectedFiles.IterCb(func(_ string, file *File) { torrent.SelectedFiles.IterCb(func(_ string, file *File) {
if file.Link == "@" || file.ForRepair { if file.Link == "repair" {
t.log.Debugf("Found a file to repair for torrent %s", torrent.AccessKey) t.log.Debugf("Found a file to repair for torrent %s", torrent.AccessKey)
forRepair = true forRepair = true
} }
if file.Link == "unselect" {
unselected++
}
}) })
if forRepair { if forRepair {
t.log.Infof("Repairing %s", torrent.AccessKey) t.log.Infof("Repairing %s", torrent.AccessKey)
t.Repair(torrent.AccessKey) t.Repair(torrent.AccessKey)
} }
if unselected == torrent.SelectedFiles.Count() && unselected > 0 {
t.log.Infof("Deleting %s", torrent.AccessKey)
t.Delete(torrent.AccessKey)
}
}) })
} }
@@ -756,14 +764,17 @@ func (t *TorrentManager) canCapacityHandle() bool {
return true return true
} }
if retryCount >= maxRetries {
t.log.Error("Max retries reached, exiting")
return false
}
delay := time.Duration(math.Pow(2, float64(retryCount))) * baseDelay delay := time.Duration(math.Pow(2, float64(retryCount))) * baseDelay
if delay > maxDelay { if delay > maxDelay {
delay = maxDelay delay = maxDelay
} }
t.log.Infof("We have reached the max number of active torrents, waiting for %s seconds before retrying", delay)
if retryCount >= maxRetries {
t.log.Error("Max retries reached, exiting")
return false
}
time.Sleep(delay) time.Sleep(delay)
retryCount++ retryCount++
} }

View File

@@ -24,8 +24,7 @@ func (t *Torrent) InProgress() bool {
type File struct { type File struct {
realdebrid.File realdebrid.File
Added string Added string
Link string Link string
ZurgFS uint64 ZurgFS uint64
ForRepair bool
} }

View File

@@ -81,8 +81,7 @@ func HandleGetRequest(w http.ResponseWriter, r *http.Request, t *intTor.TorrentM
resp := t.UnrestrictUntilOk(link) resp := t.UnrestrictUntilOk(link)
if resp == nil { if resp == nil {
log.Warnf("File %s is no longer available", file.Path) log.Warnf("File %s is no longer available", file.Path)
file.Link = "@" file.Link = "repair"
file.ForRepair = true
t.SetChecksum("") // force a recheck t.SetChecksum("") // force a recheck
streamErrorVideo("https://www.youtube.com/watch?v=gea_FJrtFVA", w, r, t, c, log) streamErrorVideo("https://www.youtube.com/watch?v=gea_FJrtFVA", w, r, t, c, log)
} else { } else {
@@ -127,8 +126,7 @@ func streamFileToResponse(file *intTor.File, url string, w http.ResponseWriter,
if err != nil { if err != nil {
if file != nil { if file != nil {
log.Warnf("Cannot download file %s: %v", file.Path, err) log.Warnf("Cannot download file %s: %v", file.Path, err)
file.Link = "@" file.Link = "repair"
file.ForRepair = true
torMgr.SetChecksum("") // force a recheck torMgr.SetChecksum("") // force a recheck
} }
streamErrorVideo("https://www.youtube.com/watch?v=FSSd8cponAA", w, r, torMgr, cfg, log) streamErrorVideo("https://www.youtube.com/watch?v=FSSd8cponAA", w, r, torMgr, cfg, log)
@@ -139,8 +137,7 @@ func streamFileToResponse(file *intTor.File, url string, w http.ResponseWriter,
if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusPartialContent { if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusPartialContent {
if file != nil { if file != nil {
log.Warnf("Received a %s status code for file %s", resp.Status, file.Path) log.Warnf("Received a %s status code for file %s", resp.Status, file.Path)
file.Link = "@" file.Link = "repair"
file.ForRepair = true
torMgr.SetChecksum("") // force a recheck torMgr.SetChecksum("") // force a recheck
} }
streamErrorVideo("https://www.youtube.com/watch?v=BcseUxviVqE", w, r, torMgr, cfg, log) streamErrorVideo("https://www.youtube.com/watch?v=BcseUxviVqE", w, r, torMgr, cfg, log)