修改shell根目录获取,移除notify.sh

This commit is contained in:
whyour 2022-03-07 23:16:36 +08:00
parent 1db13653bf
commit 747f4552e0
11 changed files with 86 additions and 59 deletions

View File

@ -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);

View File

@ -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 } },
);
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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}`);

View File

@ -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"

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bash
## 导入通用变量与函数
dir_shell=/ql/shell
dir_shell=$QL_DIR/shell
. $dir_shell/share.sh
days=$1

View File

@ -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

View File

@ -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

View File

@ -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