mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-23 06:46:09 +08:00
session api改为批量操作
This commit is contained in:
parent
bb469d4847
commit
189184832e
|
@ -62,17 +62,15 @@ export default (app: Router) => {
|
||||||
);
|
);
|
||||||
|
|
||||||
route.delete(
|
route.delete(
|
||||||
'/cookies/:id',
|
'/cookies',
|
||||||
celebrate({
|
celebrate({
|
||||||
params: Joi.object({
|
body: Joi.array().items(Joi.string().required()),
|
||||||
id: Joi.string().required(),
|
|
||||||
}),
|
|
||||||
}),
|
}),
|
||||||
async (req: Request, res: Response, next: NextFunction) => {
|
async (req: Request, res: Response, next: NextFunction) => {
|
||||||
const logger: Logger = Container.get('logger');
|
const logger: Logger = Container.get('logger');
|
||||||
try {
|
try {
|
||||||
const cookieService = Container.get(CookieService);
|
const cookieService = Container.get(CookieService);
|
||||||
const data = await cookieService.remove(req.params.id);
|
const data = await cookieService.remove(req.body);
|
||||||
return res.send({ code: 200, data });
|
return res.send({ code: 200, data });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.error('🔥 error: %o', e);
|
logger.error('🔥 error: %o', e);
|
||||||
|
@ -125,18 +123,16 @@ export default (app: Router) => {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
route.get(
|
route.put(
|
||||||
'/cookies/:id/disable',
|
'/cookies/disable',
|
||||||
celebrate({
|
celebrate({
|
||||||
params: Joi.object({
|
body: Joi.array().items(Joi.string().required()),
|
||||||
id: Joi.string().required(),
|
|
||||||
}),
|
|
||||||
}),
|
}),
|
||||||
async (req: Request, res: Response, next: NextFunction) => {
|
async (req: Request, res: Response, next: NextFunction) => {
|
||||||
const logger: Logger = Container.get('logger');
|
const logger: Logger = Container.get('logger');
|
||||||
try {
|
try {
|
||||||
const cookieService = Container.get(CookieService);
|
const cookieService = Container.get(CookieService);
|
||||||
const data = await cookieService.disabled(req.params.id);
|
const data = await cookieService.disabled(req.body);
|
||||||
return res.send({ code: 200, data });
|
return res.send({ code: 200, data });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.error('🔥 error: %o', e);
|
logger.error('🔥 error: %o', e);
|
||||||
|
@ -145,18 +141,16 @@ export default (app: Router) => {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
route.get(
|
route.put(
|
||||||
'/cookies/:id/enable',
|
'/cookies/enable',
|
||||||
celebrate({
|
celebrate({
|
||||||
params: Joi.object({
|
body: Joi.array().items(Joi.string().required()),
|
||||||
id: Joi.string().required(),
|
|
||||||
}),
|
|
||||||
}),
|
}),
|
||||||
async (req: Request, res: Response, next: NextFunction) => {
|
async (req: Request, res: Response, next: NextFunction) => {
|
||||||
const logger: Logger = Container.get('logger');
|
const logger: Logger = Container.get('logger');
|
||||||
try {
|
try {
|
||||||
const cookieService = Container.get(CookieService);
|
const cookieService = Container.get(CookieService);
|
||||||
const data = await cookieService.enabled(req.params.id);
|
const data = await cookieService.enabled(req.body);
|
||||||
return res.send({ code: 200, data });
|
return res.send({ code: 200, data });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.error('🔥 error: %o', e);
|
logger.error('🔥 error: %o', e);
|
||||||
|
|
|
@ -191,9 +191,13 @@ export default class CookieService {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async remove(_id: string) {
|
public async remove(ids: string[]) {
|
||||||
this.cronDb.remove({ _id }, {});
|
return new Promise((resolve: any) => {
|
||||||
await this.set_cookies();
|
this.cronDb.remove({ _id: { $in: ids } }, {}, async (err) => {
|
||||||
|
await this.set_cookies();
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async move(
|
public async move(
|
||||||
|
@ -283,29 +287,29 @@ export default class CookieService {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async disabled(_id: string) {
|
public async disabled(ids: string) {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve: any) => {
|
||||||
this.cronDb.update(
|
this.cronDb.update(
|
||||||
{ _id },
|
{ _id: { $in: ids } },
|
||||||
{ $set: { status: CookieStatus.disabled } },
|
{ $set: { status: CookieStatus.disabled } },
|
||||||
{},
|
{},
|
||||||
async (err) => {
|
async (err) => {
|
||||||
await this.set_cookies();
|
await this.set_cookies();
|
||||||
resolve(true);
|
resolve();
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async enabled(_id: string) {
|
public async enabled(ids: string) {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve: any) => {
|
||||||
this.cronDb.update(
|
this.cronDb.update(
|
||||||
{ _id },
|
{ _id: { $in: ids } },
|
||||||
{ $set: { status: CookieStatus.noacquired } },
|
{ $set: { status: CookieStatus.noacquired } },
|
||||||
{},
|
{},
|
||||||
async (err, num) => {
|
async (err, num) => {
|
||||||
await this.set_cookies();
|
await this.set_cookies();
|
||||||
resolve(true);
|
resolve();
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
|
@ -88,8 +88,16 @@ export default class CronService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async remove(ids: string[]) {
|
public async remove(ids: string[]) {
|
||||||
this.cronDb.remove({ _id: { $in: ids } }, { multi: true });
|
return new Promise((resolve: any) => {
|
||||||
await this.set_crontab(true);
|
this.cronDb.remove(
|
||||||
|
{ _id: { $in: ids } },
|
||||||
|
{ multi: true },
|
||||||
|
async (err) => {
|
||||||
|
await this.set_crontab(true);
|
||||||
|
resolve();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async crontabs(searchText?: string): Promise<Crontab[]> {
|
public async crontabs(searchText?: string): Promise<Crontab[]> {
|
||||||
|
@ -141,17 +149,21 @@ export default class CronService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async stop(ids: string[]) {
|
public async stop(ids: string[]) {
|
||||||
this.cronDb.find({ _id: { $in: ids } }).exec((err, docs: Crontab[]) => {
|
return new Promise((resolve: any) => {
|
||||||
this.cronDb.update(
|
this.cronDb.find({ _id: { $in: ids } }).exec((err, docs: Crontab[]) => {
|
||||||
{ _id: { $in: ids } },
|
this.cronDb.update(
|
||||||
{ $set: { status: CrontabStatus.idle }, $unset: { pid: true } },
|
{ _id: { $in: ids } },
|
||||||
);
|
{ $set: { status: CrontabStatus.idle }, $unset: { pid: true } },
|
||||||
const pids = docs
|
);
|
||||||
.map((x) => x.pid)
|
const pids = docs
|
||||||
.filter((x) => !!x)
|
.map((x) => x.pid)
|
||||||
.join('\n');
|
.filter((x) => !!x)
|
||||||
console.log(pids);
|
.join('\n');
|
||||||
exec(`echo - e "${pids}" | xargs kill - 9`);
|
console.log(pids);
|
||||||
|
exec(`echo - e "${pids}" | xargs kill - 9`, (err) => {
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -222,21 +234,31 @@ export default class CronService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async disabled(ids: string[]) {
|
public async disabled(ids: string[]) {
|
||||||
this.cronDb.update(
|
return new Promise((resolve: any) => {
|
||||||
{ _id: { $in: ids } },
|
this.cronDb.update(
|
||||||
{ $set: { isDisabled: 1 } },
|
{ _id: { $in: ids } },
|
||||||
{ multi: true },
|
{ $set: { isDisabled: 1 } },
|
||||||
);
|
{ multi: true },
|
||||||
await this.set_crontab(true);
|
async (err) => {
|
||||||
|
await this.set_crontab(true);
|
||||||
|
resolve();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async enabled(ids: string[]) {
|
public async enabled(ids: string[]) {
|
||||||
this.cronDb.update(
|
return new Promise((resolve: any) => {
|
||||||
{ _id: { $in: ids } },
|
this.cronDb.update(
|
||||||
{ $set: { isDisabled: 0 } },
|
{ _id: { $in: ids } },
|
||||||
{ multi: true },
|
{ $set: { isDisabled: 0 } },
|
||||||
);
|
{ multi: true },
|
||||||
await this.set_crontab(true);
|
async (err) => {
|
||||||
|
await this.set_crontab(true);
|
||||||
|
resolve();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async log(_id: string) {
|
public async log(_id: string) {
|
||||||
|
@ -289,7 +311,8 @@ export default class CronService {
|
||||||
|
|
||||||
lines.reverse().forEach((line, index) => {
|
lines.reverse().forEach((line, index) => {
|
||||||
line = line.replace(/\t+/g, ' ');
|
line = line.replace(/\t+/g, ' ');
|
||||||
var regex = /^((\@[a-zA-Z]+\s+)|(([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+))/;
|
var regex =
|
||||||
|
/^((\@[a-zA-Z]+\s+)|(([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+))/;
|
||||||
var command = line.replace(regex, '').trim();
|
var command = line.replace(regex, '').trim();
|
||||||
var schedule = line.replace(command, '').trim();
|
var schedule = line.replace(command, '').trim();
|
||||||
|
|
||||||
|
|
|
@ -187,7 +187,7 @@ const Config = () => {
|
||||||
</a>
|
</a>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
<Tooltip title={record.status === Status.已禁用 ? '启用' : '禁用'}>
|
<Tooltip title={record.status === Status.已禁用 ? '启用' : '禁用'}>
|
||||||
<a onClick={() => enabledOrDisabledCron(record, index)}>
|
<a onClick={() => enabledOrDisabledCookie(record, index)}>
|
||||||
{record.status === Status.已禁用 ? (
|
{record.status === Status.已禁用 ? (
|
||||||
<CheckCircleOutlined />
|
<CheckCircleOutlined />
|
||||||
) : (
|
) : (
|
||||||
|
@ -222,36 +222,6 @@ const Config = () => {
|
||||||
.finally(() => setLoading(false));
|
.finally(() => setLoading(false));
|
||||||
};
|
};
|
||||||
|
|
||||||
const decodeUrl = (val: string) => {
|
|
||||||
try {
|
|
||||||
const newUrl = decodeURIComponent(val);
|
|
||||||
return newUrl;
|
|
||||||
} catch (error) {
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// useEffect(() => {
|
|
||||||
// if (value && loading) {
|
|
||||||
// asyncUpdateStatus();
|
|
||||||
// }
|
|
||||||
// }, [value]);
|
|
||||||
|
|
||||||
const asyncUpdateStatus = async () => {
|
|
||||||
for (let i = 0; i < value.length; i++) {
|
|
||||||
const cookie = value[i];
|
|
||||||
if (cookie.status === Status.已禁用) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
await sleep(1000);
|
|
||||||
location.pathname === '/cookie' && refreshStatus(cookie, i);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const sleep = (time: number) => {
|
|
||||||
return new Promise((resolve) => setTimeout(resolve, time));
|
|
||||||
};
|
|
||||||
|
|
||||||
const refreshStatus = (record: any, index: number) => {
|
const refreshStatus = (record: any, index: number) => {
|
||||||
request
|
request
|
||||||
.get(`${config.apiPrefix}cookies/${record._id}/refresh`)
|
.get(`${config.apiPrefix}cookies/${record._id}/refresh`)
|
||||||
|
@ -265,7 +235,7 @@ const Config = () => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const enabledOrDisabledCron = (record: any, index: number) => {
|
const enabledOrDisabledCookie = (record: any, index: number) => {
|
||||||
Modal.confirm({
|
Modal.confirm({
|
||||||
title: `确认${record.status === Status.已禁用 ? '启用' : '禁用'}`,
|
title: `确认${record.status === Status.已禁用 ? '启用' : '禁用'}`,
|
||||||
content: (
|
content: (
|
||||||
|
@ -280,12 +250,12 @@ const Config = () => {
|
||||||
),
|
),
|
||||||
onOk() {
|
onOk() {
|
||||||
request
|
request
|
||||||
.get(
|
.put(
|
||||||
`${config.apiPrefix}cookies/${record._id}/${
|
`${config.apiPrefix}cookies/${
|
||||||
record.status === Status.已禁用 ? 'enable' : 'disable'
|
record.status === Status.已禁用 ? 'enable' : 'disable'
|
||||||
}`,
|
}`,
|
||||||
{
|
{
|
||||||
data: { _id: record._id },
|
data: [record._id],
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.then((data: any) => {
|
.then((data: any) => {
|
||||||
|
@ -340,7 +310,7 @@ const Config = () => {
|
||||||
),
|
),
|
||||||
onOk() {
|
onOk() {
|
||||||
request
|
request
|
||||||
.delete(`${config.apiPrefix}cookies/${record._id}`)
|
.delete(`${config.apiPrefix}cookies`, { data: [record._id] })
|
||||||
.then((data: any) => {
|
.then((data: any) => {
|
||||||
if (data.code === 200) {
|
if (data.code === 200) {
|
||||||
notification.success({
|
notification.success({
|
||||||
|
|
|
@ -103,7 +103,7 @@ const Crontab = () => {
|
||||||
align: 'center' as const,
|
align: 'center' as const,
|
||||||
render: (text: string, record: any) => (
|
render: (text: string, record: any) => (
|
||||||
<>
|
<>
|
||||||
{(!record.isDisabled || record.status !== CrontabStatus.idle) && (
|
{!record.isDisabled && (
|
||||||
<>
|
<>
|
||||||
{record.status === CrontabStatus.idle && (
|
{record.status === CrontabStatus.idle && (
|
||||||
<Tag icon={<ClockCircleOutlined />} color="default">
|
<Tag icon={<ClockCircleOutlined />} color="default">
|
||||||
|
@ -125,7 +125,7 @@ const Crontab = () => {
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
{record.isDisabled === 1 && record.status === CrontabStatus.idle && (
|
{record.isDisabled === 1 && (
|
||||||
<Tag icon={<CloseCircleOutlined />} color="error">
|
<Tag icon={<CloseCircleOutlined />} color="error">
|
||||||
已禁用
|
已禁用
|
||||||
</Tag>
|
</Tag>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user