支持单个任务运行

This commit is contained in:
Cp0204 2024-04-22 02:06:02 +08:00
parent 8855b3fb95
commit 93a60dd036
3 changed files with 37 additions and 21 deletions

View File

@ -135,7 +135,9 @@ def update():
def run_script_now(): def run_script_now():
if not is_login(): if not is_login():
return "未登录" return "未登录"
command = [python_path, script_path, config_path] payload = request.json
task_index = str(payload.get("task_index", ""))
command = [python_path, script_path, config_path, task_index]
def generate_output(): def generate_output():
process = subprocess.Popen( process = subprocess.Popen(

View File

@ -131,7 +131,8 @@
<h3>任务#<span v-html="index+1"></span></h3> <h3>任务#<span v-html="index+1"></span></h3>
</div> </div>
<div class="col text-right"> <div class="col text-right">
<button type="button" class="btn btn-outline-danger" @click="removeTask(index)">删除任务</button> <button type="button" class="btn btn-outline-primary" @click="runScriptNow(index)" title="运行此任务"><i class="bi bi-play-fill"></i></button>
<button type="button" class="btn btn-outline-danger" @click="removeTask(index)" title="删除此任务"><i class="bi bi-trash3-fill"></i></button>
</div> </div>
</div> </div>
<div class="alert alert-warning" role="alert" v-if="task.shareurl_ban" v-html="task.shareurl_ban"></div> <div class="alert alert-warning" role="alert" v-if="task.shareurl_ban" v-html="task.shareurl_ban"></div>
@ -153,12 +154,6 @@
<input type="text" name="savepath[]" class="form-control" v-model="task.savepath" placeholder="必填"> <input type="text" name="savepath[]" class="form-control" v-model="task.savepath" placeholder="必填">
</div> </div>
</div> </div>
<div class="form-group row">
<label class="col-sm-2 col-form-label">更子目录</label>
<div class="col-sm-10">
<input type="text" name="update_subdir[]" class="form-control" v-model="task.update_subdir" placeholder="可选,需更新子目录的正则式,多项以|分割,如 4k|1080p ,注意!深层嵌套目录慎用 .* " title="注意!深层嵌套目录逐级索引,工作强度会非常大,慎用!">
</div>
</div>
<div class="form-group row"> <div class="form-group row">
<label class="col-sm-2 col-form-label">正则处理</label> <label class="col-sm-2 col-form-label">正则处理</label>
<div class="col-sm-10"> <div class="col-sm-10">
@ -173,6 +168,12 @@
</div> </div>
</div> </div>
</div> </div>
<div class="form-group row">
<label class="col-sm-2 col-form-label">更子目录</label>
<div class="col-sm-10">
<input type="text" name="update_subdir[]" class="form-control" v-model="task.update_subdir" placeholder="可选,需更新子目录的正则式,多项以|分割,如 4k|1080p ,注意!深层嵌套目录慎用 .* " title="注意!深层嵌套目录逐级索引,工作强度会非常大,慎用!">
</div>
</div>
<div class="form-group row"> <div class="form-group row">
<label class="col-sm-2 col-form-label">截止日期</label> <label class="col-sm-2 col-form-label">截止日期</label>
<div class="col-sm-10"> <div class="col-sm-10">
@ -211,8 +212,8 @@
</div> </div>
<div class="bottom-buttons"> <div class="bottom-buttons">
<button class="btn btn-success"><i class="bi bi-save"></i> 保存</button> <button class="btn btn-success"><i class="bi bi-save"></i> 保存</button>
<a class="btn btn-primary" @click="runScriptNow"><i class="bi bi-play-fill"></i> 运行</a> <button type="button" class="btn btn-primary" @click="runScriptNow()"><i class="bi bi-play-fill"></i> 运行</button>
<a class="btn btn-info" @click="scrollToX(0)" @dblclick="scrollToX()" data-toggle="tooltip" data-placement="top" title="单击回顶,双击到底"><i class="bi bi-chevron-bar-up"></i> 回顶</a> <button type="button" class="btn btn-info" @click="scrollToX(0)" @dblclick="scrollToX()" data-toggle="tooltip" data-placement="top" title="单击回顶,双击到底"><i class="bi bi-chevron-bar-up"></i> 回顶</button>
<a class="btn btn-danger" href="/logout"><i class="bi bi-box-arrow-right"></i> 退出</a> <a class="btn btn-danger" href="/logout"><i class="bi bi-box-arrow-right"></i> 退出</a>
</div> </div>
</form> </form>
@ -301,14 +302,18 @@
// cookie兼容 // cookie兼容
if (typeof response.data.cookie === 'string') if (typeof response.data.cookie === 'string')
response.data.cookie = [response.data.cookie]; response.data.cookie = [response.data.cookie];
// 星期运行兼容 // 添加星期预设
response.data.tasklist = response.data.tasklist.map(task => { response.data.tasklist = response.data.tasklist.map(task => {
if (!task.hasOwnProperty('runweek')) { if (!task.hasOwnProperty('runweek')) {
task.runweek = [1, 2, 3, 4, 5, 6, 7]; task.runweek = [1, 2, 3, 4, 5, 6, 7];
} }
return task; return task;
}); });
// 存所有任务父目录 // 添加emby预设
if (!response.data.hasOwnProperty('emby')) {
response.data.emby = { ...this.emby };
}
// 获取所有任务父目录
response.data.tasklist.forEach(item => { response.data.tasklist.forEach(item => {
parentDir = this.getParentDirectory(item.savepath) parentDir = this.getParentDirectory(item.savepath)
if (!this.taskDirs.includes(parentDir)) if (!this.taskDirs.includes(parentDir))
@ -366,15 +371,17 @@
clearData(target) { clearData(target) {
this[target] = ""; this[target] = "";
}, },
runScriptNow() { runScriptNow(task_index = "") {
$('#logModal').modal('toggle') $('#logModal').modal('toggle')
this.run_log = '<div class="spinner-border" role="status"></div> 请耐心等待脚本全部执行完毕...' this.run_log = '<div class="spinner-border" role="status"></div> 请耐心等待脚本全部执行完毕...'
axios.post('/run_script_now') axios.post('/run_script_now', {
task_index: task_index,
})
.then(response => { .then(response => {
this.run_log = response.data; this.run_log = response.data;
}) })
.catch(error => { .catch(error => {
this.run_log = "错误:\n" + error this.run_log = "错误:\n" + error;
console.error('Error:', error); console.error('Error:', error);
}); });
}, },

View File

@ -771,14 +771,12 @@ def do_sign(account):
print() print()
def do_save(account): def do_save(account, tasklist=[]):
emby = Emby( emby = Emby(
CONFIG_DATA.get("emby", {}).get("url", ""), CONFIG_DATA.get("emby", {}).get("url", ""),
CONFIG_DATA.get("emby", {}).get("apikey", ""), CONFIG_DATA.get("emby", {}).get("apikey", ""),
) )
print(f"转存账号: {account.nickname}") print(f"转存账号: {account.nickname}")
# 任务列表
tasklist = CONFIG_DATA.get("tasklist", [])
# 获取全部保存目录fid # 获取全部保存目录fid
account.update_savepath_fid(tasklist) account.update_savepath_fid(tasklist)
@ -837,6 +835,7 @@ def main():
print() print()
# 读取启动参数 # 读取启动参数
config_path = sys.argv[1] if len(sys.argv) > 1 else "quark_config.json" config_path = sys.argv[1] if len(sys.argv) > 1 else "quark_config.json"
task_index = int(sys.argv[2]) if len(sys.argv) > 2 and sys.argv[2].isdigit() else ""
# 检查本地文件是否存在,如果不存在就下载 # 检查本地文件是否存在,如果不存在就下载
if not os.path.exists(config_path): if not os.path.exists(config_path):
if os.environ.get("QUARK_COOKIE"): if os.environ.get("QUARK_COOKIE"):
@ -865,13 +864,21 @@ def main():
accounts = [Quark(cookie, index) for index, cookie in enumerate(cookies)] accounts = [Quark(cookie, index) for index, cookie in enumerate(cookies)]
# 签到 # 签到
print(f"===============签到任务===============") print(f"===============签到任务===============")
for account in accounts: if type(task_index) is int:
do_sign(account) do_sign(accounts[0])
else:
for account in accounts:
do_sign(account)
print() print()
# 转存 # 转存
if accounts[0].is_active and cookie_form_file: if accounts[0].is_active and cookie_form_file:
print(f"===============转存任务===============") print(f"===============转存任务===============")
do_save(accounts[0]) # 任务列表
tasklist = CONFIG_DATA.get("tasklist", [])
if type(task_index) is int:
do_save(accounts[0], [tasklist[task_index]])
else:
do_save(accounts[0], tasklist)
print() print()
# 通知 # 通知
if NOTIFYS: if NOTIFYS: