diff --git a/.vscode/launch.json b/.vscode/launch.json index 1e9f7c07..892e5664 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -43,6 +43,19 @@ "YTP_ACCESS_LOG": "true", } }, + { + "name": "Node: Generate UI", + "request": "launch", + "runtimeArgs": [ + "run", + "generate" + ], + "runtimeExecutable": "yarn", + "type": "node", + "cwd": "${workspaceFolder}/ui", + "console": "internalConsole", + "outputCapture": "std", + }, { "name": "Python: main.py (Deep)", "type": "debugpy", diff --git a/ui/components/TaskForm.vue b/ui/components/TaskForm.vue index 7b439f39..2f6253db 100644 --- a/ui/components/TaskForm.vue +++ b/ui/components/TaskForm.vue @@ -1,7 +1,41 @@ @@ -347,4 +358,69 @@ const statusHandler = async stream => { return } } + +const exportTask = async task => { + let preset = config.presets.find(p => p.name === task.preset) + if (!preset) { + toast.error('Preset not found.') + return + } + + const info = JSON.parse(JSON.stringify(task)) + preset = JSON.parse(JSON.stringify(preset)) + + let data = { + name: info.name, + url: info.url, + preset: 'default', + timer: info.timer, + folder: info.folder, + template: info.template, + config: info.config, + } + + // -- merge preset options with task args. + let args = {} + + if (preset.args && Object.keys(preset.args).length > 0) { + for (const key of Object.keys(preset.args)) { + args[key] = preset.args[key] + } + } + + if (preset.format !== 'not_set' && preset.format) { + args.format = preset.format + } + + if (preset.postprocessors && preset.postprocessors.length > 0) { + args.postprocessors = preset.postprocessors + } + + if (preset.folder && !info.folder) { + data.folder = preset.folder + } + + if (preset.template && !info.template) { + data.template = preset.template + } + + if (!data.config || Object.keys(data.config).length < 1) { + data.config = {} + } + + for (const key of Object.keys(args)) { + if (key in data.config && Array.isArray(args[key]) && Array.isArray(data.config[key])) { + data.config[key] = data.config[key].concat(args[key]) + continue + } + + if (data?.config[key]) { + continue + } + + data.config[key] = args[key] + } + + return copyText(base64UrlEncode(JSON.stringify(data))); +}