From 0ae6fd68a4564f3277c894c7ce0e20be586e8891 Mon Sep 17 00:00:00 2001 From: whyour Date: Mon, 10 May 2021 00:02:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0timeout=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E5=80=BC=EF=BC=8C=E4=BF=AE=E6=94=B9session=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/services/cookie.ts | 22 +++++++++++++++++--- shell/share.sh | 2 ++ shell/task.sh | 6 +++--- shell/update.sh | 2 +- src/layouts/index.less | 2 +- src/pages/cookie/index.tsx | 41 ++++++++++++++++++------------------- src/pages/crontab/index.tsx | 1 + 7 files changed, 47 insertions(+), 29 deletions(-) diff --git a/back/services/cookie.ts b/back/services/cookie.ts index 6f96fbb5..af1469f1 100644 --- a/back/services/cookie.ts +++ b/back/services/cookie.ts @@ -121,6 +121,16 @@ export default class CookieService { }); } + private async formatCookies(cookies: Cookie[]) { + const result = []; + for (let i = 0; i < cookies.length; i++) { + const cookie = cookies[i]; + const { status, nickname } = await this.getJdInfo(cookie.value); + result.push({ ...cookie, status, nickname }); + } + return result; + } + public async create(payload: string[]): Promise { const cookies = await this.cookies(''); let position = initCookiePosition; @@ -135,7 +145,7 @@ export default class CookieService { }); const docs = await this.insert(tabs); await this.set_cookies(); - return docs; + return await this.formatCookies(docs); } public async insert(payload: Cookie[]): Promise { @@ -156,10 +166,11 @@ export default class CookieService { const tab = new Cookie({ ...doc, ...other }); const newDoc = await this.updateDb(tab); await this.set_cookies(); - return newDoc; + const [newCookie] = await this.formatCookies([newDoc]); + return newCookie; } - public async updateDb(payload: Cookie): Promise { + private async updateDb(payload: Cookie): Promise { return new Promise((resolve) => { this.cronDb.update( { _id: payload._id }, @@ -228,6 +239,11 @@ export default class CookieService { ], }; } + const newDocs = await this.find(query, sort); + return await this.formatCookies(newDocs); + } + + private async find(query: any, sort: any): Promise { return new Promise((resolve) => { this.cronDb .find(query) diff --git a/shell/share.sh b/shell/share.sh index 255bc9dc..ea310b9b 100755 --- a/shell/share.sh +++ b/shell/share.sh @@ -56,6 +56,8 @@ import_config() { let user_sum+=1 eval Cookie${user_sum}="\"$line\"" done + + command_timeout_time=${CommandTimeoutTime:-"1h"} } ## 创建目录,$1:目录的绝对路径 diff --git a/shell/task.sh b/shell/task.sh index 951934be..1b9827fc 100755 --- a/shell/task.sh +++ b/shell/task.sh @@ -116,7 +116,7 @@ run_normal() { log_dir="$dir_log/${p1%%.*}" log_path="$log_dir/$log_time.log" make_dir "$log_dir" - timeout $CommandTimeoutTime $which_program $p1 2>&1 | tee $log_path + timeout $command_timeout_time $which_program $p1 2>&1 | tee $log_path } ## 并发执行,因为是并发,所以日志只能直接记录在日志文件中(日志文件以Cookie编号结尾),前台执行并发跑时不会输出日志 @@ -132,7 +132,7 @@ run_concurrent() { for ((user_num = 1; user_num <= $user_sum; user_num++)); do combine_one $user_num log_path="$log_dir/${log_time}_${user_num}.log" - timeout $CommandTimeoutTime $which_program $p1 &>$log_path & + timeout $command_timeout_time $which_program $p1 &>$log_path & done } @@ -142,7 +142,7 @@ run_else() { local log_dir="$dir_log/$1" local log_path="$log_dir/$log_time.log" make_dir "$log_dir" - timeout $CommandTimeoutTime "$@" 2>&1 | tee $log_path + timeout $command_timeout_time "$@" 2>&1 | tee $log_path } ## 命令检测 diff --git a/shell/update.sh b/shell/update.sh index 60d192f9..f2d50f7f 100755 --- a/shell/update.sh +++ b/shell/update.sh @@ -117,7 +117,7 @@ del_cron() { rm -f "$dir_scripts/${cron}" detail="${detail}\n${result}" done - notify "删除失效任务通知" "$detail2" + notify "删除失效任务通知" "$detail" } ## 自动增加定时任务,需要:1.AutoAddCron 设置为 true;2.正常更新js脚本,没有报错;3.存在新任务;4.crontab.list存在并且不为空 diff --git a/src/layouts/index.less b/src/layouts/index.less index e0f8d31d..7329aca7 100644 --- a/src/layouts/index.less +++ b/src/layouts/index.less @@ -23,7 +23,7 @@ body { } } -.cookie-wrapper { +.session-wrapper { th { white-space: nowrap; } diff --git a/src/pages/cookie/index.tsx b/src/pages/cookie/index.tsx index 254478aa..7f2ff7f6 100644 --- a/src/pages/cookie/index.tsx +++ b/src/pages/cookie/index.tsx @@ -105,17 +105,17 @@ const Config = () => { return {index + 1} ; }, }, - { - title: '用户名', - dataIndex: 'pin', - key: 'pin', - align: 'center' as const, - render: (text: string, record: any) => { - const match = record.value.match(/pt_pin=([^; ]+)(?=;?)/); - const val = (match && match[1]) || '未匹配用户名'; - return {decodeUrl(val)}; - }, - }, + // { + // title: '用户名', + // dataIndex: 'pin', + // key: 'pin', + // align: 'center' as const, + // render: (text: string, record: any) => { + // const match = record.value.match(/pt_pin=([^; ]+)(?=;?)/); + // const val = (match && match[1]) || '未匹配用户名'; + // return {decodeUrl(val)}; + // }, + // }, { title: '昵称', dataIndex: 'nickname', @@ -231,11 +231,11 @@ const Config = () => { } }; - useEffect(() => { - if (value && loading) { - asyncUpdateStatus(); - } - }, [value]); + // useEffect(() => { + // if (value && loading) { + // asyncUpdateStatus(); + // } + // }, [value]); const asyncUpdateStatus = async () => { for (let i = 0; i < value.length; i++) { @@ -370,10 +370,10 @@ const Config = () => { }; const handleCookies = (cookies: any[]) => { + const result = [...value]; for (let i = 0; i < cookies.length; i++) { const cookie = cookies[i]; const index = value.findIndex((x) => x._id === cookie._id); - const result = [...value]; if (index === -1) { result.push(cookie); } else { @@ -381,9 +381,8 @@ const Config = () => { ...cookie, }); } - setValue(result); - refreshStatus(cookie, index); } + setValue(result); }; const components = { @@ -432,8 +431,8 @@ const Config = () => { return ( addCookie()}> 添加Cookie diff --git a/src/pages/crontab/index.tsx b/src/pages/crontab/index.tsx index c36509c1..6be6d27c 100644 --- a/src/pages/crontab/index.tsx +++ b/src/pages/crontab/index.tsx @@ -417,6 +417,7 @@ const Crontab = () => { notification.success({ message: '批量删除成功', }); + setSelectedRowIds([]); getCrons(); } else { notification.error({