diff --git a/back/api/cron.ts b/back/api/cron.ts index ee3f6e4e..5206c6b6 100644 --- a/back/api/cron.ts +++ b/back/api/cron.ts @@ -225,4 +225,28 @@ export default (app: Router) => { } }, ); + + route.put( + '/crons/status', + celebrate({ + body: Joi.object({ + ids: Joi.array().items(Joi.string().required()), + status: Joi.string().required(), + }), + }), + async (req: Request, res: Response, next: NextFunction) => { + const logger: Logger = Container.get('logger'); + try { + const cronService = Container.get(CronService); + const data = await cronService.status({ + ...req.body, + status: parseInt(req.body.status), + }); + return res.send({ code: 200, data }); + } catch (e) { + logger.error('🔥 error: %o', e); + return next(e); + } + }, + ); }; diff --git a/back/services/cron.ts b/back/services/cron.ts index c5c718ec..88f94032 100644 --- a/back/services/cron.ts +++ b/back/services/cron.ts @@ -83,8 +83,14 @@ export default class CronService { }); } - public async status(_id: string, stopped: boolean) { - this.cronDb.update({ _id }, { $set: { stopped, saved: false } }); + public async status({ + ids, + status, + }: { + ids: string[]; + status: CrontabStatus; + }) { + this.cronDb.update({ _id: { $in: ids } }, { $set: { status } }); } public async remove(ids: string[]) { diff --git a/sample/config.sample.sh b/sample/config.sample.sh index 44efdf7b..35a37640 100644 --- a/sample/config.sample.sh +++ b/sample/config.sample.sh @@ -1,6 +1,6 @@ -## Version: v2.2.0-062 -## Date: 2021-06-07 -## Update Content: session管理增加批量操作\n增加go-cqhttp通知方式\n修复页面标题 +## Version: v2.2.0-063 +## Date: 2021-06-13 +## Update Content: \n1. 增加文件后缀配置 RepoFileExtensions\n2. 增加定时任务pageSize缓存\n3. 增加定时任务自动运行时状态展示 ## 上面版本号中,如果第2位数字有变化,那么代表增加了新的参数,如果只有第3位数字有变化,仅代表更新了注释,没有增加新的参数,可更新可不更新 @@ -10,6 +10,9 @@ AutoDelCron="true" ## 在运行 ql repo 命令时,是否自动增加新的本地定时任务 AutoAddCron="true" +## ql repo命令拉取脚本时需要拉取的文件后缀,直接写文件后缀名即可 +RepoFileExtensions="js py" + ## 由于github仓库拉取较慢,所以会默认添加代理前缀,如不需要请移除 GithubProxyUrl="https://ghproxy.com/" diff --git a/shell/api.sh b/shell/api.sh index 2e3b7d81..d2c1d410 100755 --- a/shell/api.sh +++ b/shell/api.sh @@ -133,7 +133,7 @@ del_cron_api() { get_user_info() { local currentTimeStamp=$(date +%s) local api=$( - curl -s "http://localhost:5700/api/user?t=$currentTimeStamp" \ + curl -s "http://localhost:5600/api/user?t=$currentTimeStamp" \ -H 'Accept: */*' \ -H "Authorization: Bearer $token" \ -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36' \ @@ -147,3 +147,31 @@ get_user_info() { exit 0 fi } + +update_cron_status() { + local ids=$1 + local status=$2 + local currentTimeStamp=$(date +%s) + local api=$( + curl -s "http://localhost:5600/api/crons/status?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://localhost:5700" \ + -H "Referer: http://localhost:5700/crontab" \ + -H "Accept-Language: en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7" \ + --data-raw "{\"ids\":[$ids],\"status\":\"$status\"}" \ + --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 \ No newline at end of file diff --git a/shell/bot.sh b/shell/bot.sh index e047721f..c6b71d05 100644 --- a/shell/bot.sh +++ b/shell/bot.sh @@ -3,6 +3,7 @@ ## 导入通用变量与函数 dir_shell=/ql/shell . $dir_shell/share.sh +url="${github_proxy_url}https://github.com/SuMaiKaDe/bot.git" repo_path="${dir_repo}/dockerbot" echo -e "\n1、安装bot依赖...\n" @@ -10,6 +11,13 @@ apk --no-cache add -f zlib-dev gcc jpeg-dev python3-dev musl-dev freetype-dev echo -e "\nbot依赖安装成功...\n" echo -e "2、下载bot所需文件...\n" +if [ -d ${repo_path}/.git ]; then + git_pull_scripts ${repo_path} +else + rm -rf ${repo_path} + git_clone_scripts ${url} ${repo_path} "main" +fi + cp -rf "$repo_path/jbot" $dir_root if [[ ! -f "$dir_root/config/bot.json" ]]; then cp -f "$repo_path/config/bot.json" "$dir_root/config" diff --git a/shell/share.sh b/shell/share.sh index 464be17f..e4d9e0f2 100755 --- a/shell/share.sh +++ b/shell/share.sh @@ -62,6 +62,7 @@ import_config() { command_timeout_time=${CommandTimeoutTime:-"1h"} github_proxy_url=${GithubProxyUrl:-""} block_cookie=${TempBlockCookie:-""} + file_extensions=${RepoFileExtensions:-"js py"} } ## 创建目录,$1:目录的绝对路径 diff --git a/shell/update.sh b/shell/update.sh index bc5cb976..f8d8c5cb 100755 --- a/shell/update.sh +++ b/shell/update.sh @@ -7,8 +7,6 @@ dir_shell=/ql/shell send_mark=$dir_shell/send_mark -get_token - ## 重置仓库remote url,docker专用,$1:要重置的目录,$2:要重置为的网址 reset_romote_url() { local dir_current=$(pwd) @@ -357,7 +355,18 @@ gen_list_repo() { rm -f $dir_list_tmp/${repo}*.list >/dev/null 2>&1 cd ${repo_path} - files=$(find . -name "*.js" | sed 's/^..//') + + local cmd="find ." + local index=0 + for extension in $file_extensions; do + if [[ $index -eq 0 ]]; then + cmd="${cmd} -name \"*.${extension}\"" + else + cmd="${cmd} -o -name \"*.${extension}\"" + fi + let index+=1 + done + files=$(eval $cmd | sed 's/^..//') if [[ $path ]]; then files=$(echo "$files" | egrep $path) fi @@ -365,7 +374,7 @@ gen_list_repo() { files=$(echo "$files" | egrep -v $blackword) fi if [[ $dependence ]]; then - find . -name "*.js" | sed 's/^..//' | egrep $dependence | xargs -i cp {} $dir_scripts + eval $cmd | sed 's/^..//' | egrep $dependence | xargs -i cp {} $dir_scripts fi for file in ${files}; do filename=$(basename $file) diff --git a/src/pages/crontab/index.tsx b/src/pages/crontab/index.tsx index 8d57ae2f..18da79dc 100644 --- a/src/pages/crontab/index.tsx +++ b/src/pages/crontab/index.tsx @@ -187,6 +187,8 @@ const Crontab = () => { const [isLogModalVisible, setIsLogModalVisible] = useState(false); const [logCron, setLogCron] = useState(); const [selectedRowIds, setSelectedRowIds] = useState([]); + const [currentPage, setCurrentPage] = useState(1); + const [pageSize, setPageSize] = useState(20); const getCrons = () => { setLoading(true); @@ -233,7 +235,7 @@ const Crontab = () => { if (data.code === 200) { message.success('删除成功'); const result = [...value]; - result.splice(index, 1); + result.splice(index + pageSize * (currentPage - 1), 1); setValue(result); } else { message.error(data); @@ -264,7 +266,7 @@ const Crontab = () => { .then((data: any) => { if (data.code === 200) { const result = [...value]; - result.splice(index, 1, { + result.splice(index + pageSize * (currentPage - 1), 1, { ...record, status: CrontabStatus.running, }); @@ -298,7 +300,7 @@ const Crontab = () => { .then((data: any) => { if (data.code === 200) { const result = [...value]; - result.splice(index, 1, { + result.splice(index + pageSize * (currentPage - 1), 1, { ...record, pid: null, status: CrontabStatus.idle, @@ -342,7 +344,7 @@ const Crontab = () => { if (data.code === 200) { const newStatus = record.isDisabled === 1 ? 0 : 1; const result = [...value]; - result.splice(index, 1, { + result.splice(index + pageSize * (currentPage - 1), 1, { ...record, isDisabled: newStatus, }); @@ -429,7 +431,7 @@ const Crontab = () => { if (index === -1) { result.push(cron); } else { - result.splice(index, 1, { + result.splice(index + pageSize * (currentPage - 1), 1, { ...cron, }); } @@ -442,7 +444,7 @@ const Crontab = () => { .then((data: any) => { const index = value.findIndex((x) => x._id === cron._id); const result = [...value]; - result.splice(index, 1, { + result.splice(index + pageSize * (currentPage - 1), 1, { ...cron, ...data.data, }); @@ -511,6 +513,12 @@ const Crontab = () => { }); }; + const onPageChange = (page: number, pageSize: number | undefined) => { + setCurrentPage(page); + setPageSize(pageSize as number); + localStorage.setItem('pageSize', pageSize + ''); + }; + useEffect(() => { if (logCron) { localStorage.setItem('logCron', logCron._id); @@ -532,6 +540,7 @@ const Crontab = () => { setMarginLeft(0); setMarginTop(-72); } + setPageSize(parseInt(localStorage.getItem('pageSize') || '20')); }, []); return ( @@ -602,6 +611,9 @@ const Crontab = () => { columns={columns} pagination={{ hideOnSinglePage: true, + current: currentPage, + onChange: onPageChange, + pageSize: pageSize, showSizeChanger: true, defaultPageSize: 20, showTotal: (total: number, range: number[]) => diff --git a/src/version.ts b/src/version.ts index 246fd666..d2123029 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1,2 +1,2 @@ -export const version = 'v2.2.0-062'; -export const changeLog = 'https://t.me/jiaolongwang/105'; +export const version = 'v2.2.0-063'; +export const changeLog = 'https://t.me/jiaolongwang/106';