Compare commits

...

3 Commits

Author SHA1 Message Date
krau
5ef7c5ce60 fix: timeout in alist and webdav 2024-10-11 16:50:47 +08:00
krau
03c833acbf refactor: optimize timeout setting in initClient function 2024-10-11 16:38:43 +08:00
krau
0d369c7c79 fix: remove unnecessary context setting in processPendingTask 2024-10-11 16:26:53 +08:00
4 changed files with 6 additions and 3 deletions

View File

@@ -2,6 +2,7 @@ package common
import (
"path/filepath"
"time"
"github.com/imroc/req/v3"
"github.com/krau/SaveAny-Bot/config"
@@ -10,7 +11,7 @@ import (
var ReqClient *req.Client
func initClient() {
ReqClient = req.NewClient().SetOutputDirectory(config.Cfg.Temp.BasePath)
ReqClient = req.NewClient().SetOutputDirectory(config.Cfg.Temp.BasePath).SetTimeout(86400 * time.Second)
}
func GetDownloadedFilePath(filename string) string {

View File

@@ -29,7 +29,7 @@ func processPendingTask(task types.Task) error {
return err
}
_, err = common.ReqClient.R().SetContext(task.Ctx).SetOutputFile(task.FileName).SetDownloadCallbackWithInterval(func(info req.DownloadInfo) {
_, err = common.ReqClient.R().SetOutputFile(task.FileName).SetDownloadCallbackWithInterval(func(info req.DownloadInfo) {
if info.Response == nil || info.Response.Response == nil || info.Response.Response.StatusCode != 200 {
return
}

View File

@@ -71,7 +71,7 @@ func refreshToken(client *req.Client) {
func (a *Alist) Init() {
basePath = config.Cfg.Storage.Alist.BasePath
baseUrl = config.Cfg.Storage.Alist.URL
reqClient = req.C().SetTLSHandshakeTimeout(time.Second * 10).SetBaseURL(baseUrl)
reqClient = req.C().SetTLSHandshakeTimeout(time.Second * 10).SetBaseURL(baseUrl).SetTimeout(time.Hour * 24)
loginReq = &loginRequset{
Username: config.Cfg.Storage.Alist.Username,
Password: config.Cfg.Storage.Alist.Password,

View File

@@ -6,6 +6,7 @@ import (
"os"
"path/filepath"
"strings"
"time"
"github.com/krau/SaveAny-Bot/config"
"github.com/krau/SaveAny-Bot/logger"
@@ -27,6 +28,7 @@ func (w *Webdav) Init() {
logger.L.Fatalf("Failed to connect to webdav server: %v", err)
os.Exit(1)
}
Client.SetTimeout(24 * time.Hour)
}
func (w *Webdav) Save(ctx context.Context, filePath, storagePath string) error {