增加timeout默认值,修改session管理逻辑

This commit is contained in:
whyour 2021-05-10 00:02:29 +08:00
parent a36926a5bd
commit 0ae6fd68a4
7 changed files with 47 additions and 29 deletions

View File

@ -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<Cookie[]> { public async create(payload: string[]): Promise<Cookie[]> {
const cookies = await this.cookies(''); const cookies = await this.cookies('');
let position = initCookiePosition; let position = initCookiePosition;
@ -135,7 +145,7 @@ export default class CookieService {
}); });
const docs = await this.insert(tabs); const docs = await this.insert(tabs);
await this.set_cookies(); await this.set_cookies();
return docs; return await this.formatCookies(docs);
} }
public async insert(payload: Cookie[]): Promise<Cookie[]> { public async insert(payload: Cookie[]): Promise<Cookie[]> {
@ -156,10 +166,11 @@ export default class CookieService {
const tab = new Cookie({ ...doc, ...other }); const tab = new Cookie({ ...doc, ...other });
const newDoc = await this.updateDb(tab); const newDoc = await this.updateDb(tab);
await this.set_cookies(); await this.set_cookies();
return newDoc; const [newCookie] = await this.formatCookies([newDoc]);
return newCookie;
} }
public async updateDb(payload: Cookie): Promise<Cookie> { private async updateDb(payload: Cookie): Promise<Cookie> {
return new Promise((resolve) => { return new Promise((resolve) => {
this.cronDb.update( this.cronDb.update(
{ _id: payload._id }, { _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<Cookie[]> {
return new Promise((resolve) => { return new Promise((resolve) => {
this.cronDb this.cronDb
.find(query) .find(query)

View File

@ -56,6 +56,8 @@ import_config() {
let user_sum+=1 let user_sum+=1
eval Cookie${user_sum}="\"$line\"" eval Cookie${user_sum}="\"$line\""
done done
command_timeout_time=${CommandTimeoutTime:-"1h"}
} }
## 创建目录,$1目录的绝对路径 ## 创建目录,$1目录的绝对路径

View File

@ -116,7 +116,7 @@ run_normal() {
log_dir="$dir_log/${p1%%.*}" log_dir="$dir_log/${p1%%.*}"
log_path="$log_dir/$log_time.log" log_path="$log_dir/$log_time.log"
make_dir "$log_dir" 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编号结尾前台执行并发跑时不会输出日志 ## 并发执行因为是并发所以日志只能直接记录在日志文件中日志文件以Cookie编号结尾前台执行并发跑时不会输出日志
@ -132,7 +132,7 @@ run_concurrent() {
for ((user_num = 1; user_num <= $user_sum; user_num++)); do for ((user_num = 1; user_num <= $user_sum; user_num++)); do
combine_one $user_num combine_one $user_num
log_path="$log_dir/${log_time}_${user_num}.log" 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 done
} }
@ -142,7 +142,7 @@ run_else() {
local log_dir="$dir_log/$1" local log_dir="$dir_log/$1"
local log_path="$log_dir/$log_time.log" local log_path="$log_dir/$log_time.log"
make_dir "$log_dir" make_dir "$log_dir"
timeout $CommandTimeoutTime "$@" 2>&1 | tee $log_path timeout $command_timeout_time "$@" 2>&1 | tee $log_path
} }
## 命令检测 ## 命令检测

View File

@ -117,7 +117,7 @@ del_cron() {
rm -f "$dir_scripts/${cron}" rm -f "$dir_scripts/${cron}"
detail="${detail}\n${result}" detail="${detail}\n${result}"
done done
notify "删除失效任务通知" "$detail2" notify "删除失效任务通知" "$detail"
} }
## 自动增加定时任务需要1.AutoAddCron 设置为 true2.正常更新js脚本没有报错3.存在新任务4.crontab.list存在并且不为空 ## 自动增加定时任务需要1.AutoAddCron 设置为 true2.正常更新js脚本没有报错3.存在新任务4.crontab.list存在并且不为空

View File

@ -23,7 +23,7 @@ body {
} }
} }
.cookie-wrapper { .session-wrapper {
th { th {
white-space: nowrap; white-space: nowrap;
} }

View File

@ -105,17 +105,17 @@ const Config = () => {
return <span style={{ cursor: 'text' }}>{index + 1} </span>; return <span style={{ cursor: 'text' }}>{index + 1} </span>;
}, },
}, },
{ // {
title: '用户名', // title: '用户名',
dataIndex: 'pin', // dataIndex: 'pin',
key: 'pin', // key: 'pin',
align: 'center' as const, // align: 'center' as const,
render: (text: string, record: any) => { // render: (text: string, record: any) => {
const match = record.value.match(/pt_pin=([^; ]+)(?=;?)/); // const match = record.value.match(/pt_pin=([^; ]+)(?=;?)/);
const val = (match && match[1]) || '未匹配用户名'; // const val = (match && match[1]) || '未匹配用户名';
return <span style={{ cursor: 'text' }}>{decodeUrl(val)}</span>; // return <span style={{ cursor: 'text' }}>{decodeUrl(val)}</span>;
}, // },
}, // },
{ {
title: '昵称', title: '昵称',
dataIndex: 'nickname', dataIndex: 'nickname',
@ -231,11 +231,11 @@ const Config = () => {
} }
}; };
useEffect(() => { // useEffect(() => {
if (value && loading) { // if (value && loading) {
asyncUpdateStatus(); // asyncUpdateStatus();
} // }
}, [value]); // }, [value]);
const asyncUpdateStatus = async () => { const asyncUpdateStatus = async () => {
for (let i = 0; i < value.length; i++) { for (let i = 0; i < value.length; i++) {
@ -370,10 +370,10 @@ const Config = () => {
}; };
const handleCookies = (cookies: any[]) => { const handleCookies = (cookies: any[]) => {
const result = [...value];
for (let i = 0; i < cookies.length; i++) { for (let i = 0; i < cookies.length; i++) {
const cookie = cookies[i]; const cookie = cookies[i];
const index = value.findIndex((x) => x._id === cookie._id); const index = value.findIndex((x) => x._id === cookie._id);
const result = [...value];
if (index === -1) { if (index === -1) {
result.push(cookie); result.push(cookie);
} else { } else {
@ -381,9 +381,8 @@ const Config = () => {
...cookie, ...cookie,
}); });
} }
setValue(result);
refreshStatus(cookie, index);
} }
setValue(result);
}; };
const components = { const components = {
@ -432,8 +431,8 @@ const Config = () => {
return ( return (
<PageContainer <PageContainer
className="cookie-wrapper" className="session-wrapper"
title="Cookie管理" title="Session管理"
extra={[ extra={[
<Button key="2" type="primary" onClick={() => addCookie()}> <Button key="2" type="primary" onClick={() => addCookie()}>
Cookie Cookie

View File

@ -417,6 +417,7 @@ const Crontab = () => {
notification.success({ notification.success({
message: '批量删除成功', message: '批量删除成功',
}); });
setSelectedRowIds([]);
getCrons(); getCrons();
} else { } else {
notification.error({ notification.error({