Catch download error case

This commit is contained in:
Ben Adrian Sarmiento
2024-06-24 02:32:31 +02:00
parent 3b26040f7e
commit f84298c724
3 changed files with 11 additions and 6 deletions

View File

@@ -5,7 +5,7 @@ on:
tags:
- 'v**'
schedule:
- cron: '0 0 * * *'
- cron: '0 1 * * *'
jobs:
build:
@@ -38,7 +38,7 @@ jobs:
continue-on-error: false
run: |
# 3AM CET
since="$(date -d 'yesterday' +%Y-%m-%d) 00:00:00"
since="$(date -d 'yesterday' +%Y-%m-%d) 01:00:00"
count=$(git rev-list --count --since="$since" --until=now HEAD)
if [ "$count" -gt 0 ]; then
echo "new_commits=true" >> $GITHUB_OUTPUT

View File

@@ -5,7 +5,7 @@ on:
tags:
- 'v**'
schedule:
- cron: '0 0 * * *'
- cron: '0 1 * * *'
jobs:
build-and-push-image:
@@ -25,7 +25,7 @@ jobs:
continue-on-error: false
run: |
# 3AM CET
since="$(date -d 'yesterday' +%Y-%m-%d) 00:00:00"
since="$(date -d 'yesterday' +%Y-%m-%d) 01:00:00"
count=$(git rev-list --count --since="$since" --until=now HEAD)
if [ "$count" -gt 0 ]; then
echo "new_commits=true" >> $GITHUB_OUTPUT

View File

@@ -64,7 +64,7 @@ func (dl *Downloader) DownloadFile(
unrestrict, err := torMgr.UnrestrictFile(file, cfg.ShouldServeFromRclone())
if dlErr, ok := err.(*zurghttp.DownloadErrorResponse); ok && dlErr.Message == "bytes_limit_reached" {
log.Warnf("Your account has reached the bandwidth limit, please try again after 12AM CET")
http.Error(resp, "File is not available", http.StatusLocked)
http.Error(resp, "File is not available (bandwidth limit reached)", http.StatusLocked)
return
}
if err != nil {
@@ -108,7 +108,7 @@ func (dl *Downloader) DownloadLink(
unrestrict, err := torMgr.UnrestrictLink(link, cfg.ShouldServeFromRclone())
if dlErr, ok := err.(*zurghttp.DownloadErrorResponse); ok && dlErr.Message == "bytes_limit_reached" {
log.Warnf("Your account has reached the bandwidth limit, please try again after 12AM CET")
http.Error(resp, "Link is not available", http.StatusLocked)
http.Error(resp, "Link is not available (bandwidth limit reached)", http.StatusLocked)
return
}
if err != nil {
@@ -151,6 +151,11 @@ func (dl *Downloader) streamFileToResponse(
// Perform the request
downloadResp, err := dl.client.Do(dlReq)
if dlErr, ok := err.(*zurghttp.DownloadErrorResponse); ok && dlErr.Message == "bytes_limit_reached" {
log.Warnf("Your account has reached the bandwidth limit, please try again after 12AM CET")
http.Error(resp, "File is not available (bandwidth limit reached)", http.StatusLocked)
return
}
if err != nil {
log.Warnf("Cannot download file %s: %v", unrestrict.Download, err)
if file != nil && file.State.Event(context.Background(), "break_file") == nil {