From 59dbf4496ff1c8f596770299db5c36868ba37e01 Mon Sep 17 00:00:00 2001 From: Andy Hsu Date: Mon, 3 Jul 2023 22:57:42 +0800 Subject: [PATCH] feat(offline_download): try to init client if not ready (close #4674) --- server/handles/aria2.go | 12 ++++++++++-- server/handles/qbittorrent.go | 12 ++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/server/handles/aria2.go b/server/handles/aria2.go index f127bf04..325367a7 100644 --- a/server/handles/aria2.go +++ b/server/handles/aria2.go @@ -48,8 +48,16 @@ func AddAria2(c *gin.Context) { return } if !aria2.IsAria2Ready() { - common.ErrorStrResp(c, "aria2 not ready", 500) - return + // try to init client + _, err := aria2.InitClient(2) + if err != nil { + common.ErrorResp(c, err, 500) + return + } + if !aria2.IsAria2Ready() { + common.ErrorStrResp(c, "aria2 still not ready after init", 500) + return + } } var req AddAria2Req if err := c.ShouldBind(&req); err != nil { diff --git a/server/handles/qbittorrent.go b/server/handles/qbittorrent.go index e99007dc..b2280454 100644 --- a/server/handles/qbittorrent.go +++ b/server/handles/qbittorrent.go @@ -47,8 +47,16 @@ func AddQbittorrent(c *gin.Context) { return } if !qbittorrent.IsQbittorrentReady() { - common.ErrorStrResp(c, "qbittorrent not ready", 500) - return + // try to init client + err := qbittorrent.InitClient() + if err != nil { + common.ErrorResp(c, err, 500) + return + } + if !qbittorrent.IsQbittorrentReady() { + common.ErrorStrResp(c, "qbittorrent still not ready after init", 500) + return + } } var req AddQbittorrentReq if err := c.ShouldBind(&req); err != nil {