diff --git a/back/loaders/db.ts b/back/loaders/db.ts index 421293ed..10f97cc4 100644 --- a/back/loaders/db.ts +++ b/back/loaders/db.ts @@ -8,6 +8,7 @@ import { AppModel } from '../data/open'; import { AuthModel } from '../data/auth'; import { sequelize } from '../data'; import { fileExist } from '../config/util'; +import config from '../config'; export default async () => { try { @@ -26,11 +27,11 @@ export default async () => { // } catch (error) { } // 2.10-2.11 升级 - const cronDbFile = path.join('/ql', 'db/crontab.db'); - const envDbFile = path.join('/ql', 'db/env.db'); - const appDbFile = path.join('/ql', 'db/app.db'); - const authDbFile = path.join('/ql', 'db/auth.db'); - const dependenceDbFile = path.join('/ql', 'db/dependence.db'); + const cronDbFile = path.join(config.rootPath, 'db/crontab.db'); + const envDbFile = path.join(config.rootPath, 'db/env.db'); + const appDbFile = path.join(config.rootPath, 'db/app.db'); + const authDbFile = path.join(config.rootPath, 'db/auth.db'); + const dependenceDbFile = path.join(config.rootPath, 'db/dependence.db'); const crondbExist = await fileExist(cronDbFile); const dependenceDbExist = await fileExist(dependenceDbFile); const envDbExist = await fileExist(envDbFile); diff --git a/back/loaders/initData.ts b/back/loaders/initData.ts index ac00a0a8..4d431d4a 100644 --- a/back/loaders/initData.ts +++ b/back/loaders/initData.ts @@ -9,6 +9,7 @@ import { DependenceModel } from '../data/dependence'; import { Op } from 'sequelize'; import SystemService from '../services/system'; import ScheduleService from '../services/schedule'; +import config from '../config'; export default async () => { const cronService = Container.get(CronService); @@ -31,7 +32,9 @@ export default async () => { const group = groups[key]; const depIds = group.map((x) => x.id); for (const dep of depIds) { - await dependenceService.reInstall([dep]); + if (dep) { + await dependenceService.reInstall([dep]); + } } } } @@ -59,10 +62,10 @@ export default async () => { where: { command: { [Op.or]: [ - { [Op.like]: `%\/ql\/scripts\/%` }, - { [Op.like]: `%\/ql\/config\/%` }, - { [Op.like]: `%\/ql\/log\/%` }, - { [Op.like]: `%\/ql\/db\/%` }, + { [Op.like]: `%\/${config.rootPath}\/scripts\/%` }, + { [Op.like]: `%\/${config.rootPath}\/config\/%` }, + { [Op.like]: `%\/${config.rootPath}\/log\/%` }, + { [Op.like]: `%\/${config.rootPath}\/db\/%` }, ], }, }, @@ -70,32 +73,42 @@ export default async () => { for (let i = 0; i < docs.length; i++) { const doc = docs[i]; if (doc) { - if (doc.command.includes('/ql/scripts/')) { + if (doc.command.includes(`${config.rootPath}/scripts/`)) { await CrontabModel.update( - { command: doc.command.replace('/ql/scripts/', '') }, + { command: doc.command.replace(`${config.rootPath}/scripts/`, '') }, { where: { id: doc.id } }, ); } - if (doc.command.includes('/ql/log/')) { - await CrontabModel.update( - { command: `/ql/data/log/${doc.command.replace('/ql/log/', '')}` }, - { where: { id: doc.id } }, - ); - } - if (doc.command.includes('/ql/config/')) { + if (doc.command.includes(`${config.rootPath}/log/`)) { await CrontabModel.update( { - command: `/ql/data/config/${doc.command.replace( - '/ql/config/', + command: `${config.rootPath}/data/log/${doc.command.replace( + `${config.rootPath}/log/`, '', )}`, }, { where: { id: doc.id } }, ); } - if (doc.command.includes('/ql/db/')) { + if (doc.command.includes(`${config.rootPath}/config/`)) { await CrontabModel.update( - { command: `/ql/data/db/${doc.command.replace('/ql/db/', '')}` }, + { + command: `${config.rootPath}/data/config/${doc.command.replace( + `${config.rootPath}/config/`, + '', + )}`, + }, + { where: { id: doc.id } }, + ); + } + if (doc.command.includes(`${config.rootPath}/db/`)) { + await CrontabModel.update( + { + command: `${config.rootPath}/data/db/${doc.command.replace( + `${config.rootPath}/db/`, + '', + )}`, + }, { where: { id: doc.id } }, ); } diff --git a/shell/api.sh b/shell/api.sh index 034329f0..a08db49f 100755 --- a/shell/api.sh +++ b/shell/api.sh @@ -176,4 +176,30 @@ update_cron() { fi } +notify_api() { + local title=$1 + local content=$1 + local currentTimeStamp=$(date +%s) + local api=$( + curl -s --noproxy "*" "http://0.0.0.0:5600/api/system/notify?t=$currentTimeStamp" \ + -X 'PUT' \ + -H "Accept: application/json" \ + -H "Authorization: Bearer $token" \ + -H "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 11_2_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36" \ + -H "Content-Type: application/json;charset=UTF-8" \ + -H "Origin: http://0.0.0.0:5700" \ + -H "Referer: http://0.0.0.0:5700/crontab" \ + -H "Accept-Language: en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7" \ + --data-raw "{\"title\":\"$title\",\"content\":\"$content\"}" \ + --compressed + ) + code=$(echo $api | jq -r .code) + message=$(echo $api | jq -r .message) + if [[ $code == 200 ]]; then + echo -e "成功" + else + echo -e "失败(${message})" + fi +} + get_token diff --git a/shell/bot.sh b/shell/bot.sh index d2dbe2a9..87e7f075 100644 --- a/shell/bot.sh +++ b/shell/bot.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash ## 导入通用变量与函数 -dir_shell=/ql/shell +dir_shell=$QL_DIR/shell . $dir_shell/share.sh if [[ -z ${BotRepoUrl} ]]; then diff --git a/shell/check.sh b/shell/check.sh index 9dbad018..27b27237 100644 --- a/shell/check.sh +++ b/shell/check.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -dir_shell=/ql/shell +dir_shell=$QL_DIR/shell . $dir_shell/share.sh . $dir_shell/api.sh diff --git a/shell/notify.js b/shell/notify.js deleted file mode 100644 index 92bce2b4..00000000 --- a/shell/notify.js +++ /dev/null @@ -1,5 +0,0 @@ -const notify = require('/ql/data/scripts/sendNotify.js'); -const title = process.argv[2]; -const content = process.argv[3]; - -notify.sendNotify(`${title}`, `${content}`); diff --git a/shell/notify.sh b/shell/notify.sh deleted file mode 100755 index e066858b..00000000 --- a/shell/notify.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -#author:spark thanks to: https://github.com/sparkssssssss/scripts - -. /ql/data/config/config.sh -title=$(echo $1|sed 's/-/_/g') -msg=$(echo -e $2) - -node /ql/shell/notify.js "$title" "$msg" \ No newline at end of file diff --git a/shell/rmlog.sh b/shell/rmlog.sh index ae4e82e8..0e010520 100755 --- a/shell/rmlog.sh +++ b/shell/rmlog.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash ## 导入通用变量与函数 -dir_shell=/ql/shell +dir_shell=$QL_DIR/shell . $dir_shell/share.sh days=$1 diff --git a/shell/share.sh b/shell/share.sh index 7630adc7..b75a30dc 100755 --- a/shell/share.sh +++ b/shell/share.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash ## 目录 -dir_root=/ql +dir_root=$QL_DIR dir_data=$dir_root/data dir_shell=$dir_root/shell dir_sample=$dir_root/sample diff --git a/shell/task.sh b/shell/task.sh index b9bf9a92..4473b42d 100755 --- a/shell/task.sh +++ b/shell/task.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash ## 导入通用变量与函数 -dir_shell=/ql/shell +dir_shell=$QL_DIR/shell . $dir_shell/share.sh . $dir_shell/api.sh diff --git a/shell/update.sh b/shell/update.sh index 4f6d6f2c..5c862ca0 100755 --- a/shell/update.sh +++ b/shell/update.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -dir_shell=/ql/shell +dir_shell=$QL_DIR/shell . $dir_shell/share.sh . $dir_shell/api.sh @@ -43,7 +43,7 @@ detect_config_version() { local notify_title="配置文件更新通知" local notify_content="更新日期: $update_date\n用户版本: $ver_config_user\n新的版本: $ver_config_sample\n更新内容: $update_content\n更新说明: 如需使用新功能请对照config.sample.sh,将相关新参数手动增加到你自己的config.sh中,否则请无视本消息。本消息只在该新版本配置文件更新当天发送一次。\n" echo -e $notify_content - notify "$notify_title" "$notify_content" + notify_api "$notify_title" "$notify_content" [[ $? -eq 0 ]] && echo $ver_config_sample >$send_mark fi else @@ -91,7 +91,7 @@ del_cron() { done if [[ $ids ]]; then result=$(del_cron_api "$ids") - notify "$path 删除任务${result}" "$detail" + notify_api "$path 删除任务${result}" "$detail" fi } @@ -131,7 +131,7 @@ add_cron() { fi fi done - notify "$path 新增任务" "$detail" + notify_api "$path 新增任务" "$detail" } ## 更新仓库 @@ -203,7 +203,7 @@ update_raw() { if [[ -z $cron_id ]]; then result=$(add_cron_api "$cron_line:$cmd_task $filename:$cron_name") echo -e "$result\n" - notify "新增任务通知" "\n$result" + notify_api "新增任务通知" "\n$result" # update_cron_api "$cron_line:$cmd_task $filename:$cron_name:$cron_id" fi else @@ -274,7 +274,7 @@ update_qinglong() { fi if [[ $exit_status -eq 0 ]]; then echo -e "\n更新$ql_static_repo成功...\n" - local static_version=$(cat /ql/src/version.ts | perl -pe "s|.*\'(.*)\';\.*|\1|" | head -1) + local static_version=$(cat $dir_root/src/version.ts | perl -pe "s|.*\'(.*)\';\.*|\1|" | head -1) echo -e "\n当前版本 $static_version...\n" rm -rf $dir_static/* @@ -292,10 +292,10 @@ update_qinglong() { } patch_version() { - if [[ -f "/ql/db/cookie.db" ]]; then + if [[ -f "$dir_root/db/cookie.db" ]]; then echo -e "检测到旧的db文件,拷贝为新db...\n" - mv /ql/db/cookie.db /ql/db/env.db - rm -rf /ql/db/cookie.db + mv $dir_root/db/cookie.db $dir_root/db/env.db + rm -rf $dir_root/db/cookie.db echo fi @@ -305,29 +305,29 @@ patch_version() { git config --global pull.rebase false - cp -f /ql/.env.example /ql/.env + cp -f $dir_root/.env.example $dir_root/.env - if [[ -d "/ql/db" ]]; then + if [[ -d "$dir_root/db" ]]; then echo -e "检测到旧的db目录,拷贝到data目录...\n" - cp -rf /ql/config /ql/data + cp -rf $dir_root/config $dir_root/data echo fi - if [[ -d "/ql/scripts" ]]; then + if [[ -d "$dir_root/scripts" ]]; then echo -e "检测到旧的scripts目录,拷贝到data目录...\n" - cp -rf /ql/scripts /ql/data + cp -rf $dir_root/scripts $dir_root/data echo fi - if [[ -d "/ql/log" ]]; then + if [[ -d "$dir_root/log" ]]; then echo -e "检测到旧的log目录,拷贝到data目录...\n" - cp -rf /ql/log /ql/data + cp -rf $dir_root/log $dir_root/data echo fi - if [[ -d "/ql/config" ]]; then + if [[ -d "$dir_root/config" ]]; then echo -e "检测到旧的config目录,拷贝到data目录...\n" - cp -rf /ql/config /ql/data + cp -rf $dir_root/config $dir_root/data echo fi