From 8c97021e8f031e265553377a8119583ce40bcc6a Mon Sep 17 00:00:00 2001 From: Cian John Date: Sat, 20 Mar 2021 17:59:55 +0800 Subject: [PATCH] =?UTF-8?q?Feat(remotearia2):=20=E8=BD=AC=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bootstrap/init.go | 1 + pkg/aria2/aria2.go | 10 +++++++++- pkg/task/tranfer.go | 8 ++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/bootstrap/init.go b/bootstrap/init.go index c71e0d6..d100297 100644 --- a/bootstrap/init.go +++ b/bootstrap/init.go @@ -31,6 +31,7 @@ func Init(path string) { } else { if conf.SlaveConfig.Aria2 { model.Init() + task.Init() aria2.Init(false) } } diff --git a/pkg/aria2/aria2.go b/pkg/aria2/aria2.go index a2513a3..641c405 100644 --- a/pkg/aria2/aria2.go +++ b/pkg/aria2/aria2.go @@ -152,7 +152,15 @@ func SlaveInit(isReload bool) { Instance = client - // monitor + if !isReload { + // 从数据库中读取未完成任务,创建监控 + unfinished := model.GetDownloadsByStatus(Ready, Paused, Downloading) + + for i := 0; i < len(unfinished); i++ { + // 创建任务监控 + NewMonitor(&unfinished[i]) + } + } } // MasterInit 主机初始化 diff --git a/pkg/task/tranfer.go b/pkg/task/tranfer.go index 8cdc247..4c555df 100644 --- a/pkg/task/tranfer.go +++ b/pkg/task/tranfer.go @@ -3,6 +3,7 @@ package task import ( "context" "encoding/json" + "github.com/cloudreve/Cloudreve/v3/pkg/conf" "os" "path" "path/filepath" @@ -84,6 +85,13 @@ func (job *TransferTask) GetError() *JobError { // Do 开始执行任务 func (job *TransferTask) Do() { defer job.Recycle() + if model.IsTrueVal(model.GetSettingByName("aria2_remote_enabled")) && conf.SystemConfig.Mode != "slave" { + return + } + + if conf.SlaveConfig.SlaveId == 0 || model.GetIntSetting("aria2_remote_id", 0) != int(conf.SlaveConfig.SlaveId) { + return + } // 创建文件系统 fs, err := filesystem.NewFileSystem(job.User)