mirror of
https://github.com/Cp0204/quark-auto-save.git
synced 2026-01-16 17:30:43 +08:00
✨ 增加新建任务时插件默认配置项的支持
- 优化插件加载逻辑以返回可用插件和任务插件配置 - 修改插件配置的 json 编辑器高度为180px
This commit is contained in:
parent
c9c83cb65a
commit
63230d5c2b
@ -267,7 +267,7 @@
|
|||||||
<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">
|
||||||
<!-- <input type="text" name="addition[]" class="form-control" v-model="task.addition" placeholder="可选"> -->
|
<!-- <input type="text" name="addition[]" class="form-control" v-model="task.addition" placeholder="可选"> -->
|
||||||
<v-jsoneditor v-model="task.addition" :options="{mode:'tree'}" :plus="false" height="200px"></v-jsoneditor>
|
<v-jsoneditor v-model="task.addition" :options="{mode:'tree'}" :plus="false" height="180px"></v-jsoneditor>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -462,16 +462,13 @@
|
|||||||
}
|
}
|
||||||
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))
|
||||||
this.taskDirs.push(parentDir);
|
this.taskDirs.push(parentDir);
|
||||||
});
|
});
|
||||||
|
this.newTask.addition = response.data.task_plugins_config;
|
||||||
this.formData = response.data;
|
this.formData = response.data;
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
|||||||
@ -715,7 +715,8 @@ class Quark:
|
|||||||
|
|
||||||
|
|
||||||
def load_plugins(plugins_config, plugins_dir="plugins"):
|
def load_plugins(plugins_config, plugins_dir="plugins"):
|
||||||
plugins = {}
|
plugins_available = {}
|
||||||
|
task_plugins_config = {}
|
||||||
all_modules = [
|
all_modules = [
|
||||||
f.replace(".py", "") for f in os.listdir(plugins_dir) if f.endswith(".py")
|
f.replace(".py", "") for f in os.listdir(plugins_dir) if f.endswith(".py")
|
||||||
]
|
]
|
||||||
@ -737,14 +738,18 @@ def load_plugins(plugins_config, plugins_dir="plugins"):
|
|||||||
ServerClass = getattr(module, module_name.capitalize())
|
ServerClass = getattr(module, module_name.capitalize())
|
||||||
# 检查配置中是否存在该模块的配置
|
# 检查配置中是否存在该模块的配置
|
||||||
if module_name in plugins_config:
|
if module_name in plugins_config:
|
||||||
server_config = plugins_config[module_name]
|
plugin = ServerClass(**plugins_config[module_name])
|
||||||
plugins[module_name] = ServerClass(**server_config)
|
plugins_available[module_name] = plugin
|
||||||
else:
|
else:
|
||||||
plugins_config[module_name] = ServerClass().default_config
|
plugin = ServerClass()
|
||||||
|
plugins_config[module_name] = plugin.default_config
|
||||||
|
# 检查插件是否支持单独任务配置
|
||||||
|
if hasattr(plugin, "default_task_config"):
|
||||||
|
task_plugins_config[module_name] = plugin.default_task_config
|
||||||
except (ImportError, AttributeError) as e:
|
except (ImportError, AttributeError) as e:
|
||||||
print(f"载入模块 {module_name} 失败: {e}")
|
print(f"载入模块 {module_name} 失败: {e}")
|
||||||
print()
|
print()
|
||||||
return plugins
|
return plugins_available, task_plugins_config
|
||||||
|
|
||||||
|
|
||||||
def verify_account(account):
|
def verify_account(account):
|
||||||
@ -804,7 +809,9 @@ def do_sign(account):
|
|||||||
|
|
||||||
|
|
||||||
def do_save(account, tasklist=[]):
|
def do_save(account, tasklist=[]):
|
||||||
plugins = load_plugins(CONFIG_DATA.get("plugins", {}))
|
plugins, CONFIG_DATA["task_plugins_config"] = load_plugins(
|
||||||
|
CONFIG_DATA.get("plugins", {})
|
||||||
|
)
|
||||||
print(f"转存账号: {account.nickname}")
|
print(f"转存账号: {account.nickname}")
|
||||||
# 获取全部保存目录fid
|
# 获取全部保存目录fid
|
||||||
account.update_savepath_fid(tasklist)
|
account.update_savepath_fid(tasklist)
|
||||||
@ -842,15 +849,27 @@ def do_save(account, tasklist=[]):
|
|||||||
print()
|
print()
|
||||||
is_new_tree = account.do_save_task(task)
|
is_new_tree = account.do_save_task(task)
|
||||||
is_rename = account.do_rename_task(task)
|
is_rename = account.do_rename_task(task)
|
||||||
|
|
||||||
|
# 补充任务的插件配置
|
||||||
|
def merge_dicts(a, b):
|
||||||
|
result = a.copy()
|
||||||
|
for key, value in b.items():
|
||||||
|
if (
|
||||||
|
key in result
|
||||||
|
and isinstance(result[key], dict)
|
||||||
|
and isinstance(value, dict)
|
||||||
|
):
|
||||||
|
result[key] = merge_dicts(result[key], value)
|
||||||
|
elif key not in result:
|
||||||
|
result[key] = value
|
||||||
|
return result
|
||||||
|
|
||||||
|
task["addition"] = merge_dicts(
|
||||||
|
task.get("addition", {}), CONFIG_DATA["task_plugins_config"]
|
||||||
|
)
|
||||||
# 调用插件
|
# 调用插件
|
||||||
print(f"🧩 调用插件")
|
print(f"🧩 调用插件")
|
||||||
for plugin_name, plugin in plugins.items():
|
for plugin_name, plugin in plugins.items():
|
||||||
if hasattr(plugin, "default_task_config") and not task.get(
|
|
||||||
"addition", {}
|
|
||||||
).get(plugin_name):
|
|
||||||
task.setdefault("addition", {})[
|
|
||||||
plugin_name
|
|
||||||
] = plugin.default_task_config
|
|
||||||
if plugin.is_active and (is_new_tree or is_rename):
|
if plugin.is_active and (is_new_tree or is_rename):
|
||||||
task = plugin.run(task, account=account, tree=is_new_tree) or task
|
task = plugin.run(task, account=account, tree=is_new_tree) or task
|
||||||
print()
|
print()
|
||||||
|
|||||||
@ -20,7 +20,6 @@
|
|||||||
"pattern": "$TV",
|
"pattern": "$TV",
|
||||||
"replace": "",
|
"replace": "",
|
||||||
"enddate": "2099-01-30",
|
"enddate": "2099-01-30",
|
||||||
"media_id": "",
|
|
||||||
"update_subdir": "4k|1080p"
|
"update_subdir": "4k|1080p"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user