mirror of
https://github.com/whyour/qinglong.git
synced 2026-08-11 19:05:20 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
88cf671465 | ||
|
|
29f082dea2 | ||
|
|
9a55968ed6 | ||
|
|
6ec6e25855 | ||
|
|
af48bc378b | ||
|
|
3f5ae4bcb9 | ||
|
|
c6624e9001 | ||
|
|
5530ce76e3 | ||
|
|
654b51e476 | ||
|
|
6428ac3624 | ||
|
|
c36450f436 | ||
|
|
dcea231249 | ||
|
|
f236119bd6 | ||
|
|
cb870fad85 | ||
|
|
44e2caedfc | ||
|
|
c0b5192296 | ||
|
|
ba43882c0b | ||
|
|
dfc706e16d | ||
|
|
25b03d4345 | ||
|
|
4e8f36d9a4 | ||
|
|
8f4d67ffa7 | ||
|
|
ad47277149 | ||
|
|
98c2a37ab6 | ||
|
|
f2fea47336 | ||
|
|
e274d3e2f9 | ||
|
|
36f4c3c02c | ||
|
|
ae891f8e55 | ||
|
|
c874dc9705 | ||
|
|
23bfbeb995 |
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
<p align="center">
|
<p align="center">
|
||||||
<a href="https://github.com/whyour/qinglong">
|
<a href="https://github.com/whyour/qinglong">
|
||||||
<img width="150" src="https://z3.ax1x.com/2021/11/18/I7MpAe.png">
|
<img width="150" src="https://user-images.githubusercontent.com/22700758/191449379-f9f56204-0e31-4a16-be5a-331f52696a73.png">
|
||||||
</a>
|
</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
@@ -183,7 +183,7 @@ task <file_path> desi <env_name> <account_number>
|
|||||||
- [crontab-ui](https://github.com/alseambusher/crontab-ui)
|
- [crontab-ui](https://github.com/alseambusher/crontab-ui)
|
||||||
- [Ant Design](https://ant.design)
|
- [Ant Design](https://ant.design)
|
||||||
- [Ant Design Pro](https://pro.ant.design/)
|
- [Ant Design Pro](https://pro.ant.design/)
|
||||||
- [Umijs3.0](https://umijs.org)
|
- [Umijs](https://umijs.org)
|
||||||
- [darkreader](https://github.com/darkreader/darkreader)
|
- [darkreader](https://github.com/darkreader/darkreader)
|
||||||
- [admin-server](https://github.com/sunpu007/admin-server)
|
- [admin-server](https://github.com/sunpu007/admin-server)
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<p align="center">
|
<p align="center">
|
||||||
<a href="https://github.com/whyour/qinglong">
|
<a href="https://github.com/whyour/qinglong">
|
||||||
<img width="150" src="https://z3.ax1x.com/2021/11/18/I7MpAe.png">
|
<img width="150" src="https://user-images.githubusercontent.com/22700758/191449379-f9f56204-0e31-4a16-be5a-331f52696a73.png">
|
||||||
</a>
|
</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
@@ -183,7 +183,7 @@ task <file_path> desi <env_name> <account_number>
|
|||||||
- [crontab-ui](https://github.com/alseambusher/crontab-ui)
|
- [crontab-ui](https://github.com/alseambusher/crontab-ui)
|
||||||
- [Ant Design](https://ant.design)
|
- [Ant Design](https://ant.design)
|
||||||
- [Ant Design Pro](https://pro.ant.design/)
|
- [Ant Design Pro](https://pro.ant.design/)
|
||||||
- [Umijs3.0](https://umijs.org)
|
- [Umijs](https://umijs.org)
|
||||||
- [darkreader](https://github.com/darkreader/darkreader)
|
- [darkreader](https://github.com/darkreader/darkreader)
|
||||||
- [admin-server](https://github.com/sunpu007/admin-server)
|
- [admin-server](https://github.com/sunpu007/admin-server)
|
||||||
|
|
||||||
|
|||||||
+32
-1
@@ -3,8 +3,9 @@ import { Container } from 'typedi';
|
|||||||
import { Logger } from 'winston';
|
import { Logger } from 'winston';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import config from '../config';
|
import config from '../config';
|
||||||
import { getFileContentByName, readDirs } from '../config/util';
|
import { emptyDir, getFileContentByName, readDirs } from '../config/util';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
|
import { celebrate, Joi } from 'celebrate';
|
||||||
const route = Router();
|
const route = Router();
|
||||||
const blacklist = ['.tmp'];
|
const blacklist = ['.tmp'];
|
||||||
|
|
||||||
@@ -45,4 +46,34 @@ export default (app: Router) => {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
route.delete(
|
||||||
|
'/',
|
||||||
|
celebrate({
|
||||||
|
body: Joi.object({
|
||||||
|
filename: Joi.string().required(),
|
||||||
|
path: Joi.string().allow(''),
|
||||||
|
type: Joi.string().optional()
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
async (req: Request, res: Response, next: NextFunction) => {
|
||||||
|
try {
|
||||||
|
let { filename, path, type } = req.body as {
|
||||||
|
filename: string;
|
||||||
|
path: string;
|
||||||
|
type: string;
|
||||||
|
};
|
||||||
|
const filePath = join(config.logPath, path, filename);
|
||||||
|
if (type === 'directory') {
|
||||||
|
emptyDir(filePath);
|
||||||
|
} else {
|
||||||
|
fs.unlinkSync(filePath);
|
||||||
|
}
|
||||||
|
res.send({ code: 200 });
|
||||||
|
} catch (e) {
|
||||||
|
return next(e);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
+9
-2
@@ -4,6 +4,7 @@ import {
|
|||||||
readDirs,
|
readDirs,
|
||||||
getLastModifyFilePath,
|
getLastModifyFilePath,
|
||||||
readDir,
|
readDir,
|
||||||
|
emptyDir,
|
||||||
} from '../config/util';
|
} from '../config/util';
|
||||||
import { Router, Request, Response, NextFunction } from 'express';
|
import { Router, Request, Response, NextFunction } from 'express';
|
||||||
import { Container } from 'typedi';
|
import { Container } from 'typedi';
|
||||||
@@ -169,17 +170,23 @@ export default (app: Router) => {
|
|||||||
body: Joi.object({
|
body: Joi.object({
|
||||||
filename: Joi.string().required(),
|
filename: Joi.string().required(),
|
||||||
path: Joi.string().allow(''),
|
path: Joi.string().allow(''),
|
||||||
|
type: Joi.string().optional()
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
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 {
|
||||||
let { filename, path } = req.body as {
|
let { filename, path, type } = req.body as {
|
||||||
filename: string;
|
filename: string;
|
||||||
path: string;
|
path: string;
|
||||||
|
type: string;
|
||||||
};
|
};
|
||||||
const filePath = join(config.scriptPath, path, filename);
|
const filePath = join(config.scriptPath, path, filename);
|
||||||
fs.unlinkSync(filePath);
|
if (type === 'directory') {
|
||||||
|
emptyDir(filePath);
|
||||||
|
} else {
|
||||||
|
fs.unlinkSync(filePath);
|
||||||
|
}
|
||||||
res.send({ code: 200 });
|
res.send({ code: 200 });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return next(e);
|
return next(e);
|
||||||
|
|||||||
+1
-1
@@ -17,7 +17,7 @@ async function startServer() {
|
|||||||
|
|
||||||
const server = app
|
const server = app
|
||||||
.listen(config.port, () => {
|
.listen(config.port, () => {
|
||||||
Logger.debug(`✌️ Back server launched on port ${config.port}`);
|
Logger.debug(`✌️ 后端服务启动成功!`);
|
||||||
})
|
})
|
||||||
.on('error', (err) => {
|
.on('error', (err) => {
|
||||||
Logger.error(err);
|
Logger.error(err);
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ if (!process.env.QL_DIR) {
|
|||||||
if (qlHomePath.endsWith('/static/')) {
|
if (qlHomePath.endsWith('/static/')) {
|
||||||
qlHomePath = path.join(qlHomePath, '../');
|
qlHomePath = path.join(qlHomePath, '../');
|
||||||
}
|
}
|
||||||
process.env.QL_DIR = qlHomePath;
|
process.env.QL_DIR = qlHomePath.replace(/\/$/g, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
const lastVersionFile = `http://qn.whyour.cn/version.ts?v=${Date.now()}`;
|
const lastVersionFile = `http://qn.whyour.cn/version.ts?v=${Date.now()}`;
|
||||||
|
|||||||
+45
-23
@@ -302,7 +302,6 @@ export function readDirs(
|
|||||||
title: file,
|
title: file,
|
||||||
key,
|
key,
|
||||||
type: 'directory',
|
type: 'directory',
|
||||||
disabled: true,
|
|
||||||
parent: relativePath,
|
parent: relativePath,
|
||||||
children: readDirs(subPath, baseDir).sort(
|
children: readDirs(subPath, baseDir).sort(
|
||||||
(a: any, b: any) =>
|
(a: any, b: any) =>
|
||||||
@@ -313,6 +312,7 @@ export function readDirs(
|
|||||||
return {
|
return {
|
||||||
title: file,
|
title: file,
|
||||||
type: 'file',
|
type: 'file',
|
||||||
|
isLeaf: true,
|
||||||
key,
|
key,
|
||||||
parent: relativePath,
|
parent: relativePath,
|
||||||
};
|
};
|
||||||
@@ -345,6 +345,20 @@ export function readDir(
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function emptyDir(path: string) {
|
||||||
|
const files = fs.readdirSync(path);
|
||||||
|
files.forEach((file) => {
|
||||||
|
const filePath = `${path}/${file}`;
|
||||||
|
const stats = fs.statSync(filePath);
|
||||||
|
if (stats.isDirectory()) {
|
||||||
|
emptyDir(filePath);
|
||||||
|
} else {
|
||||||
|
fs.unlinkSync(filePath);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
fs.rmdirSync(path);
|
||||||
|
}
|
||||||
|
|
||||||
export function promiseExec(command: string): Promise<string> {
|
export function promiseExec(command: string): Promise<string> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
exec(
|
exec(
|
||||||
@@ -365,22 +379,29 @@ export function parseHeaders(headers: string) {
|
|||||||
let val;
|
let val;
|
||||||
let i;
|
let i;
|
||||||
|
|
||||||
headers && headers.split('\n').forEach(function parser(line) {
|
headers &&
|
||||||
i = line.indexOf(':');
|
headers.split('\n').forEach(function parser(line) {
|
||||||
key = line.substring(0, i).trim().toLowerCase();
|
i = line.indexOf(':');
|
||||||
val = line.substring(i + 1).trim();
|
key = line.substring(0, i).trim().toLowerCase();
|
||||||
|
val = line.substring(i + 1).trim();
|
||||||
|
|
||||||
if (!key) {
|
if (!key) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
|
parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
|
||||||
});
|
});
|
||||||
|
|
||||||
return parsed;
|
return parsed;
|
||||||
};
|
}
|
||||||
|
|
||||||
export function parseBody(body: string, contentType: 'application/json' | 'multipart/form-data' | 'application/x-www-form-urlencoded') {
|
export function parseBody(
|
||||||
|
body: string,
|
||||||
|
contentType:
|
||||||
|
| 'application/json'
|
||||||
|
| 'multipart/form-data'
|
||||||
|
| 'application/x-www-form-urlencoded',
|
||||||
|
) {
|
||||||
if (!body) return '';
|
if (!body) return '';
|
||||||
|
|
||||||
const parsed: any = {};
|
const parsed: any = {};
|
||||||
@@ -388,22 +409,23 @@ export function parseBody(body: string, contentType: 'application/json' | 'multi
|
|||||||
let val;
|
let val;
|
||||||
let i;
|
let i;
|
||||||
|
|
||||||
body && body.split('\n').forEach(function parser(line) {
|
body &&
|
||||||
i = line.indexOf(':');
|
body.split('\n').forEach(function parser(line) {
|
||||||
key = line.substring(0, i).trim().toLowerCase();
|
i = line.indexOf(':');
|
||||||
val = line.substring(i + 1).trim();
|
key = line.substring(0, i).trim().toLowerCase();
|
||||||
|
val = line.substring(i + 1).trim();
|
||||||
|
|
||||||
if (!key || parsed[key]) {
|
if (!key || parsed[key]) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
parsed[key] = val;
|
parsed[key] = val;
|
||||||
});
|
});
|
||||||
|
|
||||||
switch (contentType) {
|
switch (contentType) {
|
||||||
case 'multipart/form-data':
|
case 'multipart/form-data':
|
||||||
return Object.keys(parsed).reduce((p, c) => {
|
return Object.keys(parsed).reduce((p, c) => {
|
||||||
p.append(c, parsed[c])
|
p.append(c, parsed[c]);
|
||||||
return p;
|
return p;
|
||||||
}, new FormData());
|
}, new FormData());
|
||||||
case 'application/x-www-form-urlencoded':
|
case 'application/x-www-form-urlencoded':
|
||||||
@@ -413,4 +435,4 @@ export function parseBody(body: string, contentType: 'application/json' | 'multi
|
|||||||
}
|
}
|
||||||
|
|
||||||
return parsed;
|
return parsed;
|
||||||
};
|
}
|
||||||
|
|||||||
@@ -18,13 +18,12 @@ export default async () => {
|
|||||||
tokenCommand = `node ${tokenFile}`;
|
tokenCommand = `node ${tokenFile}`;
|
||||||
}
|
}
|
||||||
const cron = {
|
const cron = {
|
||||||
id: 'token',
|
id: NaN,
|
||||||
name: '生成token',
|
name: '生成token',
|
||||||
command: tokenCommand,
|
command: tokenCommand,
|
||||||
};
|
};
|
||||||
scheduleService.createIntervalTask(cron as any, {
|
scheduleService.createIntervalTask(cron, {
|
||||||
days: 28,
|
days: 28,
|
||||||
runImmediately: true,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// 运行删除日志任务
|
// 运行删除日志任务
|
||||||
@@ -37,7 +36,6 @@ export default async () => {
|
|||||||
};
|
};
|
||||||
scheduleService.createIntervalTask(cron, {
|
scheduleService.createIntervalTask(cron, {
|
||||||
days: data.info.frequency,
|
days: data.info.frequency,
|
||||||
runImmediately: true,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,16 +2,23 @@ import { Application } from 'express';
|
|||||||
import * as Sentry from '@sentry/node';
|
import * as Sentry from '@sentry/node';
|
||||||
import * as Tracing from '@sentry/tracing';
|
import * as Tracing from '@sentry/tracing';
|
||||||
import Logger from './logger';
|
import Logger from './logger';
|
||||||
|
import config from '../config';
|
||||||
|
import fs from 'fs';
|
||||||
|
|
||||||
export default ({ expressApp }: { expressApp: Application }) => {
|
export default ({ expressApp }: { expressApp: Application }) => {
|
||||||
|
const versionRegx = /.*export const version = \'(.*)\'\;/;
|
||||||
|
|
||||||
|
const currentVersionFile = fs.readFileSync(config.versionFile, 'utf8');
|
||||||
|
const currentVersion = currentVersionFile.match(versionRegx)![1];
|
||||||
|
|
||||||
Sentry.init({
|
Sentry.init({
|
||||||
dsn: 'https://f4b5b55fb3c645b29a5dc2d70a1a4ef4@o1098464.ingest.sentry.io/6122819',
|
dsn: 'https://f4b5b55fb3c645b29a5dc2d70a1a4ef4@o1098464.ingest.sentry.io/6122819',
|
||||||
integrations: [
|
integrations: [
|
||||||
new Sentry.Integrations.Http({ tracing: true }),
|
new Sentry.Integrations.Http({ tracing: true }),
|
||||||
new Tracing.Integrations.Express({ app: expressApp }),
|
new Tracing.Integrations.Express({ app: expressApp }),
|
||||||
],
|
],
|
||||||
|
tracesSampleRate: 0.1,
|
||||||
tracesSampleRate: 1.0,
|
release: currentVersion,
|
||||||
});
|
});
|
||||||
|
|
||||||
expressApp.use(Sentry.Handlers.requestHandler());
|
expressApp.use(Sentry.Handlers.requestHandler());
|
||||||
|
|||||||
+1
-1
@@ -22,7 +22,7 @@ app
|
|||||||
await require('./loaders/sentry').default({ expressApp: app });
|
await require('./loaders/sentry').default({ expressApp: app });
|
||||||
await require('./loaders/db').default();
|
await require('./loaders/db').default();
|
||||||
|
|
||||||
Logger.debug(`✌️ Back server launched on port ${config.publicPort}`);
|
Logger.debug(`✌️ 公共服务启动成功!`);
|
||||||
})
|
})
|
||||||
.on('error', (err) => {
|
.on('error', (err) => {
|
||||||
Logger.error(err);
|
Logger.error(err);
|
||||||
|
|||||||
+1
-5
@@ -44,11 +44,7 @@ app
|
|||||||
await require('./loaders/db').default();
|
await require('./loaders/db').default();
|
||||||
|
|
||||||
await run();
|
await run();
|
||||||
Logger.info(`
|
Logger.debug('定时任务服务启动成功!');
|
||||||
################################################
|
|
||||||
🛡️ Schedule listening on port: ${config.cronPort} 🛡️
|
|
||||||
################################################
|
|
||||||
`);
|
|
||||||
})
|
})
|
||||||
.on('error', (err) => {
|
.on('error', (err) => {
|
||||||
Logger.error(err);
|
Logger.error(err);
|
||||||
|
|||||||
@@ -70,9 +70,8 @@ export default class SystemService {
|
|||||||
};
|
};
|
||||||
await this.scheduleService.cancelIntervalTask(cron);
|
await this.scheduleService.cancelIntervalTask(cron);
|
||||||
if (frequency > 0) {
|
if (frequency > 0) {
|
||||||
await this.scheduleService.createIntervalTask(cron, {
|
this.scheduleService.createIntervalTask(cron, {
|
||||||
days: frequency,
|
days: frequency,
|
||||||
runImmediately: true,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return { code: 200, data: { ...cron } };
|
return { code: 200, data: { ...cron } };
|
||||||
|
|||||||
+20
-15
@@ -24,7 +24,7 @@ export default class UserService {
|
|||||||
@Inject('logger') private logger: winston.Logger,
|
@Inject('logger') private logger: winston.Logger,
|
||||||
private scheduleService: ScheduleService,
|
private scheduleService: ScheduleService,
|
||||||
private sockService: SockService,
|
private sockService: SockService,
|
||||||
) {}
|
) { }
|
||||||
|
|
||||||
public async login(
|
public async login(
|
||||||
payloads: {
|
payloads: {
|
||||||
@@ -65,15 +65,13 @@ export default class UserService {
|
|||||||
return this.initAuthInfo();
|
return this.initAuthInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (retries > 2 && Date.now() - lastlogon < Math.pow(3, retries) * 1000) {
|
const retriesTime = Math.pow(3, retries) * 1000;
|
||||||
|
if (retries > 2 && timestamp - lastlogon < retriesTime) {
|
||||||
|
const waitTime = Math.ceil((retriesTime - (timestamp - lastlogon)) / 1000);
|
||||||
return {
|
return {
|
||||||
code: 410,
|
code: 410,
|
||||||
message: `失败次数过多,请${Math.round(
|
message: `失败次数过多,请${waitTime}秒后重试`,
|
||||||
(Math.pow(3, retries) * 1000 - Date.now() + lastlogon) / 1000,
|
data: waitTime,
|
||||||
)}秒后重试`,
|
|
||||||
data: Math.round(
|
|
||||||
(Math.pow(3, retries) * 1000 - Date.now() + lastlogon) / 1000,
|
|
||||||
),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,12 +83,12 @@ export default class UserService {
|
|||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
code: 420,
|
code: 420,
|
||||||
message: '请输入两步验证token',
|
message: '',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = createRandomString(50, 100);
|
const data = createRandomString(50, 100);
|
||||||
const expiration = twoFactorActivated ? 30 : 3;
|
const expiration = twoFactorActivated ? 60 : 20;
|
||||||
let token = jwt.sign({ data }, config.secret as any, {
|
let token = jwt.sign({ data }, config.secret as any, {
|
||||||
expiresIn: 60 * 60 * 24 * expiration,
|
expiresIn: 60 * 60 * 24 * expiration,
|
||||||
algorithm: 'HS384',
|
algorithm: 'HS384',
|
||||||
@@ -111,8 +109,7 @@ export default class UserService {
|
|||||||
});
|
});
|
||||||
await this.notificationService.notify(
|
await this.notificationService.notify(
|
||||||
'登录通知',
|
'登录通知',
|
||||||
`你于${dayjs(timestamp).format('YYYY-MM-DD HH:mm:ss')}在 ${address} ${
|
`你于${dayjs(timestamp).format('YYYY-MM-DD HH:mm:ss')}在 ${address} ${req.platform
|
||||||
req.platform
|
|
||||||
}端 登录成功,ip地址 ${ip}`,
|
}端 登录成功,ip地址 ${ip}`,
|
||||||
);
|
);
|
||||||
await this.getLoginLog();
|
await this.getLoginLog();
|
||||||
@@ -140,8 +137,7 @@ export default class UserService {
|
|||||||
});
|
});
|
||||||
await this.notificationService.notify(
|
await this.notificationService.notify(
|
||||||
'登录通知',
|
'登录通知',
|
||||||
`你于${dayjs(timestamp).format('YYYY-MM-DD HH:mm:ss')}在 ${address} ${
|
`你于${dayjs(timestamp).format('YYYY-MM-DD HH:mm:ss')}在 ${address} ${req.platform
|
||||||
req.platform
|
|
||||||
}端 登录失败,ip地址 ${ip}`,
|
}端 登录失败,ip地址 ${ip}`,
|
||||||
);
|
);
|
||||||
await this.getLoginLog();
|
await this.getLoginLog();
|
||||||
@@ -155,7 +151,16 @@ export default class UserService {
|
|||||||
status: LoginStatus.fail,
|
status: LoginStatus.fail,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
return { code: 400, message: config.authError };
|
if (retries > 2) {
|
||||||
|
const waitTime = Math.round(Math.pow(3, retries + 1));
|
||||||
|
return {
|
||||||
|
code: 410,
|
||||||
|
message: `失败次数过多,请${waitTime}秒后重试`,
|
||||||
|
data: waitTime,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return { code: 400, message: config.authError };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return this.initAuthInfo();
|
return this.initAuthInfo();
|
||||||
|
|||||||
@@ -14,12 +14,7 @@ cp -fv $nginx_app_conf /etc/nginx/conf.d/front.conf
|
|||||||
sed -i "s,QL_BASE_URL,${qlBaseUrl},g" /etc/nginx/conf.d/front.conf
|
sed -i "s,QL_BASE_URL,${qlBaseUrl},g" /etc/nginx/conf.d/front.conf
|
||||||
pm2 l &>/dev/null
|
pm2 l &>/dev/null
|
||||||
|
|
||||||
if [[ $PipMirror ]]; then
|
patch_version &>/dev/null
|
||||||
pip3 config set global.index-url $PipMirror
|
|
||||||
fi
|
|
||||||
if [[ $NpmMirror ]]; then
|
|
||||||
npm config set registry $NpmMirror
|
|
||||||
fi
|
|
||||||
echo
|
echo
|
||||||
|
|
||||||
echo -e "======================2. 安装依赖========================\n"
|
echo -e "======================2. 安装依赖========================\n"
|
||||||
@@ -47,13 +42,13 @@ echo -e "定时任务启动成功...\n"
|
|||||||
|
|
||||||
if [[ $AutoStartBot == true ]]; then
|
if [[ $AutoStartBot == true ]]; then
|
||||||
echo -e "======================7. 启动bot========================\n"
|
echo -e "======================7. 启动bot========================\n"
|
||||||
nohup ql bot >>$dir_log/start.log 2>&1 &
|
nohup ql bot >$dir_log/bot.log 2>&1 &
|
||||||
echo -e "bot后台启动中...\n"
|
echo -e "bot后台启动中...\n"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $EnableExtraShell == true ]]; then
|
if [[ $EnableExtraShell == true ]]; then
|
||||||
echo -e "======================8. 执行自定义脚本========================\n"
|
echo -e "======================8. 执行自定义脚本========================\n"
|
||||||
nohup ql extra >>$dir_log/start.log 2>&1 &
|
nohup ql extra >$dir_log/extra.log 2>&1 &
|
||||||
echo -e "自定义脚本后台执行中...\n"
|
echo -e "自定义脚本后台执行中...\n"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -125,12 +125,12 @@
|
|||||||
"qrcode.react": "^1.0.1",
|
"qrcode.react": "^1.0.1",
|
||||||
"query-string": "^7.1.1",
|
"query-string": "^7.1.1",
|
||||||
"rc-tween-one": "^3.0.6",
|
"rc-tween-one": "^3.0.6",
|
||||||
"react": "18.x",
|
"react": "18.2.0",
|
||||||
"react-codemirror2": "^7.2.1",
|
"react-codemirror2": "^7.2.1",
|
||||||
"react-diff-viewer": "^3.1.1",
|
"react-diff-viewer": "^3.1.1",
|
||||||
"react-dnd": "^14.0.2",
|
"react-dnd": "^14.0.2",
|
||||||
"react-dnd-html5-backend": "^14.0.0",
|
"react-dnd-html5-backend": "^14.0.0",
|
||||||
"react-dom": "18.x",
|
"react-dom": "18.2.0",
|
||||||
"react-split-pane": "^0.1.92",
|
"react-split-pane": "^0.1.92",
|
||||||
"sockjs-client": "^1.6.0",
|
"sockjs-client": "^1.6.0",
|
||||||
"ts-node": "^10.6.0",
|
"ts-node": "^10.6.0",
|
||||||
|
|||||||
@@ -19,6 +19,11 @@ RepoFileExtensions="js py"
|
|||||||
## 代理地址,支持http/https/socks,例如 http://127.0.0.1:7890
|
## 代理地址,支持http/https/socks,例如 http://127.0.0.1:7890
|
||||||
ProxyUrl=""
|
ProxyUrl=""
|
||||||
|
|
||||||
|
## 资源告警阙值,默认CPU 80%、内存80%、磁盘90%
|
||||||
|
CpuWarn=80
|
||||||
|
MemoryWarn=80
|
||||||
|
DiskWarn=90
|
||||||
|
|
||||||
## 设置定时任务执行的超时时间,默认1h,后缀"s"代表秒(默认值), "m"代表分, "h"代表小时, "d"代表天
|
## 设置定时任务执行的超时时间,默认1h,后缀"s"代表秒(默认值), "m"代表分, "h"代表小时, "d"代表天
|
||||||
CommandTimeoutTime="1h"
|
CommandTimeoutTime="1h"
|
||||||
|
|
||||||
|
|||||||
+160
-160
@@ -1,187 +1,187 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
get_token() {
|
get_token() {
|
||||||
token=$(cat $file_auth_token | jq -r .value)
|
token=$(cat $file_auth_token | jq -r .value)
|
||||||
}
|
}
|
||||||
|
|
||||||
add_cron_api() {
|
add_cron_api() {
|
||||||
local currentTimeStamp=$(date +%s)
|
local currentTimeStamp=$(date +%s)
|
||||||
if [[ $# -eq 1 ]]; then
|
if [[ $# -eq 1 ]]; then
|
||||||
local schedule=$(echo "$1" | awk -F ":" '{print $1}')
|
local schedule=$(echo "$1" | awk -F ":" '{print $1}')
|
||||||
local command=$(echo "$1" | awk -F ":" '{print $2}')
|
local command=$(echo "$1" | awk -F ":" '{print $2}')
|
||||||
local name=$(echo "$1" | awk -F ":" '{print $3}')
|
local name=$(echo "$1" | awk -F ":" '{print $3}')
|
||||||
else
|
else
|
||||||
local schedule=$1
|
local schedule=$1
|
||||||
local command=$2
|
local command=$2
|
||||||
local name=$3
|
local name=$3
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local api=$(
|
local api=$(
|
||||||
curl -s --noproxy "*" "http://0.0.0.0:5600/open/crons?t=$currentTimeStamp" \
|
curl -s --noproxy "*" "http://0.0.0.0:5600/open/crons?t=$currentTimeStamp" \
|
||||||
-H "Accept: application/json" \
|
-H "Accept: application/json" \
|
||||||
-H "Authorization: Bearer $token" \
|
-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 "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 "Content-Type: application/json;charset=UTF-8" \
|
||||||
-H "Origin: http://0.0.0.0:5700" \
|
-H "Origin: http://0.0.0.0:5700" \
|
||||||
-H "Referer: http://0.0.0.0:5700/crontab" \
|
-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" \
|
-H "Accept-Language: en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7" \
|
||||||
--data-raw "{\"name\":\"$name\",\"command\":\"$command\",\"schedule\":\"$schedule\"}" \
|
--data-raw "{\"name\":\"$name\",\"command\":\"$command\",\"schedule\":\"$schedule\"}" \
|
||||||
--compressed
|
--compressed
|
||||||
)
|
)
|
||||||
code=$(echo $api | jq -r .code)
|
code=$(echo $api | jq -r .code)
|
||||||
message=$(echo $api | jq -r .message)
|
message=$(echo $api | jq -r .message)
|
||||||
if [[ $code == 200 ]]; then
|
if [[ $code == 200 ]]; then
|
||||||
echo -e "$name -> 添加成功"
|
echo -e "$name -> 添加成功"
|
||||||
else
|
else
|
||||||
echo -e "$name -> 添加失败(${message})"
|
echo -e "$name -> 添加失败(${message})"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
update_cron_api() {
|
update_cron_api() {
|
||||||
local currentTimeStamp=$(date +%s)
|
local currentTimeStamp=$(date +%s)
|
||||||
if [[ $# -eq 1 ]]; then
|
if [[ $# -eq 1 ]]; then
|
||||||
local schedule=$(echo "$1" | awk -F ":" '{print $1}')
|
local schedule=$(echo "$1" | awk -F ":" '{print $1}')
|
||||||
local command=$(echo "$1" | awk -F ":" '{print $2}')
|
local command=$(echo "$1" | awk -F ":" '{print $2}')
|
||||||
local name=$(echo "$1" | awk -F ":" '{print $3}')
|
local name=$(echo "$1" | awk -F ":" '{print $3}')
|
||||||
local id=$(echo "$1" | awk -F ":" '{print $4}')
|
local id=$(echo "$1" | awk -F ":" '{print $4}')
|
||||||
else
|
else
|
||||||
local schedule=$1
|
local schedule=$1
|
||||||
local command=$2
|
local command=$2
|
||||||
local name=$3
|
local name=$3
|
||||||
local id=$4
|
local id=$4
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local api=$(
|
local api=$(
|
||||||
curl -s --noproxy "*" "http://0.0.0.0:5600/open/crons?t=$currentTimeStamp" \
|
curl -s --noproxy "*" "http://0.0.0.0:5600/open/crons?t=$currentTimeStamp" \
|
||||||
-X 'PUT' \
|
-X 'PUT' \
|
||||||
-H "Accept: application/json" \
|
-H "Accept: application/json" \
|
||||||
-H "Authorization: Bearer $token" \
|
-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 "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 "Content-Type: application/json;charset=UTF-8" \
|
||||||
-H "Origin: http://0.0.0.0:5700" \
|
-H "Origin: http://0.0.0.0:5700" \
|
||||||
-H "Referer: http://0.0.0.0:5700/crontab" \
|
-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" \
|
-H "Accept-Language: en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7" \
|
||||||
--data-raw "{\"name\":\"$name\",\"command\":\"$command\",\"schedule\":\"$schedule\",\"id\":\"$id\"}" \
|
--data-raw "{\"name\":\"$name\",\"command\":\"$command\",\"schedule\":\"$schedule\",\"id\":\"$id\"}" \
|
||||||
--compressed
|
--compressed
|
||||||
)
|
)
|
||||||
code=$(echo $api | jq -r .code)
|
code=$(echo $api | jq -r .code)
|
||||||
message=$(echo $api | jq -r .message)
|
message=$(echo $api | jq -r .message)
|
||||||
if [[ $code == 200 ]]; then
|
if [[ $code == 200 ]]; then
|
||||||
echo -e "$name -> 更新成功"
|
echo -e "$name -> 更新成功"
|
||||||
else
|
else
|
||||||
echo -e "$name -> 更新失败(${message})"
|
echo -e "$name -> 更新失败(${message})"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
update_cron_command_api() {
|
update_cron_command_api() {
|
||||||
local currentTimeStamp=$(date +%s)
|
local currentTimeStamp=$(date +%s)
|
||||||
if [[ $# -eq 1 ]]; then
|
if [[ $# -eq 1 ]]; then
|
||||||
local command=$(echo "$1" | awk -F ":" '{print $1}')
|
local command=$(echo "$1" | awk -F ":" '{print $1}')
|
||||||
local id=$(echo "$1" | awk -F ":" '{print $2}')
|
local id=$(echo "$1" | awk -F ":" '{print $2}')
|
||||||
else
|
else
|
||||||
local command=$1
|
local command=$1
|
||||||
local id=$2
|
local id=$2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local api=$(
|
local api=$(
|
||||||
curl -s --noproxy "*" "http://0.0.0.0:5600/open/crons?t=$currentTimeStamp" \
|
curl -s --noproxy "*" "http://0.0.0.0:5600/open/crons?t=$currentTimeStamp" \
|
||||||
-X 'PUT' \
|
-X 'PUT' \
|
||||||
-H "Accept: application/json" \
|
-H "Accept: application/json" \
|
||||||
-H "Authorization: Bearer $token" \
|
-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 "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 "Content-Type: application/json;charset=UTF-8" \
|
||||||
-H "Origin: http://0.0.0.0:5700" \
|
-H "Origin: http://0.0.0.0:5700" \
|
||||||
-H "Referer: http://0.0.0.0:5700/crontab" \
|
-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" \
|
-H "Accept-Language: en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7" \
|
||||||
--data-raw "{\"command\":\"$command\",\"id\":\"$id\"}" \
|
--data-raw "{\"command\":\"$command\",\"id\":\"$id\"}" \
|
||||||
--compressed
|
--compressed
|
||||||
)
|
)
|
||||||
code=$(echo $api | jq -r .code)
|
code=$(echo $api | jq -r .code)
|
||||||
message=$(echo $api | jq -r .message)
|
message=$(echo $api | jq -r .message)
|
||||||
if [[ $code == 200 ]]; then
|
if [[ $code == 200 ]]; then
|
||||||
echo -e "$command -> 更新成功"
|
echo -e "$command -> 更新成功"
|
||||||
else
|
else
|
||||||
echo -e "$command -> 更新失败(${message})"
|
echo -e "$command -> 更新失败(${message})"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
del_cron_api() {
|
del_cron_api() {
|
||||||
local ids=$1
|
local ids=$1
|
||||||
local currentTimeStamp=$(date +%s)
|
local currentTimeStamp=$(date +%s)
|
||||||
local api=$(
|
local api=$(
|
||||||
curl -s --noproxy "*" "http://0.0.0.0:5600/open/crons?t=$currentTimeStamp" \
|
curl -s --noproxy "*" "http://0.0.0.0:5600/open/crons?t=$currentTimeStamp" \
|
||||||
-X 'DELETE' \
|
-X 'DELETE' \
|
||||||
-H "Accept: application/json" \
|
-H "Accept: application/json" \
|
||||||
-H "Authorization: Bearer $token" \
|
-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 "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 "Content-Type: application/json;charset=UTF-8" \
|
||||||
-H "Origin: http://0.0.0.0:5700" \
|
-H "Origin: http://0.0.0.0:5700" \
|
||||||
-H "Referer: http://0.0.0.0:5700/crontab" \
|
-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" \
|
-H "Accept-Language: en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7" \
|
||||||
--data-raw "[$ids]" \
|
--data-raw "[$ids]" \
|
||||||
--compressed
|
--compressed
|
||||||
)
|
)
|
||||||
code=$(echo $api | jq -r .code)
|
code=$(echo $api | jq -r .code)
|
||||||
message=$(echo $api | jq -r .message)
|
message=$(echo $api | jq -r .message)
|
||||||
if [[ $code == 200 ]]; then
|
if [[ $code == 200 ]]; then
|
||||||
echo -e "成功"
|
echo -e "成功"
|
||||||
else
|
else
|
||||||
echo -e "失败(${message})"
|
echo -e "失败(${message})"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
update_cron() {
|
update_cron() {
|
||||||
local ids="$1"
|
local ids="$1"
|
||||||
local status="$2"
|
local status="$2"
|
||||||
local pid="${3:-''}"
|
local pid="${3:-''}"
|
||||||
local logPath="$4"
|
local logPath="$4"
|
||||||
local lastExecutingTime="${5:-0}"
|
local lastExecutingTime="${5:-0}"
|
||||||
local runningTime="${6:-0}"
|
local runningTime="${6:-0}"
|
||||||
local currentTimeStamp=$(date +%s)
|
local currentTimeStamp=$(date +%s)
|
||||||
local api=$(
|
local api=$(
|
||||||
curl -s --noproxy "*" "http://0.0.0.0:5600/open/crons/status?t=$currentTimeStamp" \
|
curl -s --noproxy "*" "http://0.0.0.0:5600/open/crons/status?t=$currentTimeStamp" \
|
||||||
-X 'PUT' \
|
-X 'PUT' \
|
||||||
-H "Accept: application/json" \
|
-H "Accept: application/json" \
|
||||||
-H "Authorization: Bearer $token" \
|
-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 "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 "Content-Type: application/json;charset=UTF-8" \
|
||||||
-H "Origin: http://0.0.0.0:5700" \
|
-H "Origin: http://0.0.0.0:5700" \
|
||||||
-H "Referer: http://0.0.0.0:5700/crontab" \
|
-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" \
|
-H "Accept-Language: en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7" \
|
||||||
--data-raw "{\"ids\":[$ids],\"status\":\"$status\",\"pid\":\"$pid\",\"log_path\":\"$logPath\",\"last_execution_time\":$lastExecutingTime,\"last_running_time\":$runningTime}" \
|
--data-raw "{\"ids\":[$ids],\"status\":\"$status\",\"pid\":\"$pid\",\"log_path\":\"$logPath\",\"last_execution_time\":$lastExecutingTime,\"last_running_time\":$runningTime}" \
|
||||||
--compressed
|
--compressed
|
||||||
)
|
)
|
||||||
code=$(echo $api | jq -r .code)
|
code=$(echo $api | jq -r .code)
|
||||||
message=$(echo $api | jq -r .message)
|
message=$(echo $api | jq -r .message)
|
||||||
if [[ $code != 200 ]]; then
|
if [[ $code != 200 ]]; then
|
||||||
echo -e "\n## 更新任务状态失败(${message})\n" >> $dir_log/$log_path
|
echo -e "\n## 更新任务状态失败(${message})\n" >>$dir_log/$log_path
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
notify_api() {
|
notify_api() {
|
||||||
local title=$1
|
local title=$1
|
||||||
local content=$2
|
local content=$2
|
||||||
local currentTimeStamp=$(date +%s)
|
local currentTimeStamp=$(date +%s)
|
||||||
local api=$(
|
local api=$(
|
||||||
curl -s --noproxy "*" "http://0.0.0.0:5600/open/system/notify?t=$currentTimeStamp" \
|
curl -s --noproxy "*" "http://0.0.0.0:5600/open/system/notify?t=$currentTimeStamp" \
|
||||||
-X 'PUT' \
|
-X 'PUT' \
|
||||||
-H "Accept: application/json" \
|
-H "Accept: application/json" \
|
||||||
-H "Authorization: Bearer $token" \
|
-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 "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 "Content-Type: application/json;charset=UTF-8" \
|
||||||
-H "Origin: http://0.0.0.0:5700" \
|
-H "Origin: http://0.0.0.0:5700" \
|
||||||
-H "Referer: http://0.0.0.0:5700/crontab" \
|
-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" \
|
-H "Accept-Language: en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7" \
|
||||||
--data-raw "{\"title\":\"$title\",\"content\":\"$content\"}" \
|
--data-raw "{\"title\":\"$title\",\"content\":\"$content\"}" \
|
||||||
--compressed
|
--compressed
|
||||||
)
|
)
|
||||||
code=$(echo $api | jq -r .code)
|
code=$(echo $api | jq -r .code)
|
||||||
message=$(echo $api | jq -r .message)
|
message=$(echo $api | jq -r .message)
|
||||||
if [[ $code == 200 ]]; then
|
if [[ $code == 200 ]]; then
|
||||||
echo -e "通知发送成功"
|
echo -e "通知发送成功"
|
||||||
else
|
else
|
||||||
echo -e "通知失败(${message})"
|
echo -e "通知失败(${message})"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
get_token
|
get_token
|
||||||
|
|||||||
+4
-5
@@ -35,11 +35,10 @@ fi
|
|||||||
cp -f "$repo_path/jbot/requirements.txt" "$dir_data"
|
cp -f "$repo_path/jbot/requirements.txt" "$dir_data"
|
||||||
|
|
||||||
cd $dir_data
|
cd $dir_data
|
||||||
cat requirements.txt | while read LREAD
|
cat requirements.txt | while read LREAD; do
|
||||||
do
|
if [[ ! $(pip3 show "${LREAD%%=*}" 2>/dev/null) ]]; then
|
||||||
if [[ ! $(pip3 show "${LREAD%%=*}" 2>/dev/null) ]]; then
|
pip3 --default-timeout=100 install ${LREAD}
|
||||||
pip3 --default-timeout=100 install ${LREAD}
|
fi
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
|
|
||||||
echo -e "\npython3依赖安装成功...\n"
|
echo -e "\npython3依赖安装成功...\n"
|
||||||
|
|||||||
+1
-1
@@ -29,4 +29,4 @@ git tag -a "$version" -m "release $version"
|
|||||||
echo -e "提交tag"
|
echo -e "提交tag"
|
||||||
git push --tags
|
git push --tags
|
||||||
|
|
||||||
echo -e "完成发布"
|
echo -e "完成发布"
|
||||||
|
|||||||
+23
-23
@@ -8,35 +8,35 @@ days=$1
|
|||||||
|
|
||||||
## 删除运行js脚本的旧日志
|
## 删除运行js脚本的旧日志
|
||||||
remove_js_log() {
|
remove_js_log() {
|
||||||
local log_full_path_list=$(find $dir_log/ -name "*.log")
|
local log_full_path_list=$(find $dir_log/ -name "*.log")
|
||||||
local diff_time
|
local diff_time
|
||||||
for log in $log_full_path_list; do
|
for log in $log_full_path_list; do
|
||||||
local log_date=$(echo $log | awk -F "/" '{print $NF}' | cut -c1-10) #文件名比文件属性获得的日期要可靠
|
local log_date=$(echo $log | awk -F "/" '{print $NF}' | cut -c1-10) #文件名比文件属性获得的日期要可靠
|
||||||
if [[ $(date +%s -d $log_date 2>/dev/null) ]]; then
|
if [[ $(date +%s -d $log_date 2>/dev/null) ]]; then
|
||||||
if [[ $is_macos -eq 1 ]]; then
|
if [[ $is_macos -eq 1 ]]; then
|
||||||
diff_time=$(($(date +%s) - $(date -j -f "%Y-%m-%d" "$log_date" +%s)))
|
diff_time=$(($(date +%s) - $(date -j -f "%Y-%m-%d" "$log_date" +%s)))
|
||||||
else
|
else
|
||||||
diff_time=$(($(date +%s) - $(date +%s -d "$log_date")))
|
diff_time=$(($(date +%s) - $(date +%s -d "$log_date")))
|
||||||
fi
|
fi
|
||||||
[[ $diff_time -gt $((${days} * 86400)) ]] && rm -vf $log
|
[[ $diff_time -gt $((${days} * 86400)) ]] && rm -vf $log
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
## 删除空文件夹
|
## 删除空文件夹
|
||||||
remove_empty_dir() {
|
remove_empty_dir() {
|
||||||
cd $dir_log
|
cd $dir_log
|
||||||
for dir in $(ls); do
|
for dir in $(ls); do
|
||||||
if [[ -d $dir ]] && [[ -z $(ls $dir) ]]; then
|
if [[ -d $dir ]] && [[ -z $(ls $dir) ]]; then
|
||||||
rm -rf $dir
|
rm -rf $dir
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
## 运行
|
## 运行
|
||||||
if [[ ${days} ]]; then
|
if [[ ${days} ]]; then
|
||||||
echo -e "查找旧日志文件中...\n"
|
echo -e "查找旧日志文件中...\n"
|
||||||
remove_js_log
|
remove_js_log
|
||||||
remove_empty_dir
|
remove_empty_dir
|
||||||
echo -e "删除旧日志执行完毕\n"
|
echo -e "删除旧日志执行完毕\n"
|
||||||
fi
|
fi
|
||||||
|
|||||||
+313
-256
@@ -50,377 +50,434 @@ list_own_drop=$dir_list_tmp/own_drop.list
|
|||||||
|
|
||||||
## 软连接及其原始文件对应关系
|
## 软连接及其原始文件对应关系
|
||||||
link_name=(
|
link_name=(
|
||||||
task
|
task
|
||||||
ql
|
ql
|
||||||
)
|
)
|
||||||
original_name=(
|
original_name=(
|
||||||
task.sh
|
task.sh
|
||||||
update.sh
|
update.sh
|
||||||
)
|
)
|
||||||
|
|
||||||
init_env() {
|
init_env() {
|
||||||
export NODE_PATH=/usr/local/bin:/usr/local/pnpm-global/5/node_modules:/usr/local/lib/node_modules:/root/.local/share/pnpm/global/5/node_modules
|
export NODE_PATH=/usr/local/bin:/usr/local/pnpm-global/5/node_modules:/usr/local/lib/node_modules:/root/.local/share/pnpm/global/5/node_modules
|
||||||
export PYTHONUNBUFFERED=1
|
export PYTHONUNBUFFERED=1
|
||||||
}
|
}
|
||||||
|
|
||||||
import_config() {
|
import_config() {
|
||||||
[[ -f $file_config_user ]] && . $file_config_user
|
[[ -f $file_config_user ]] && . $file_config_user
|
||||||
[[ -f $file_env ]] && . $file_env
|
[[ -f $file_env ]] && . $file_env
|
||||||
|
|
||||||
ql_base_url=${QlBaseUrl:-""}
|
ql_base_url=${QlBaseUrl:-""}
|
||||||
command_timeout_time=${CommandTimeoutTime:-"1h"}
|
command_timeout_time=${CommandTimeoutTime:-"1h"}
|
||||||
proxy_url=${ProxyUrl:-""}
|
proxy_url=${ProxyUrl:-""}
|
||||||
file_extensions=${RepoFileExtensions:-"js py"}
|
file_extensions=${RepoFileExtensions:-"js py"}
|
||||||
current_branch=${QL_BRANCH}
|
current_branch=${QL_BRANCH}
|
||||||
|
|
||||||
if [[ -n "${DefaultCronRule}" ]]; then
|
if [[ -n "${DefaultCronRule}" ]]; then
|
||||||
default_cron="${DefaultCronRule}"
|
default_cron="${DefaultCronRule}"
|
||||||
else
|
else
|
||||||
default_cron="$(random_range 0 59) $(random_range 0 23) * * *"
|
default_cron="$(random_range 0 59) $(random_range 0 23) * * *"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
cpu_warn=${CpuWarn:-80}
|
||||||
|
mem_warn=${MemoryWarn:-80}
|
||||||
|
disk_warn=${DiskWarn:-90}
|
||||||
}
|
}
|
||||||
|
|
||||||
set_proxy() {
|
set_proxy() {
|
||||||
if [[ $proxy_url ]]; then
|
if [[ $proxy_url ]]; then
|
||||||
export http_proxy="${proxy_url}"
|
export http_proxy="${proxy_url}"
|
||||||
export https_proxy="${proxy_url}"
|
export https_proxy="${proxy_url}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
unset_proxy() {
|
unset_proxy() {
|
||||||
unset http_proxy
|
unset http_proxy
|
||||||
unset https_proxy
|
unset https_proxy
|
||||||
}
|
}
|
||||||
|
|
||||||
make_dir() {
|
make_dir() {
|
||||||
local dir=$1
|
local dir=$1
|
||||||
if [[ ! -d $dir ]]; then
|
if [[ ! -d $dir ]]; then
|
||||||
mkdir -p $dir
|
mkdir -p $dir
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
detect_termux() {
|
detect_termux() {
|
||||||
if [[ $PATH == *com.termux* ]]; then
|
if [[ $PATH == *com.termux* ]]; then
|
||||||
is_termux=1
|
is_termux=1
|
||||||
else
|
else
|
||||||
is_termux=0
|
is_termux=0
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
detect_macos() {
|
detect_macos() {
|
||||||
[[ $(uname -s) == Darwin ]] && is_macos=1 || is_macos=0
|
[[ $(uname -s) == Darwin ]] && is_macos=1 || is_macos=0
|
||||||
}
|
}
|
||||||
|
|
||||||
gen_random_num() {
|
gen_random_num() {
|
||||||
local divi=$1
|
local divi=$1
|
||||||
echo $((${RANDOM} % $divi))
|
echo $((${RANDOM} % $divi))
|
||||||
}
|
}
|
||||||
|
|
||||||
link_shell_sub() {
|
link_shell_sub() {
|
||||||
local link_path="$1"
|
local link_path="$1"
|
||||||
local original_path="$2"
|
local original_path="$2"
|
||||||
if [[ ! -L $link_path ]] || [[ $(readlink -f $link_path) != $original_path ]]; then
|
if [[ ! -L $link_path ]] || [[ $(readlink -f $link_path) != $original_path ]]; then
|
||||||
rm -f $link_path 2>/dev/null
|
rm -f $link_path 2>/dev/null
|
||||||
ln -sf $original_path $link_path
|
ln -sf $original_path $link_path
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
link_shell() {
|
link_shell() {
|
||||||
if [[ $is_termux -eq 1 ]]; then
|
if [[ $is_termux -eq 1 ]]; then
|
||||||
local path="/data/data/com.termux/files/usr/bin/"
|
local path="/data/data/com.termux/files/usr/bin/"
|
||||||
elif [[ $PATH == */usr/local/bin* ]] && [[ -d /usr/local/bin ]]; then
|
elif [[ $PATH == */usr/local/bin* ]] && [[ -d /usr/local/bin ]]; then
|
||||||
local path="/usr/local/bin/"
|
local path="/usr/local/bin/"
|
||||||
else
|
else
|
||||||
local path=""
|
local path=""
|
||||||
echo -e "脚本功能受限,请自行添加命令的软连接...\n"
|
echo -e "脚本功能受限,请自行添加命令的软连接...\n"
|
||||||
fi
|
fi
|
||||||
if [[ $path ]]; then
|
if [[ $path ]]; then
|
||||||
for ((i = 0; i < ${#link_name[*]}; i++)); do
|
for ((i = 0; i < ${#link_name[*]}; i++)); do
|
||||||
link_shell_sub "$path${link_name[i]}" "$dir_shell/${original_name[i]}"
|
link_shell_sub "$path${link_name[i]}" "$dir_shell/${original_name[i]}"
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
define_cmd() {
|
define_cmd() {
|
||||||
local cmd_prefix cmd_suffix
|
local cmd_prefix cmd_suffix
|
||||||
if type task &>/dev/null; then
|
if type task &>/dev/null; then
|
||||||
cmd_suffix=""
|
cmd_suffix=""
|
||||||
if [[ -f "$dir_shell/task.sh" ]]; then
|
if [[ -f "$dir_shell/task.sh" ]]; then
|
||||||
cmd_prefix=""
|
cmd_prefix=""
|
||||||
else
|
|
||||||
cmd_prefix="bash "
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
cmd_suffix=".sh"
|
cmd_prefix="bash "
|
||||||
if [[ -f "$dir_shell/task.sh" ]]; then
|
|
||||||
cmd_prefix="$dir_shell/"
|
|
||||||
else
|
|
||||||
cmd_prefix="bash $dir_shell/"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
for ((i = 0; i < ${#link_name[*]}; i++)); do
|
else
|
||||||
export cmd_${link_name[i]}="${cmd_prefix}${link_name[i]}${cmd_suffix}"
|
cmd_suffix=".sh"
|
||||||
done
|
if [[ -f "$dir_shell/task.sh" ]]; then
|
||||||
|
cmd_prefix="$dir_shell/"
|
||||||
|
else
|
||||||
|
cmd_prefix="bash $dir_shell/"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
for ((i = 0; i < ${#link_name[*]}; i++)); do
|
||||||
|
export cmd_${link_name[i]}="${cmd_prefix}${link_name[i]}${cmd_suffix}"
|
||||||
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
fix_config() {
|
fix_config() {
|
||||||
make_dir $dir_static
|
make_dir $dir_static
|
||||||
make_dir $dir_data
|
make_dir $dir_data
|
||||||
make_dir $dir_config
|
make_dir $dir_config
|
||||||
make_dir $dir_log
|
make_dir $dir_log
|
||||||
make_dir $dir_db
|
make_dir $dir_db
|
||||||
make_dir $dir_scripts
|
make_dir $dir_scripts
|
||||||
make_dir $dir_list_tmp
|
make_dir $dir_list_tmp
|
||||||
make_dir $dir_repo
|
make_dir $dir_repo
|
||||||
make_dir $dir_raw
|
make_dir $dir_raw
|
||||||
make_dir $dir_update_log
|
make_dir $dir_update_log
|
||||||
make_dir $dir_dep
|
make_dir $dir_dep
|
||||||
|
|
||||||
if [[ ! -s $file_config_user ]]; then
|
if [[ ! -s $file_config_user ]]; then
|
||||||
echo -e "复制一份 $file_config_sample 为 $file_config_user,随后请按注释编辑你的配置文件:$file_config_user\n"
|
echo -e "复制一份 $file_config_sample 为 $file_config_user,随后请按注释编辑你的配置文件:$file_config_user\n"
|
||||||
cp -fv $file_config_sample $file_config_user
|
cp -fv $file_config_sample $file_config_user
|
||||||
echo
|
echo
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ ! -f $file_env ]]; then
|
if [[ ! -f $file_env ]]; then
|
||||||
echo -e "检测到config配置目录下不存在env.sh,创建一个空文件用于初始化...\n"
|
echo -e "检测到config配置目录下不存在env.sh,创建一个空文件用于初始化...\n"
|
||||||
touch $file_env
|
touch $file_env
|
||||||
echo
|
echo
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ ! -f $file_task_before ]]; then
|
if [[ ! -f $file_task_before ]]; then
|
||||||
echo -e "复制一份 $file_task_sample 为 $file_task_before\n"
|
echo -e "复制一份 $file_task_sample 为 $file_task_before\n"
|
||||||
cp -fv $file_task_sample $file_task_before
|
cp -fv $file_task_sample $file_task_before
|
||||||
echo
|
echo
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ ! -f $file_task_after ]]; then
|
if [[ ! -f $file_task_after ]]; then
|
||||||
echo -e "复制一份 $file_task_sample 为 $file_task_after\n"
|
echo -e "复制一份 $file_task_sample 为 $file_task_after\n"
|
||||||
cp -fv $file_task_sample $file_task_after
|
cp -fv $file_task_sample $file_task_after
|
||||||
echo
|
echo
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ ! -f $file_extra_shell ]]; then
|
if [[ ! -f $file_extra_shell ]]; then
|
||||||
echo -e "复制一份 $file_extra_sample 为 $file_extra_shell\n"
|
echo -e "复制一份 $file_extra_sample 为 $file_extra_shell\n"
|
||||||
cp -fv $file_extra_sample $file_extra_shell
|
cp -fv $file_extra_sample $file_extra_shell
|
||||||
echo
|
echo
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ ! -s $file_auth_user ]]; then
|
if [[ ! -s $file_auth_user ]]; then
|
||||||
echo -e "复制一份 $file_auth_sample 为 $file_auth_user\n"
|
echo -e "复制一份 $file_auth_sample 为 $file_auth_user\n"
|
||||||
cp -fv $file_auth_sample $file_auth_user
|
cp -fv $file_auth_sample $file_auth_user
|
||||||
echo
|
echo
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ ! -s $file_notify_py ]]; then
|
if [[ ! -s $file_notify_py ]]; then
|
||||||
echo -e "复制一份 $file_notify_py_sample 为 $file_notify_py\n"
|
echo -e "复制一份 $file_notify_py_sample 为 $file_notify_py\n"
|
||||||
cp -fv $file_notify_py_sample $file_notify_py
|
cp -fv $file_notify_py_sample $file_notify_py
|
||||||
echo
|
echo
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ ! -s $file_notify_js ]]; then
|
if [[ ! -s $file_notify_js ]]; then
|
||||||
echo -e "复制一份 $file_notify_js_sample 为 $file_notify_js\n"
|
echo -e "复制一份 $file_notify_js_sample 为 $file_notify_js\n"
|
||||||
cp -fv $file_notify_js_sample $file_notify_js
|
cp -fv $file_notify_js_sample $file_notify_js
|
||||||
echo
|
echo
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -s /etc/nginx/conf.d/default.conf ]]; then
|
if [[ -s /etc/nginx/conf.d/default.conf ]]; then
|
||||||
echo -e "检测到默认nginx配置文件,清空...\n"
|
echo -e "检测到默认nginx配置文件,清空...\n"
|
||||||
cat /dev/null >/etc/nginx/conf.d/default.conf
|
cat /dev/null >/etc/nginx/conf.d/default.conf
|
||||||
echo
|
echo
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ ! -s $dep_notify_js ]]; then
|
if [[ ! -s $dep_notify_js ]]; then
|
||||||
echo -e "复制一份 $file_notify_js_sample 为 $dep_notify_js\n"
|
echo -e "复制一份 $file_notify_js_sample 为 $dep_notify_js\n"
|
||||||
cp -fv $file_notify_js_sample $dep_notify_js
|
cp -fv $file_notify_js_sample $dep_notify_js
|
||||||
echo
|
echo
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ ! -s $dep_notify_py ]]; then
|
if [[ ! -s $dep_notify_py ]]; then
|
||||||
echo -e "复制一份 $file_notify_py_sample 为 $dep_notify_py\n"
|
echo -e "复制一份 $file_notify_py_sample 为 $dep_notify_py\n"
|
||||||
cp -fv $file_notify_py_sample $dep_notify_py
|
cp -fv $file_notify_py_sample $dep_notify_py
|
||||||
echo
|
echo
|
||||||
fi
|
fi
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
npm_install_sub() {
|
npm_install_sub() {
|
||||||
if [ $is_termux -eq 1 ]; then
|
if [ $is_termux -eq 1 ]; then
|
||||||
npm install --production --no-bin-links
|
npm install --production --no-bin-links
|
||||||
elif ! type pnpm &>/dev/null; then
|
elif ! type pnpm &>/dev/null; then
|
||||||
npm install --production
|
npm install --production
|
||||||
else
|
else
|
||||||
pnpm install --loglevel error --production
|
pnpm install --loglevel error --production
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
npm_install_1() {
|
npm_install_1() {
|
||||||
local dir_current=$(pwd)
|
local dir_current=$(pwd)
|
||||||
local dir_work=$1
|
local dir_work=$1
|
||||||
|
|
||||||
cd $dir_work
|
cd $dir_work
|
||||||
echo -e "运行 npm install...\n"
|
echo -e "运行 npm install...\n"
|
||||||
npm_install_sub
|
npm_install_sub
|
||||||
[[ $? -ne 0 ]] && echo -e "\nnpm install 运行不成功,请进入 $dir_work 目录后手动运行 npm install...\n"
|
[[ $? -ne 0 ]] && echo -e "\nnpm install 运行不成功,请进入 $dir_work 目录后手动运行 npm install...\n"
|
||||||
cd $dir_current
|
cd $dir_current
|
||||||
}
|
}
|
||||||
|
|
||||||
npm_install_2() {
|
npm_install_2() {
|
||||||
local dir_current=$(pwd)
|
local dir_current=$(pwd)
|
||||||
local dir_work=$1
|
local dir_work=$1
|
||||||
|
|
||||||
cd $dir_work
|
cd $dir_work
|
||||||
echo -e "检测到 $dir_work 的依赖包有变化,运行 npm install...\n"
|
echo -e "检测到 $dir_work 的依赖包有变化,运行 npm install...\n"
|
||||||
npm_install_sub
|
npm_install_sub
|
||||||
if [[ $? -ne 0 ]]; then
|
if [[ $? -ne 0 ]]; then
|
||||||
echo -e "\n安装 $dir_work 的依赖包运行不成功,再次尝试一遍...\n"
|
echo -e "\n安装 $dir_work 的依赖包运行不成功,再次尝试一遍...\n"
|
||||||
npm_install_1 $dir_work
|
npm_install_1 $dir_work
|
||||||
fi
|
fi
|
||||||
cd $dir_current
|
cd $dir_current
|
||||||
}
|
}
|
||||||
|
|
||||||
diff_and_copy() {
|
diff_and_copy() {
|
||||||
local copy_source=$1
|
local copy_source=$1
|
||||||
local copy_to=$2
|
local copy_to=$2
|
||||||
if [[ ! -s $copy_to ]] || [[ $(diff $copy_source $copy_to) ]]; then
|
if [[ ! -s $copy_to ]] || [[ $(diff $copy_source $copy_to) ]]; then
|
||||||
cp -f $copy_source $copy_to
|
cp -f $copy_source $copy_to
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
update_depend() {
|
update_depend() {
|
||||||
local dir_current=$(pwd)
|
local dir_current=$(pwd)
|
||||||
|
|
||||||
if [[ ! -s $dir_scripts/package.json ]] || [[ $(diff $dir_sample/package.json $dir_scripts/package.json) ]]; then
|
if [[ ! -s $dir_scripts/package.json ]] || [[ $(diff $dir_sample/package.json $dir_scripts/package.json) ]]; then
|
||||||
cp -f $dir_sample/package.json $dir_scripts/package.json
|
cp -f $dir_sample/package.json $dir_scripts/package.json
|
||||||
npm_install_2 $dir_scripts
|
npm_install_2 $dir_scripts
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cd $dir_current
|
cd $dir_current
|
||||||
}
|
}
|
||||||
|
|
||||||
git_clone_scripts() {
|
git_clone_scripts() {
|
||||||
local url=$1
|
local url=$1
|
||||||
local dir=$2
|
local dir=$2
|
||||||
local branch=$3
|
local branch=$3
|
||||||
[[ $branch ]] && local part_cmd="-b $branch "
|
[[ $branch ]] && local part_cmd="-b $branch "
|
||||||
echo -e "开始克隆仓库 $url 到 $dir\n"
|
echo -e "开始克隆仓库 $url 到 $dir\n"
|
||||||
|
|
||||||
set_proxy
|
set_proxy
|
||||||
git clone $part_cmd $url $dir
|
git clone $part_cmd $url $dir
|
||||||
exit_status=$?
|
exit_status=$?
|
||||||
unset_proxy
|
unset_proxy
|
||||||
}
|
}
|
||||||
|
|
||||||
git_pull_scripts() {
|
git_pull_scripts() {
|
||||||
local dir_current=$(pwd)
|
local dir_current=$(pwd)
|
||||||
local dir_work="$1"
|
local dir_work="$1"
|
||||||
local branch="$2"
|
local branch="$2"
|
||||||
cd $dir_work
|
cd $dir_work
|
||||||
echo -e "开始更新仓库:$dir_work\n"
|
echo -e "开始更新仓库:$dir_work\n"
|
||||||
|
|
||||||
set_proxy
|
set_proxy
|
||||||
git fetch --all
|
git fetch --all
|
||||||
exit_status=$?
|
exit_status=$?
|
||||||
git pull &>/dev/null
|
git pull &>/dev/null
|
||||||
unset_proxy
|
unset_proxy
|
||||||
reset_branch "$branch"
|
reset_branch "$branch"
|
||||||
|
|
||||||
cd $dir_current
|
cd $dir_current
|
||||||
}
|
}
|
||||||
|
|
||||||
reset_romote_url() {
|
reset_romote_url() {
|
||||||
local dir_current=$(pwd)
|
local dir_current=$(pwd)
|
||||||
local dir_work=$1
|
local dir_work=$1
|
||||||
local url=$2
|
local url=$2
|
||||||
local branch="$3"
|
local branch="$3"
|
||||||
|
|
||||||
if [[ -d "$dir_work/.git" ]]; then
|
if [[ -d "$dir_work/.git" ]]; then
|
||||||
cd $dir_work
|
cd $dir_work
|
||||||
[[ -f ".git/index.lock" ]] && rm -f .git/index.lock >/dev/null
|
[[ -f ".git/index.lock" ]] && rm -f .git/index.lock >/dev/null
|
||||||
git remote set-url origin $url &>/dev/null
|
git remote set-url origin $url &>/dev/null
|
||||||
|
|
||||||
local part_cmd=""
|
local part_cmd=""
|
||||||
reset_branch "$branch"
|
reset_branch "$branch"
|
||||||
cd $dir_current
|
cd $dir_current
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
reset_branch() {
|
reset_branch() {
|
||||||
local branch="$1"
|
local branch="$1"
|
||||||
if [[ $branch ]]; then
|
if [[ $branch ]]; then
|
||||||
part_cmd="origin/${branch}"
|
part_cmd="origin/${branch}"
|
||||||
git checkout -B "$branch"
|
git checkout -B "$branch" &>/dev/null
|
||||||
git branch --set-upstream-to=$part_cmd $branch
|
git branch --set-upstream-to=$part_cmd $branch &>/dev/null
|
||||||
fi
|
fi
|
||||||
git reset --hard $part_cmd &>/dev/null
|
git reset --hard $part_cmd &>/dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
random_range() {
|
random_range() {
|
||||||
local beg=$1
|
local beg=$1
|
||||||
local end=$2
|
local end=$2
|
||||||
echo $((RANDOM % ($end - $beg) + $beg))
|
echo $((RANDOM % ($end - $beg) + $beg))
|
||||||
}
|
}
|
||||||
|
|
||||||
reload_pm2() {
|
reload_pm2() {
|
||||||
pm2 l &>/dev/null
|
pm2 l &>/dev/null
|
||||||
|
|
||||||
echo -e "启动面板服务\n"
|
echo -e "启动面板服务\n"
|
||||||
pm2 delete panel --source-map-support --time &>/dev/null
|
pm2 delete panel --source-map-support --time &>/dev/null
|
||||||
pm2 start $dir_static/build/app.js -n panel --source-map-support --time &>/dev/null
|
pm2 start $dir_static/build/app.js -n panel --source-map-support --time &>/dev/null
|
||||||
|
|
||||||
echo -e "启动定时任务服务\n"
|
echo -e "启动定时任务服务\n"
|
||||||
pm2 delete schedule --source-map-support --time &>/dev/null
|
pm2 delete schedule --source-map-support --time &>/dev/null
|
||||||
pm2 start $dir_static/build/schedule.js -n schedule --source-map-support --time &>/dev/null
|
pm2 start $dir_static/build/schedule.js -n schedule --source-map-support --time &>/dev/null
|
||||||
|
|
||||||
echo -e "启动公开服务\n"
|
echo -e "启动公开服务\n"
|
||||||
pm2 delete public --source-map-support --time &>/dev/null
|
pm2 delete public --source-map-support --time &>/dev/null
|
||||||
pm2 start $dir_static/build/public.js -n public --source-map-support --time &>/dev/null
|
pm2 start $dir_static/build/public.js -n public --source-map-support --time &>/dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
diff_time() {
|
diff_time() {
|
||||||
local format="$1"
|
local format="$1"
|
||||||
local begin_time="$2"
|
local begin_time="$2"
|
||||||
local end_time="$3"
|
local end_time="$3"
|
||||||
|
|
||||||
if [[ $is_macos -eq 1 ]]; then
|
if [[ $is_macos -eq 1 ]]; then
|
||||||
diff_time=$(($(date -j -f "$format" "$end_time" +%s) - $(date -j -f "$format" "$begin_time" +%s)))
|
diff_time=$(($(date -j -f "$format" "$end_time" +%s) - $(date -j -f "$format" "$begin_time" +%s)))
|
||||||
else
|
else
|
||||||
diff_time=$(($(date +%s -d "$end_time") - $(date +%s -d "$begin_time")))
|
diff_time=$(($(date +%s -d "$end_time") - $(date +%s -d "$begin_time")))
|
||||||
fi
|
fi
|
||||||
echo "$diff_time"
|
echo "$diff_time"
|
||||||
}
|
}
|
||||||
|
|
||||||
format_time() {
|
format_time() {
|
||||||
local format="$1"
|
local format="$1"
|
||||||
local time="$2"
|
local time="$2"
|
||||||
|
|
||||||
if [[ $is_macos -eq 1 ]]; then
|
if [[ $is_macos -eq 1 ]]; then
|
||||||
echo $(date -j -f "$format" "$time" "+%Y-%m-%d %H:%M:%S")
|
echo $(date -j -f "$format" "$time" "+%Y-%m-%d %H:%M:%S")
|
||||||
else
|
else
|
||||||
echo $(date -d "$time" "+%Y-%m-%d %H:%M:%S")
|
echo $(date -d "$time" "+%Y-%m-%d %H:%M:%S")
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
format_log_time() {
|
format_log_time() {
|
||||||
local format="$1"
|
local format="$1"
|
||||||
local time="$2"
|
local time="$2"
|
||||||
|
|
||||||
if [[ $is_macos -eq 1 ]]; then
|
if [[ $is_macos -eq 1 ]]; then
|
||||||
echo $(date -j -f "$format" "$time" "+%Y-%m-%d-%H-%M-%S")
|
echo $(date -j -f "$format" "$time" "+%Y-%m-%d-%H-%M-%S")
|
||||||
else
|
else
|
||||||
echo $(date -d "$time" "+%Y-%m-%d-%H-%M-%S")
|
echo $(date -d "$time" "+%Y-%m-%d-%H-%M-%S")
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
format_timestamp() {
|
format_timestamp() {
|
||||||
local format="$1"
|
local format="$1"
|
||||||
local time="$2"
|
local time="$2"
|
||||||
|
|
||||||
if [[ $is_macos -eq 1 ]]; then
|
if [[ $is_macos -eq 1 ]]; then
|
||||||
echo $(date -j -f "$format" "$time" "+%s")
|
echo $(date -j -f "$format" "$time" "+%s")
|
||||||
else
|
else
|
||||||
echo $(date -d "$time" "+%s")
|
echo $(date -d "$time" "+%s")
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
patch_version() {
|
||||||
|
if [[ $PipMirror ]]; then
|
||||||
|
pip3 config set global.index-url $PipMirror
|
||||||
|
fi
|
||||||
|
if [[ $NpmMirror ]]; then
|
||||||
|
npm config set registry $NpmMirror
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 兼容pnpm@7
|
||||||
|
pnpm setup &>/dev/null
|
||||||
|
source ~/.bashrc
|
||||||
|
pnpm install -g &>/dev/null
|
||||||
|
|
||||||
|
if [[ -f "$dir_root/db/cookie.db" ]]; then
|
||||||
|
echo -e "检测到旧的db文件,拷贝为新db...\n"
|
||||||
|
mv $dir_root/db/cookie.db $dir_root/db/env.db
|
||||||
|
rm -rf $dir_root/db/cookie.db
|
||||||
|
echo
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! type ts-node &>/dev/null; then
|
||||||
|
pnpm add -g ts-node typescript tslib
|
||||||
|
fi
|
||||||
|
|
||||||
|
git config --global pull.rebase false
|
||||||
|
|
||||||
|
cp -f $dir_root/.env.example $dir_root/.env
|
||||||
|
|
||||||
|
if [[ -d "$dir_root/db" ]]; then
|
||||||
|
echo -e "检测到旧的db目录,拷贝到data目录...\n"
|
||||||
|
cp -rf $dir_root/config $dir_root/data
|
||||||
|
echo
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -d "$dir_root/scripts" ]]; then
|
||||||
|
echo -e "检测到旧的scripts目录,拷贝到data目录...\n"
|
||||||
|
cp -rf $dir_root/scripts $dir_root/data
|
||||||
|
echo
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -d "$dir_root/log" ]]; then
|
||||||
|
echo -e "检测到旧的log目录,拷贝到data目录...\n"
|
||||||
|
cp -rf $dir_root/log $dir_root/data
|
||||||
|
echo
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -d "$dir_root/config" ]]; then
|
||||||
|
echo -e "检测到旧的config目录,拷贝到data目录...\n"
|
||||||
|
cp -rf $dir_root/config $dir_root/data
|
||||||
|
echo
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
init_env
|
init_env
|
||||||
|
|||||||
+281
-284
@@ -7,355 +7,352 @@ dir_shell=$QL_DIR/shell
|
|||||||
|
|
||||||
## 选择python3还是node
|
## 选择python3还是node
|
||||||
define_program() {
|
define_program() {
|
||||||
local file_param=$1
|
local file_param=$1
|
||||||
if [[ $file_param == *.js ]]; then
|
if [[ $file_param == *.js ]]; then
|
||||||
which_program="node"
|
which_program="node"
|
||||||
elif [[ $file_param == *.py ]] || [[ $file_param == *.pyc ]]; then
|
elif [[ $file_param == *.py ]] || [[ $file_param == *.pyc ]]; then
|
||||||
which_program="python3"
|
which_program="python3"
|
||||||
elif [[ $file_param == *.sh ]]; then
|
elif [[ $file_param == *.sh ]]; then
|
||||||
which_program="bash"
|
which_program="bash"
|
||||||
elif [[ $file_param == *.ts ]]; then
|
elif [[ $file_param == *.ts ]]; then
|
||||||
which_program="ts-node-transpile-only"
|
which_program="ts-node-transpile-only"
|
||||||
else
|
else
|
||||||
which_program=""
|
which_program=""
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
random_delay() {
|
random_delay() {
|
||||||
local random_delay_max=$RandomDelay
|
local random_delay_max=$RandomDelay
|
||||||
if [[ $random_delay_max ]] && [[ $random_delay_max -gt 0 ]]; then
|
if [[ $random_delay_max ]] && [[ $random_delay_max -gt 0 ]]; then
|
||||||
local file_param=$1
|
local file_param=$1
|
||||||
local file_extensions=${RandomDelayFileExtensions-"js"}
|
local file_extensions=${RandomDelayFileExtensions-"js"}
|
||||||
local ignored_minutes=${RandomDelayIgnoredMinutes-"0 30"}
|
local ignored_minutes=${RandomDelayIgnoredMinutes-"0 30"}
|
||||||
|
|
||||||
if [[ -n $file_extensions ]]; then
|
if [[ -n $file_extensions ]]; then
|
||||||
if ! echo "$file_param" | grep -qE "\.${file_extensions// /$|\\.}$"; then
|
if ! echo "$file_param" | grep -qE "\.${file_extensions// /$|\\.}$"; then
|
||||||
# echo -e "\n当前文件需要准点运行, 放弃随机延迟\n"
|
# echo -e "\n当前文件需要准点运行, 放弃随机延迟\n"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
|
|
||||||
local current_min
|
|
||||||
current_min=$(date "+%-M")
|
|
||||||
for minute in $ignored_minutes; do
|
|
||||||
if [[ $current_min -eq $minute ]]; then
|
|
||||||
# echo -e "\n当前时间需要准点运行, 放弃随机延迟\n"
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
local delay_second=$(($(gen_random_num "$random_delay_max") + 1))
|
|
||||||
echo -e "\n命令未添加 \"now\",随机延迟 $delay_second 秒后再执行任务,如需立即终止,请按 CTRL+C...\n"
|
|
||||||
sleep $delay_second
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
local current_min
|
||||||
|
current_min=$(date "+%-M")
|
||||||
|
for minute in $ignored_minutes; do
|
||||||
|
if [[ $current_min -eq $minute ]]; then
|
||||||
|
# echo -e "\n当前时间需要准点运行, 放弃随机延迟\n"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
local delay_second=$(($(gen_random_num "$random_delay_max") + 1))
|
||||||
|
echo -e "\n命令未添加 \"now\",随机延迟 $delay_second 秒后再执行任务,如需立即终止,请按 CTRL+C...\n"
|
||||||
|
sleep $delay_second
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
## scripts目录下所有可运行脚本数组
|
## scripts目录下所有可运行脚本数组
|
||||||
gen_array_scripts() {
|
gen_array_scripts() {
|
||||||
local dir_current=$(pwd)
|
local dir_current=$(pwd)
|
||||||
local i="-1"
|
local i="-1"
|
||||||
cd $dir_scripts
|
cd $dir_scripts
|
||||||
for file in $(ls); do
|
for file in $(ls); do
|
||||||
if [[ -f $file ]] && [[ $file == *.js && $file != sendNotify.js ]]; then
|
if [[ -f $file ]] && [[ $file == *.js && $file != sendNotify.js ]]; then
|
||||||
let i++
|
let i++
|
||||||
array_scripts[i]=$(echo "$file" | perl -pe "s|$dir_scripts/||g")
|
array_scripts[i]=$(echo "$file" | perl -pe "s|$dir_scripts/||g")
|
||||||
array_scripts_name[i]=$(grep "new Env" $file | awk -F "'|\"" '{print $2}' | head -1)
|
array_scripts_name[i]=$(grep "new Env" $file | awk -F "'|\"" '{print $2}' | head -1)
|
||||||
[[ -z ${array_scripts_name[i]} ]] && array_scripts_name[i]="<未识别出活动名称>"
|
[[ -z ${array_scripts_name[i]} ]] && array_scripts_name[i]="<未识别出活动名称>"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
cd $dir_current
|
cd $dir_current
|
||||||
}
|
}
|
||||||
|
|
||||||
## 使用说明
|
## 使用说明
|
||||||
usage() {
|
usage() {
|
||||||
define_cmd
|
define_cmd
|
||||||
gen_array_scripts
|
gen_array_scripts
|
||||||
echo -e "task命令运行本程序自动添加进crontab的脚本,需要输入脚本的绝对路径或去掉 “$dir_scripts/” 目录后的相对路径(定时任务中请写作相对路径),用法为:"
|
echo -e "task命令运行本程序自动添加进crontab的脚本,需要输入脚本的绝对路径或去掉 “$dir_scripts/” 目录后的相对路径(定时任务中请写作相对路径),用法为:"
|
||||||
echo -e "1.$cmd_task <file_name> # 依次执行,如果设置了随机延迟,将随机延迟一定秒数"
|
echo -e "1.$cmd_task <file_name> # 依次执行,如果设置了随机延迟,将随机延迟一定秒数"
|
||||||
echo -e "2.$cmd_task <file_name> now # 依次执行,无论是否设置了随机延迟,均立即运行,前台会输出日志,同时记录在日志文件中"
|
echo -e "2.$cmd_task <file_name> now # 依次执行,无论是否设置了随机延迟,均立即运行,前台会输出日志,同时记录在日志文件中"
|
||||||
echo -e "3.$cmd_task <file_name> conc <环境变量名称> <账号编号,空格分隔>(可选的) # 并发执行,无论是否设置了随机延迟,均立即运行,前台不产生日志,直接记录在日志文件中,且可指定账号执行"
|
echo -e "3.$cmd_task <file_name> conc <环境变量名称> <账号编号,空格分隔>(可选的) # 并发执行,无论是否设置了随机延迟,均立即运行,前台不产生日志,直接记录在日志文件中,且可指定账号执行"
|
||||||
echo -e "4.$cmd_task <file_name> desi <环境变量名称> <账号编号,空格分隔> # 指定账号执行,无论是否设置了随机延迟,均立即运行"
|
echo -e "4.$cmd_task <file_name> desi <环境变量名称> <账号编号,空格分隔> # 指定账号执行,无论是否设置了随机延迟,均立即运行"
|
||||||
if [[ ${#array_scripts[*]} -gt 0 ]]; then
|
if [[ ${#array_scripts[*]} -gt 0 ]]; then
|
||||||
echo -e "\n当前有以下脚本可以运行:"
|
echo -e "\n当前有以下脚本可以运行:"
|
||||||
for ((i = 0; i < ${#array_scripts[*]}; i++)); do
|
for ((i = 0; i < ${#array_scripts[*]}; i++)); do
|
||||||
echo -e "$(($i + 1)). ${array_scripts_name[i]}:${array_scripts[i]}"
|
echo -e "$(($i + 1)). ${array_scripts_name[i]}:${array_scripts[i]}"
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
echo -e "\n暂无脚本可以执行"
|
echo -e "\n暂无脚本可以执行"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
## run nohup,$1:文件名,不含路径,带后缀
|
## run nohup,$1:文件名,不含路径,带后缀
|
||||||
run_nohup() {
|
run_nohup() {
|
||||||
local file_name=$1
|
local file_name=$1
|
||||||
nohup node $file_name &>$log_path &
|
nohup node $file_name &>$log_path &
|
||||||
}
|
}
|
||||||
|
|
||||||
handle_log_path() {
|
handle_log_path() {
|
||||||
define_program "$file_param"
|
define_program "$file_param"
|
||||||
|
|
||||||
local suffix=""
|
local suffix=""
|
||||||
if [[ ! -z $ID ]]; then
|
if [[ ! -z $ID ]]; then
|
||||||
suffix="_${ID}"
|
suffix="_${ID}"
|
||||||
|
fi
|
||||||
|
time=$(date "+$time_format")
|
||||||
|
log_time=$(format_log_time "$time_format" "$time")
|
||||||
|
log_dir_tmp="${file_param##*/}"
|
||||||
|
if [[ $file_param =~ "/" ]]; then
|
||||||
|
if [[ $file_param == /* ]]; then
|
||||||
|
log_dir_tmp_path="${file_param:1}"
|
||||||
|
else
|
||||||
|
log_dir_tmp_path="${file_param}"
|
||||||
fi
|
fi
|
||||||
time=$(date "+$time_format")
|
fi
|
||||||
log_time=$(format_log_time "$time_format" "$time")
|
log_dir_tmp_path="${log_dir_tmp_path%/*}"
|
||||||
log_dir_tmp="${file_param##*/}"
|
log_dir_tmp_path="${log_dir_tmp_path##*/}"
|
||||||
if [[ $file_param =~ "/" ]]; then
|
[[ $log_dir_tmp_path ]] && log_dir_tmp="${log_dir_tmp_path}_${log_dir_tmp}"
|
||||||
if [[ $file_param == /* ]]; then
|
log_dir="${log_dir_tmp%.*}${suffix}"
|
||||||
log_dir_tmp_path="${file_param:1}"
|
log_path="$log_dir/$log_time.log"
|
||||||
else
|
cmd=">> $dir_log/$log_path 2>&1"
|
||||||
log_dir_tmp_path="${file_param}"
|
[[ "$show_log" == "true" ]] && cmd=""
|
||||||
fi
|
make_dir "$dir_log/$log_dir"
|
||||||
fi
|
}
|
||||||
log_dir_tmp_path="${log_dir_tmp_path%/*}"
|
|
||||||
log_dir_tmp_path="${log_dir_tmp_path##*/}"
|
check_server() {
|
||||||
[[ $log_dir_tmp_path ]] && log_dir_tmp="${log_dir_tmp_path}_${log_dir_tmp}"
|
cpu_use=$(top -b -n 1 | grep CPU | grep -v -E 'grep|PID' | awk '{print $2}' | cut -f 1 -d "%")
|
||||||
log_dir="${log_dir_tmp%.*}${suffix}"
|
|
||||||
log_path="$log_dir/$log_time.log"
|
mem_free=$(free -m | grep "Mem" | awk '{print $3}')
|
||||||
cmd=">> $dir_log/$log_path 2>&1"
|
mem_total=$(free -m | grep "Mem" | awk '{print $2}')
|
||||||
[[ "$show_log" == "true" ]] && cmd=""
|
mem_use=$(printf "%d%%" $((mem_free * 100 / mem_total)) | cut -f 1 -d "%")
|
||||||
make_dir "$dir_log/$log_dir"
|
|
||||||
|
disk_use=$(df -P | grep /dev | grep -v -E '(tmp|boot|shm)' | awk '{print $5}' | cut -f 1 -d "%")
|
||||||
|
|
||||||
|
eval echo -e "\#\# 当前CPU占用 $cpu_use% 内存占用 $mem_use% 磁盘占用 $disk_use% \\\n" $cmd
|
||||||
|
if [[ $cpu_use -gt $cpu_warn ]] || [[ $mem_free -lt $mem_warn ]] || [[ $disk_use -gt $disk_warn ]]; then
|
||||||
|
echo -e "\#\# 服务器资源占用异常,本次任务跳过执行" $cmd
|
||||||
|
notify_api "服务器资源异常警告" "当前CPU占用 $cpu_use% 内存占用 $mem_use% 磁盘占用 $disk_use%"
|
||||||
|
|
||||||
|
end_time=$(date '+%Y-%m-%d %H:%M:%S')
|
||||||
|
diff_time=$(($end_timestamp - $begin_timestamp))
|
||||||
|
[[ $ID ]] && update_cron "\"$ID\"" "1" "" "$log_path" "$begin_timestamp" "$diff_time"
|
||||||
|
eval echo -e "\\\n\#\# 执行结束... $end_time 耗时 $diff_time 秒" $cmd
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
handle_task_before() {
|
||||||
|
handle_log_path
|
||||||
|
|
||||||
|
begin_time=$(format_time "$time_format" "$time")
|
||||||
|
begin_timestamp=$(format_timestamp "$time_format" "$time")
|
||||||
|
|
||||||
|
eval echo -e "\#\# 开始执行... $begin_time\\\n" $cmd
|
||||||
|
|
||||||
|
[[ $is_macos -eq 0 ]] && check_server
|
||||||
|
|
||||||
|
[[ -f $task_error_log_path ]] && eval cat $task_error_log_path $cmd
|
||||||
|
|
||||||
|
[[ $ID ]] && update_cron "\"$ID\"" "0" "$$" "$log_path" "$begin_timestamp"
|
||||||
|
eval . $file_task_before "$@" $cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
## 正常运行单个脚本,$1:传入参数
|
## 正常运行单个脚本,$1:传入参数
|
||||||
run_normal() {
|
run_normal() {
|
||||||
local file_param=$1
|
local file_param=$1
|
||||||
if [[ $# -eq 1 ]]; then
|
if [[ $# -eq 1 ]]; then
|
||||||
random_delay "$file_param"
|
random_delay "$file_param"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
handle_log_path
|
handle_task_before
|
||||||
|
|
||||||
local begin_time=$(format_time "$time_format" "$time")
|
cd $dir_scripts
|
||||||
local begin_timestamp=$(format_timestamp "$time_format" "$time")
|
local relative_path="${file_param%/*}"
|
||||||
|
if [[ ! -z ${relative_path} ]] && [[ ${file_param} =~ "/" ]]; then
|
||||||
eval echo -e "\#\# 开始执行... $begin_time\\\n" $cmd
|
cd ${relative_path}
|
||||||
[[ -f $task_error_log_path ]] && eval cat $task_error_log_path $cmd
|
file_param=${file_param/$relative_path\//}
|
||||||
|
fi
|
||||||
|
|
||||||
local id=$(cat $list_crontab_user | grep -E "$cmd_task $file_param" | perl -pe "s|.*ID=(.*) $cmd_task $file_param\.*|\1|" | head -1 | awk -F " " '{print $1}')
|
eval $timeoutCmd $which_program $file_param $cmd
|
||||||
[[ $id ]] && update_cron "\"$id\"" "0" "$$" "$log_path" "$begin_timestamp"
|
|
||||||
eval . $file_task_before "$@" $cmd
|
|
||||||
|
|
||||||
cd $dir_scripts
|
eval . $file_task_after "$@" $cmd
|
||||||
local relative_path="${file_param%/*}"
|
local end_time=$(date '+%Y-%m-%d %H:%M:%S')
|
||||||
if [[ ! -z ${relative_path} ]] && [[ ${file_param} =~ "/" ]]; then
|
local end_timestamp=$(date "+%s")
|
||||||
cd ${relative_path}
|
local diff_time=$(expr $end_timestamp - $begin_timestamp)
|
||||||
file_param=${file_param/$relative_path\//}
|
[[ $ID ]] && update_cron "\"$ID\"" "1" "" "$log_path" "$begin_timestamp" "$diff_time"
|
||||||
fi
|
eval echo -e "\\\n\#\# 执行结束... $end_time 耗时 $diff_time 秒" $cmd
|
||||||
|
|
||||||
eval $timeoutCmd $which_program $file_param $cmd
|
|
||||||
|
|
||||||
eval . $file_task_after "$@" $cmd
|
|
||||||
local end_time=$(date '+%Y-%m-%d %H:%M:%S')
|
|
||||||
local end_timestamp=$(date "+%s")
|
|
||||||
local diff_time=$(expr $end_timestamp - $begin_timestamp)
|
|
||||||
[[ $id ]] && update_cron "\"$id\"" "1" "" "$log_path" "$begin_timestamp" "$diff_time"
|
|
||||||
eval echo -e "\\\n\#\# 执行结束... $end_time 耗时 $diff_time 秒" $cmd
|
|
||||||
}
|
}
|
||||||
|
|
||||||
## 并发执行时,设定的 RandomDelay 不会生效,即所有任务立即执行
|
## 并发执行时,设定的 RandomDelay 不会生效,即所有任务立即执行
|
||||||
run_concurrent() {
|
run_concurrent() {
|
||||||
local file_param="$1"
|
local file_param="$1"
|
||||||
local env_param="$2"
|
local env_param="$2"
|
||||||
local num_param=$(echo "$3" | perl -pe "s|.*$2(.*)|\1|")
|
local num_param=$(echo "$3" | perl -pe "s|.*$2(.*)|\1|")
|
||||||
if [[ ! $env_param ]]; then
|
if [[ ! $env_param ]]; then
|
||||||
echo -e "\n 缺少并发运行的环境变量参数"
|
echo -e "\n 缺少并发运行的环境变量参数"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local envs=$(eval echo "\$${env_param}")
|
handle_task_before
|
||||||
local array=($(echo $envs | sed 's/&/ /g'))
|
|
||||||
local tempArr=$(echo $num_param | perl -pe "s|(\d+)(-\|~\|_)(\d+)|{\1..\3}|g")
|
|
||||||
local runArr=($(eval echo $tempArr))
|
|
||||||
runArr=($(awk -v RS=' ' '!a[$1]++' <<< ${runArr[@]}))
|
|
||||||
|
|
||||||
local n=0
|
local envs=$(eval echo "\$${env_param}")
|
||||||
for i in ${runArr[@]}; do
|
local array=($(echo $envs | sed 's/&/ /g'))
|
||||||
array_run[n]=${array[$i - 1]}
|
local tempArr=$(echo $num_param | perl -pe "s|(\d+)(-\|~\|_)(\d+)|{\1..\3}|g")
|
||||||
let n++
|
local runArr=($(eval echo $tempArr))
|
||||||
done
|
runArr=($(awk -v RS=' ' '!a[$1]++' <<<${runArr[@]}))
|
||||||
|
|
||||||
local cookieStr=$(echo ${array_run[*]} | sed 's/\ /\&/g')
|
local n=0
|
||||||
[[ ! -z $cookieStr ]] && export ${env_param}=${cookieStr}
|
for i in ${runArr[@]}; do
|
||||||
|
array_run[n]=${array[$i - 1]}
|
||||||
|
let n++
|
||||||
|
done
|
||||||
|
|
||||||
handle_log_path
|
local cookieStr=$(echo ${array_run[*]} | sed 's/\ /\&/g')
|
||||||
|
[[ ! -z $cookieStr ]] && export ${env_param}=${cookieStr}
|
||||||
|
|
||||||
local begin_time=$(format_time "$time_format" "$time")
|
local envs=$(eval echo "\$${env_param}")
|
||||||
local begin_timestamp=$(format_timestamp "$time_format" "$time")
|
local array=($(echo $envs | sed 's/&/ /g'))
|
||||||
|
single_log_time=$(date "+%Y-%m-%d-%H-%M-%S.%N")
|
||||||
|
|
||||||
eval echo -e "\#\# 开始执行... $begin_time\\\n" $cmd
|
cd $dir_scripts
|
||||||
[[ -f $task_error_log_path ]] && eval cat $task_error_log_path $cmd
|
local relative_path="${file_param%/*}"
|
||||||
|
if [[ ! -z ${relative_path} ]] && [[ ${file_param} =~ "/" ]]; then
|
||||||
|
cd ${relative_path}
|
||||||
|
file_param=${file_param/$relative_path\//}
|
||||||
|
fi
|
||||||
|
for i in "${!array[@]}"; do
|
||||||
|
export ${env_param}=${array[i]}
|
||||||
|
single_log_path="$dir_log/$log_dir/${single_log_time}_$((i + 1)).log"
|
||||||
|
eval $timeoutCmd $which_program $file_param &>$single_log_path &
|
||||||
|
done
|
||||||
|
|
||||||
local id=$(cat $list_crontab_user | grep -E "$cmd_task $file_param" | perl -pe "s|.*ID=(.*) $cmd_task $file_param\.*|\1|" | head -1 | awk -F " " '{print $1}')
|
wait
|
||||||
[[ $id ]] && update_cron "\"$id\"" "0" "$$" "$log_path" "$begin_timestamp"
|
for i in "${!array[@]}"; do
|
||||||
eval . $file_task_before "$@" $cmd
|
single_log_path="$dir_log/$log_dir/${single_log_time}_$((i + 1)).log"
|
||||||
|
eval cat $single_log_path $cmd
|
||||||
|
[[ -f $single_log_path ]] && rm -f $single_log_path
|
||||||
|
done
|
||||||
|
|
||||||
local envs=$(eval echo "\$${env_param}")
|
eval . $file_task_after "$@" $cmd
|
||||||
local array=($(echo $envs | sed 's/&/ /g'))
|
local end_time=$(date '+%Y-%m-%d %H:%M:%S')
|
||||||
single_log_time=$(date "+%Y-%m-%d-%H-%M-%S.%N")
|
local end_timestamp=$(date "+%s")
|
||||||
|
local diff_time=$(($end_timestamp - $begin_timestamp))
|
||||||
cd $dir_scripts
|
[[ $ID ]] && update_cron "\"$ID\"" "1" "" "$log_path" "$begin_timestamp" "$diff_time"
|
||||||
local relative_path="${file_param%/*}"
|
eval echo -e "\\\n\#\# 执行结束... $end_time 耗时 $diff_time 秒" $cmd
|
||||||
if [[ ! -z ${relative_path} ]] && [[ ${file_param} =~ "/" ]]; then
|
|
||||||
cd ${relative_path}
|
|
||||||
file_param=${file_param/$relative_path\//}
|
|
||||||
fi
|
|
||||||
for i in "${!array[@]}"; do
|
|
||||||
export ${env_param}=${array[i]}
|
|
||||||
single_log_path="$dir_log/$log_dir/${single_log_time}_$((i + 1)).log"
|
|
||||||
eval $timeoutCmd $which_program $file_param &>$single_log_path &
|
|
||||||
done
|
|
||||||
|
|
||||||
wait
|
|
||||||
for i in "${!array[@]}"; do
|
|
||||||
single_log_path="$dir_log/$log_dir/${single_log_time}_$((i + 1)).log"
|
|
||||||
eval cat $single_log_path $cmd
|
|
||||||
[[ -f $single_log_path ]] && rm -f $single_log_path
|
|
||||||
done
|
|
||||||
|
|
||||||
eval . $file_task_after "$@" $cmd
|
|
||||||
local end_time=$(date '+%Y-%m-%d %H:%M:%S')
|
|
||||||
local end_timestamp=$(date "+%s")
|
|
||||||
local diff_time=$(( $end_timestamp - $begin_timestamp ))
|
|
||||||
[[ $id ]] && update_cron "\"$id\"" "1" "" "$log_path" "$begin_timestamp" "$diff_time"
|
|
||||||
eval echo -e "\\\n\#\# 执行结束... $end_time 耗时 $diff_time 秒" $cmd
|
|
||||||
}
|
}
|
||||||
|
|
||||||
run_designated() {
|
run_designated() {
|
||||||
local file_param="$1"
|
local file_param="$1"
|
||||||
local env_param="$2"
|
local env_param="$2"
|
||||||
local num_param=$(echo "$3" | perl -pe "s|.*$2(.*)|\1|")
|
local num_param=$(echo "$3" | perl -pe "s|.*$2(.*)|\1|")
|
||||||
if [[ ! $env_param ]] || [[ ! $num_param ]]; then
|
if [[ ! $env_param ]] || [[ ! $num_param ]]; then
|
||||||
echo -e "\n 缺少单独运行的参数 task xxx.js desi Test 1 3"
|
echo -e "\n 缺少单独运行的参数 task xxx.js desi Test 1 3"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
handle_log_path
|
handle_task_before
|
||||||
|
|
||||||
local begin_time=$(format_time "$time_format" "$time")
|
local envs=$(eval echo "\$${env_param}")
|
||||||
local begin_timestamp=$(format_timestamp "$time_format" "$time")
|
local array=($(echo $envs | sed 's/&/ /g'))
|
||||||
|
local tempArr=$(echo $num_param | perl -pe "s|(\d+)(-\|~\|_)(\d+)|{\1..\3}|g")
|
||||||
|
local runArr=($(eval echo $tempArr))
|
||||||
|
runArr=($(awk -v RS=' ' '!a[$1]++' <<<${runArr[@]}))
|
||||||
|
|
||||||
local envs=$(eval echo "\$${env_param}")
|
local n=0
|
||||||
local array=($(echo $envs | sed 's/&/ /g'))
|
for i in ${runArr[@]}; do
|
||||||
local tempArr=$(echo $num_param | perl -pe "s|(\d+)(-\|~\|_)(\d+)|{\1..\3}|g")
|
array_run[n]=${array[$i - 1]}
|
||||||
local runArr=($(eval echo $tempArr))
|
let n++
|
||||||
runArr=($(awk -v RS=' ' '!a[$1]++' <<< ${runArr[@]}))
|
done
|
||||||
|
|
||||||
local n=0
|
local cookieStr=$(echo ${array_run[*]} | sed 's/\ /\&/g')
|
||||||
for i in ${runArr[@]}; do
|
[[ ! -z $cookieStr ]] && export ${env_param}=${cookieStr}
|
||||||
array_run[n]=${array[$i - 1]}
|
|
||||||
let n++
|
|
||||||
done
|
|
||||||
|
|
||||||
local cookieStr=$(echo ${array_run[*]} | sed 's/\ /\&/g')
|
cd $dir_scripts
|
||||||
[[ ! -z $cookieStr ]] && export ${env_param}=${cookieStr}
|
local relative_path="${file_param%/*}"
|
||||||
|
if [[ ! -z ${relative_path} ]] && [[ ${file_param} =~ "/" ]]; then
|
||||||
|
cd ${relative_path}
|
||||||
|
file_param=${file_param/$relative_path\//}
|
||||||
|
fi
|
||||||
|
eval $timeoutCmd $which_program $file_param $cmd
|
||||||
|
|
||||||
eval echo -e "\#\# 开始执行... $begin_time\\\n" $cmd
|
eval . $file_task_after "$@" $cmd
|
||||||
[[ -f $task_error_log_path ]] && eval cat $task_error_log_path $cmd
|
local end_time=$(date '+%Y-%m-%d %H:%M:%S')
|
||||||
|
local end_timestamp=$(date "+%s")
|
||||||
local id=$(cat $list_crontab_user | grep -E "$cmd_task $file_param" | perl -pe "s|.*ID=(.*) $cmd_task $file_param\.*|\1|" | head -1 | awk -F " " '{print $1}')
|
local diff_time=$(($end_timestamp - $begin_timestamp))
|
||||||
[[ $id ]] && update_cron "\"$id\"" "0" "$$" "$log_path" "$begin_timestamp"
|
[[ $ID ]] && update_cron "\"$ID\"" "1" "" "$log_path" "$begin_timestamp" "$diff_time"
|
||||||
eval . $file_task_before "$@" $cmd
|
eval echo -e "\\\n\#\# 执行结束... $end_time 耗时 $diff_time 秒" $cmd
|
||||||
|
|
||||||
cd $dir_scripts
|
|
||||||
local relative_path="${file_param%/*}"
|
|
||||||
if [[ ! -z ${relative_path} ]] && [[ ${file_param} =~ "/" ]]; then
|
|
||||||
cd ${relative_path}
|
|
||||||
file_param=${file_param/$relative_path\//}
|
|
||||||
fi
|
|
||||||
eval $timeoutCmd $which_program $file_param $cmd
|
|
||||||
|
|
||||||
eval . $file_task_after "$@" $cmd
|
|
||||||
local end_time=$(date '+%Y-%m-%d %H:%M:%S')
|
|
||||||
local end_timestamp=$(date "+%s")
|
|
||||||
local diff_time=$(( $end_timestamp - $begin_timestamp ))
|
|
||||||
[[ $id ]] && update_cron "\"$id\"" "1" "" "$log_path" "$begin_timestamp" "$diff_time"
|
|
||||||
eval echo -e "\\\n\#\# 执行结束... $end_time 耗时 $diff_time 秒" $cmd
|
|
||||||
}
|
}
|
||||||
|
|
||||||
## 运行其他命令
|
## 运行其他命令
|
||||||
run_else() {
|
run_else() {
|
||||||
local file_param="$1"
|
local file_param="$1"
|
||||||
|
|
||||||
handle_log_path
|
handle_task_before
|
||||||
|
|
||||||
local begin_time=$(format_time "$time_format" "$time")
|
cd $dir_scripts
|
||||||
local begin_timestamp=$(format_timestamp "$time_format" "$time")
|
local relative_path="${file_param%/*}"
|
||||||
|
if [[ ! -z ${relative_path} ]] && [[ ${file_param} =~ "/" ]]; then
|
||||||
|
cd ${relative_path}
|
||||||
|
file_param=${file_param/$relative_path\//}
|
||||||
|
fi
|
||||||
|
|
||||||
eval echo -e "\#\# 开始执行... $begin_time\\\n" $cmd
|
shift
|
||||||
[[ -f $task_error_log_path ]] && eval cat $task_error_log_path $cmd
|
eval $timeoutCmd $which_program "$file_param" "$@" $cmd
|
||||||
|
|
||||||
local id=$(cat $list_crontab_user | grep -E "$cmd_task $@" | perl -pe "s|.*ID=(.*) $cmd_task $@\.*|\1|" | head -1 | awk -F " " '{print $1}')
|
eval . $file_task_after "$file_param" "$@" $cmd
|
||||||
[[ $id ]] && update_cron "\"$id\"" "0" "$$" "$log_path" "$begin_timestamp"
|
local end_time=$(date '+%Y-%m-%d %H:%M:%S')
|
||||||
eval . $file_task_before "$@" $cmd
|
local end_timestamp=$(date "+%s")
|
||||||
|
local diff_time=$(($end_timestamp - $begin_timestamp))
|
||||||
cd $dir_scripts
|
[[ $ID ]] && update_cron "\"$ID\"" "1" "" "$log_path" "$begin_timestamp" "$diff_time"
|
||||||
local relative_path="${file_param%/*}"
|
eval echo -e "\\\n\#\# 执行结束... $end_time 耗时 $diff_time 秒" $cmd
|
||||||
if [[ ! -z ${relative_path} ]] && [[ ${file_param} =~ "/" ]]; then
|
|
||||||
cd ${relative_path}
|
|
||||||
file_param=${file_param/$relative_path\//}
|
|
||||||
fi
|
|
||||||
|
|
||||||
shift
|
|
||||||
eval $timeoutCmd $which_program "$file_param" "$@" $cmd
|
|
||||||
|
|
||||||
eval . $file_task_after "$file_param" "$@" $cmd
|
|
||||||
local end_time=$(date '+%Y-%m-%d %H:%M:%S')
|
|
||||||
local end_timestamp=$(date "+%s")
|
|
||||||
local diff_time=$(( $end_timestamp - $begin_timestamp ))
|
|
||||||
[[ $id ]] && update_cron "\"$id\"" "1" "" "$log_path" "$begin_timestamp" "$diff_time"
|
|
||||||
eval echo -e "\\\n\#\# 执行结束... $end_time 耗时 $diff_time 秒" $cmd
|
|
||||||
}
|
}
|
||||||
|
|
||||||
## 命令检测
|
## 命令检测
|
||||||
main() {
|
main() {
|
||||||
show_log="false"
|
show_log="false"
|
||||||
while getopts ":l" opt
|
while getopts ":l" opt; do
|
||||||
do
|
case $opt in
|
||||||
case $opt in
|
l)
|
||||||
l)
|
show_log="true"
|
||||||
show_log="true"
|
;;
|
||||||
;;
|
esac
|
||||||
esac
|
done
|
||||||
done
|
[[ "$show_log" == "true" ]] && shift $(($OPTIND - 1))
|
||||||
[[ "$show_log" == "true" ]] && shift $(($OPTIND - 1))
|
|
||||||
|
|
||||||
timeoutCmd=""
|
timeoutCmd=""
|
||||||
if type timeout &>/dev/null; then
|
if type timeout &>/dev/null; then
|
||||||
timeoutCmd="timeout -k 10s $command_timeout_time "
|
timeoutCmd="timeout -k 10s $command_timeout_time "
|
||||||
fi
|
fi
|
||||||
|
|
||||||
time_format="%Y-%m-%d %H:%M:%S"
|
time_format="%Y-%m-%d %H:%M:%S"
|
||||||
if [[ $1 == *.js ]] || [[ $1 == *.py ]] || [[ $1 == *.pyc ]] || [[ $1 == *.sh ]] || [[ $1 == *.ts ]]; then
|
if [[ $1 == *.js ]] || [[ $1 == *.py ]] || [[ $1 == *.pyc ]] || [[ $1 == *.sh ]] || [[ $1 == *.ts ]]; then
|
||||||
case $# in
|
case $# in
|
||||||
1)
|
1)
|
||||||
run_normal "$1"
|
run_normal "$1"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
case $2 in
|
case $2 in
|
||||||
now)
|
now)
|
||||||
run_normal "$1" "$2"
|
run_normal "$1" "$2"
|
||||||
;;
|
;;
|
||||||
conc)
|
conc)
|
||||||
run_concurrent "$1" "$3" "$*"
|
run_concurrent "$1" "$3" "$*"
|
||||||
;;
|
;;
|
||||||
desi)
|
desi)
|
||||||
run_designated "$1" "$3" "$*"
|
run_designated "$1" "$3" "$*"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
run_else "$@"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
[[ -f "$dir_log/$log_path" ]] && cat "$dir_log/$log_path"
|
|
||||||
elif [[ $# -eq 0 ]]; then
|
|
||||||
echo
|
|
||||||
usage
|
|
||||||
else
|
|
||||||
run_else "$@"
|
run_else "$@"
|
||||||
fi
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
[[ -f "$dir_log/$log_path" ]] && cat "$dir_log/$log_path"
|
||||||
|
elif [[ $# -eq 0 ]]; then
|
||||||
|
echo
|
||||||
|
usage
|
||||||
|
else
|
||||||
|
run_else "$@"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
main "$@"
|
main "$@"
|
||||||
|
|||||||
+393
-444
@@ -8,554 +8,503 @@ send_mark=$dir_shell/send_mark
|
|||||||
|
|
||||||
## 检测cron的差异,$1:脚本清单文件路径,$2:cron任务清单文件路径,$3:增加任务清单文件路径,$4:删除任务清单文件路径
|
## 检测cron的差异,$1:脚本清单文件路径,$2:cron任务清单文件路径,$3:增加任务清单文件路径,$4:删除任务清单文件路径
|
||||||
diff_cron() {
|
diff_cron() {
|
||||||
local list_scripts="$1"
|
local list_scripts="$1"
|
||||||
local list_task="$2"
|
local list_task="$2"
|
||||||
local list_add="$3"
|
local list_add="$3"
|
||||||
local list_drop="$4"
|
local list_drop="$4"
|
||||||
if [[ -s $list_task ]] && [[ -s $list_scripts ]]; then
|
if [[ -s $list_task ]] && [[ -s $list_scripts ]]; then
|
||||||
grep -vwf $list_task $list_scripts >$list_add
|
grep -vwf $list_task $list_scripts >$list_add
|
||||||
grep -vwf $list_scripts $list_task >$list_drop
|
grep -vwf $list_scripts $list_task >$list_drop
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ ! -s $list_task ]] && [[ -s $list_scripts ]]; then
|
if [[ ! -s $list_task ]] && [[ -s $list_scripts ]]; then
|
||||||
cp -f $list_scripts $list_add
|
cp -f $list_scripts $list_add
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ ! -s $list_scripts ]] && [[ -s $list_task ]]; then
|
if [[ ! -s $list_scripts ]] && [[ -s $list_task ]]; then
|
||||||
cp -f $list_task $list_drop
|
cp -f $list_task $list_drop
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
## 检测配置文件版本
|
## 检测配置文件版本
|
||||||
detect_config_version() {
|
detect_config_version() {
|
||||||
## 识别出两个文件的版本号
|
## 识别出两个文件的版本号
|
||||||
ver_config_sample=$(grep " Version: " $file_config_sample | perl -pe "s|.+v((\d+\.?){3})|\1|")
|
ver_config_sample=$(grep " Version: " $file_config_sample | perl -pe "s|.+v((\d+\.?){3})|\1|")
|
||||||
[[ -f $file_config_user ]] && ver_config_user=$(grep " Version: " $file_config_user | perl -pe "s|.+v((\d+\.?){3})|\1|")
|
[[ -f $file_config_user ]] && ver_config_user=$(grep " Version: " $file_config_user | perl -pe "s|.+v((\d+\.?){3})|\1|")
|
||||||
|
|
||||||
## 删除旧的发送记录文件
|
## 删除旧的发送记录文件
|
||||||
[[ -f $send_mark ]] && [[ $(cat $send_mark) != $ver_config_sample ]] && rm -f $send_mark
|
[[ -f $send_mark ]] && [[ $(cat $send_mark) != $ver_config_sample ]] && rm -f $send_mark
|
||||||
|
|
||||||
## 识别出更新日期和更新内容
|
## 识别出更新日期和更新内容
|
||||||
update_date=$(grep " Date: " $file_config_sample | awk -F ": " '{print $2}')
|
update_date=$(grep " Date: " $file_config_sample | awk -F ": " '{print $2}')
|
||||||
update_content=$(grep " Update Content: " $file_config_sample | awk -F ": " '{print $2}')
|
update_content=$(grep " Update Content: " $file_config_sample | awk -F ": " '{print $2}')
|
||||||
|
|
||||||
## 如果是今天,并且版本号不一致,则发送通知
|
## 如果是今天,并且版本号不一致,则发送通知
|
||||||
if [[ -f $file_config_user ]] && [[ $ver_config_user != $ver_config_sample ]] && [[ $update_date == $(date "+%Y-%m-%d") ]]; then
|
if [[ -f $file_config_user ]] && [[ $ver_config_user != $ver_config_sample ]] && [[ $update_date == $(date "+%Y-%m-%d") ]]; then
|
||||||
if [[ ! -f $send_mark ]]; then
|
if [[ ! -f $send_mark ]]; then
|
||||||
local notify_title="配置文件更新通知"
|
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"
|
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
|
echo -e $notify_content
|
||||||
notify_api "$notify_title" "$notify_content"
|
notify_api "$notify_title" "$notify_content"
|
||||||
[[ $? -eq 0 ]] && echo $ver_config_sample >$send_mark
|
[[ $? -eq 0 ]] && echo $ver_config_sample >$send_mark
|
||||||
fi
|
|
||||||
else
|
|
||||||
[[ -f $send_mark ]] && rm -f $send_mark
|
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
[[ -f $send_mark ]] && rm -f $send_mark
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
## 输出是否有新的或失效的定时任务,$1:新的或失效的任务清单文件路径,$2:新/失效
|
## 输出是否有新的或失效的定时任务,$1:新的或失效的任务清单文件路径,$2:新/失效
|
||||||
output_list_add_drop() {
|
output_list_add_drop() {
|
||||||
local list=$1
|
local list=$1
|
||||||
local type=$2
|
local type=$2
|
||||||
if [[ -s $list ]]; then
|
if [[ -s $list ]]; then
|
||||||
echo -e "检测到有$type的定时任务:\n"
|
echo -e "检测到有$type的定时任务:\n"
|
||||||
cat $list
|
cat $list
|
||||||
echo
|
echo
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
## 自动删除失效的脚本与定时任务,需要:1.AutoDelCron 设置为 true;2.正常更新js脚本,没有报错;3.存在失效任务
|
## 自动删除失效的脚本与定时任务,需要:1.AutoDelCron 设置为 true;2.正常更新js脚本,没有报错;3.存在失效任务
|
||||||
## $1:失效任务清单文件路径
|
## $1:失效任务清单文件路径
|
||||||
del_cron() {
|
del_cron() {
|
||||||
local list_drop=$1
|
local list_drop=$1
|
||||||
local path=$2
|
local path=$2
|
||||||
local detail=""
|
local detail=""
|
||||||
local ids=""
|
local ids=""
|
||||||
echo -e "开始尝试自动删除失效的定时任务...\n"
|
echo -e "开始尝试自动删除失效的定时任务...\n"
|
||||||
for cron in $(cat $list_drop); do
|
for cron in $(cat $list_drop); do
|
||||||
local id=$(cat $list_crontab_user | grep -E "$cmd_task $cron" | perl -pe "s|.*ID=(.*) $cmd_task $cron\.*|\1|" | head -1 | head -1 | awk -F " " '{print $1}')
|
local id=$(cat $list_crontab_user | grep -E "$cmd_task $cron" | perl -pe "s|.*ID=(.*) $cmd_task $cron\.*|\1|" | head -1 | head -1 | awk -F " " '{print $1}')
|
||||||
if [[ $ids ]]; then
|
|
||||||
ids="$ids,\"$id\""
|
|
||||||
else
|
|
||||||
ids="\"$id\""
|
|
||||||
fi
|
|
||||||
cron_file="$dir_scripts/${cron}"
|
|
||||||
if [[ -f $cron_file ]]; then
|
|
||||||
cron_name=$(grep "new Env" $cron_file | awk -F "\(" '{print $2}' | awk -F "\)" '{print $1}' | sed 's:^.\(.*\).$:\1:' | head -1)
|
|
||||||
rm -f $cron_file
|
|
||||||
fi
|
|
||||||
[[ -z $cron_name ]] && cron_name="$cron"
|
|
||||||
if [[ $detail ]]; then
|
|
||||||
detail="${detail}\n${cron_name}"
|
|
||||||
else
|
|
||||||
detail="${cron_name}"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
if [[ $ids ]]; then
|
if [[ $ids ]]; then
|
||||||
result=$(del_cron_api "$ids")
|
ids="$ids,\"$id\""
|
||||||
notify_api "$path 删除任务${result}" "$detail"
|
else
|
||||||
|
ids="\"$id\""
|
||||||
fi
|
fi
|
||||||
|
cron_file="$dir_scripts/${cron}"
|
||||||
|
if [[ -f $cron_file ]]; then
|
||||||
|
cron_name=$(grep "new Env" $cron_file | awk -F "\(" '{print $2}' | awk -F "\)" '{print $1}' | sed 's:^.\(.*\).$:\1:' | head -1)
|
||||||
|
rm -f $cron_file
|
||||||
|
fi
|
||||||
|
[[ -z $cron_name ]] && cron_name="$cron"
|
||||||
|
if [[ $detail ]]; then
|
||||||
|
detail="${detail}\n${cron_name}"
|
||||||
|
else
|
||||||
|
detail="${cron_name}"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
if [[ $ids ]]; then
|
||||||
|
result=$(del_cron_api "$ids")
|
||||||
|
notify_api "$path 删除任务${result}" "$detail"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
## 自动增加定时任务,需要:1.AutoAddCron 设置为 true;2.正常更新js脚本,没有报错;3.存在新任务;4.crontab.list存在并且不为空
|
## 自动增加定时任务,需要:1.AutoAddCron 设置为 true;2.正常更新js脚本,没有报错;3.存在新任务;4.crontab.list存在并且不为空
|
||||||
## $1:新任务清单文件路径
|
## $1:新任务清单文件路径
|
||||||
add_cron() {
|
add_cron() {
|
||||||
local list_add=$1
|
local list_add=$1
|
||||||
local path=$2
|
local path=$2
|
||||||
echo -e "开始尝试自动添加定时任务...\n"
|
echo -e "开始尝试自动添加定时任务...\n"
|
||||||
local detail=""
|
local detail=""
|
||||||
cd $dir_scripts
|
cd $dir_scripts
|
||||||
for file in $(cat $list_add); do
|
for file in $(cat $list_add); do
|
||||||
local file_name=${file/${path}\//}
|
local file_name=${file/${path}\//}
|
||||||
file_name=${file_name/${path}\_/}
|
file_name=${file_name/${path}\_/}
|
||||||
if [[ -f $file ]]; then
|
if [[ -f $file ]]; then
|
||||||
cron_line=$(
|
cron_line=$(
|
||||||
perl -ne "{
|
perl -ne "{
|
||||||
print if /.*([\d\*]*[\*-\/,\d]*[\d\*] ){4,5}[\d\*]*[\*-\/,\d]*[\d\*]( |,|\").*$file_name/
|
print if /.*([\d\*]*[\*-\/,\d]*[\d\*] ){4,5}[\d\*]*[\*-\/,\d]*[\d\*]( |,|\").*$file_name/
|
||||||
}" $file |
|
}" $file |
|
||||||
perl -pe "{
|
perl -pe "{
|
||||||
s|[^\d\*]*(([\d\*]*[\*-\/,\d]*[\d\*] ){4,5}[\d\*]*[\*-\/,\d]*[\d\*])( \|,\|\").*/?$file_name.*|\1|g;
|
s|[^\d\*]*(([\d\*]*[\*-\/,\d]*[\d\*] ){4,5}[\d\*]*[\*-\/,\d]*[\d\*])( \|,\|\").*/?$file_name.*|\1|g;
|
||||||
s|\*([\d\*])(.*)|\1\2|g;
|
s|\*([\d\*])(.*)|\1\2|g;
|
||||||
s| | |g;
|
s| | |g;
|
||||||
}" | sort -u | head -1
|
}" | sort -u | head -1
|
||||||
)
|
)
|
||||||
cron_name=$(grep "new Env" $file | awk -F "\(" '{print $2}' | awk -F "\)" '{print $1}' | sed 's:^.\(.*\).$:\1:' | head -1)
|
cron_name=$(grep "new Env" $file | awk -F "\(" '{print $2}' | awk -F "\)" '{print $1}' | sed 's:^.\(.*\).$:\1:' | head -1)
|
||||||
[[ -z $cron_name ]] && cron_name="$file_name"
|
[[ -z $cron_name ]] && cron_name="$file_name"
|
||||||
[[ -z $cron_line ]] && cron_line=$(grep "cron:" $file | awk -F ":" '{print $2}' | head -1 | xargs)
|
[[ -z $cron_line ]] && cron_line=$(grep "cron:" $file | awk -F ":" '{print $2}' | head -1 | xargs)
|
||||||
[[ -z $cron_line ]] && cron_line=$(grep "cron " $file | awk -F "cron \"" '{print $2}' | awk -F "\" " '{print $1}' | head -1 | xargs)
|
[[ -z $cron_line ]] && cron_line=$(grep "cron " $file | awk -F "cron \"" '{print $2}' | awk -F "\" " '{print $1}' | head -1 | xargs)
|
||||||
[[ -z $cron_line ]] && cron_line="$default_cron"
|
[[ -z $cron_line ]] && cron_line="$default_cron"
|
||||||
result=$(add_cron_api "$cron_line:$cmd_task $file:$cron_name")
|
result=$(add_cron_api "$cron_line:$cmd_task $file:$cron_name")
|
||||||
echo -e "$result"
|
echo -e "$result"
|
||||||
if [[ $detail ]]; then
|
if [[ $detail ]]; then
|
||||||
detail="${detail}${result}\n"
|
detail="${detail}${result}\n"
|
||||||
else
|
else
|
||||||
detail="${result}\n"
|
detail="${result}\n"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
notify_api "$path 新增任务" "$detail"
|
notify_api "$path 新增任务" "$detail"
|
||||||
}
|
}
|
||||||
|
|
||||||
## 更新仓库
|
## 更新仓库
|
||||||
update_repo() {
|
update_repo() {
|
||||||
local url="$1"
|
local url="$1"
|
||||||
local path="$2"
|
local path="$2"
|
||||||
local blackword="$3"
|
local blackword="$3"
|
||||||
local dependence="$4"
|
local dependence="$4"
|
||||||
local branch="$5"
|
local branch="$5"
|
||||||
local extensions="$6"
|
local extensions="$6"
|
||||||
local tmp="${url%/*}"
|
local tmp="${url%/*}"
|
||||||
local authorTmp1="${tmp##*/}"
|
local authorTmp1="${tmp##*/}"
|
||||||
local authorTmp2="${authorTmp1##*:}"
|
local authorTmp2="${authorTmp1##*:}"
|
||||||
local author="${authorTmp2##*.}"
|
local author="${authorTmp2##*.}"
|
||||||
|
|
||||||
local repo_path="${dir_repo}/${uniq_path}"
|
local repo_path="${dir_repo}/${uniq_path}"
|
||||||
|
|
||||||
make_dir "${dir_scripts}/${uniq_path}"
|
make_dir "${dir_scripts}/${uniq_path}"
|
||||||
|
|
||||||
local formatUrl="$url"
|
local formatUrl="$url"
|
||||||
if [[ -d ${repo_path}/.git ]]; then
|
if [[ -d ${repo_path}/.git ]]; then
|
||||||
reset_romote_url ${repo_path} "${formatUrl}" "${branch}"
|
reset_romote_url ${repo_path} "${formatUrl}" "${branch}"
|
||||||
git_pull_scripts ${repo_path} "${branch}"
|
git_pull_scripts ${repo_path} "${branch}"
|
||||||
else
|
else
|
||||||
git_clone_scripts "${formatUrl}" ${repo_path} "${branch}"
|
git_clone_scripts "${formatUrl}" ${repo_path} "${branch}"
|
||||||
fi
|
fi
|
||||||
if [[ $exit_status -eq 0 ]]; then
|
if [[ $exit_status -eq 0 ]]; then
|
||||||
echo -e "\n更新${repo_path}成功...\n"
|
echo -e "\n更新${repo_path}成功...\n"
|
||||||
diff_scripts "$repo_path" "$author" "$path" "$blackword" "$dependence" "$extensions"
|
diff_scripts "$repo_path" "$author" "$path" "$blackword" "$dependence" "$extensions"
|
||||||
else
|
else
|
||||||
echo -e "\n更新${repo_path}失败,请检查网络...\n"
|
echo -e "\n更新${repo_path}失败,请检查网络...\n"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
## 更新所有 raw 文件
|
## 更新所有 raw 文件
|
||||||
update_raw() {
|
update_raw() {
|
||||||
echo -e "--------------------------------------------------------------\n"
|
echo -e "--------------------------------------------------------------\n"
|
||||||
local url="$1"
|
local url="$1"
|
||||||
local raw_url="$url"
|
local raw_url="$url"
|
||||||
local suffix="${raw_url##*.}"
|
local suffix="${raw_url##*.}"
|
||||||
local raw_file_name="${uniq_path}.${suffix}"
|
local raw_file_name="${uniq_path}.${suffix}"
|
||||||
echo -e "开始下载:${raw_url} \n\n保存路径:$dir_raw/${raw_file_name}\n"
|
echo -e "开始下载:${raw_url} \n\n保存路径:$dir_raw/${raw_file_name}\n"
|
||||||
|
|
||||||
set_proxy
|
set_proxy
|
||||||
wget -q --no-check-certificate -O "$dir_raw/${raw_file_name}.new" ${raw_url}
|
wget -q --no-check-certificate -O "$dir_raw/${raw_file_name}.new" ${raw_url}
|
||||||
unset_proxy
|
unset_proxy
|
||||||
|
|
||||||
if [[ $? -eq 0 ]]; then
|
if [[ $? -eq 0 ]]; then
|
||||||
mv "$dir_raw/${raw_file_name}.new" "$dir_raw/${raw_file_name}"
|
mv "$dir_raw/${raw_file_name}.new" "$dir_raw/${raw_file_name}"
|
||||||
echo -e "下载 ${raw_file_name} 成功...\n"
|
echo -e "下载 ${raw_file_name} 成功...\n"
|
||||||
cd $dir_raw
|
cd $dir_raw
|
||||||
local filename="raw_${raw_file_name}"
|
local filename="raw_${raw_file_name}"
|
||||||
local cron_id=$(cat $list_crontab_user | grep -E "$cmd_task $filename" | perl -pe "s|.*ID=(.*) $cmd_task $filename\.*|\1|" | head -1 | head -1 | awk -F " " '{print $1}')
|
local cron_id=$(cat $list_crontab_user | grep -E "$cmd_task $filename" | perl -pe "s|.*ID=(.*) $cmd_task $filename\.*|\1|" | head -1 | head -1 | awk -F " " '{print $1}')
|
||||||
cp -f $raw_file_name $dir_scripts/${filename}
|
cp -f $raw_file_name $dir_scripts/${filename}
|
||||||
cron_line=$(
|
cron_line=$(
|
||||||
perl -ne "{
|
perl -ne "{
|
||||||
print if /.*([\d\*]*[\*-\/,\d]*[\d\*] ){4,5}[\d\*]*[\*-\/,\d]*[\d\*]( |,|\").*$raw_file_name/
|
print if /.*([\d\*]*[\*-\/,\d]*[\d\*] ){4,5}[\d\*]*[\*-\/,\d]*[\d\*]( |,|\").*$raw_file_name/
|
||||||
}" $raw_file_name |
|
}" $raw_file_name |
|
||||||
perl -pe "{
|
perl -pe "{
|
||||||
s|[^\d\*]*(([\d\*]*[\*-\/,\d]*[\d\*] ){4,5}[\d\*]*[\*-\/,\d]*[\d\*])( \|,\|\").*/?$raw_file_name.*|\1|g;
|
s|[^\d\*]*(([\d\*]*[\*-\/,\d]*[\d\*] ){4,5}[\d\*]*[\*-\/,\d]*[\d\*])( \|,\|\").*/?$raw_file_name.*|\1|g;
|
||||||
s|\*([\d\*])(.*)|\1\2|g;
|
s|\*([\d\*])(.*)|\1\2|g;
|
||||||
s| | |g;
|
s| | |g;
|
||||||
}" | sort -u | head -1
|
}" | sort -u | head -1
|
||||||
)
|
)
|
||||||
cron_name=$(grep "new Env" $raw_file_name | awk -F "\(" '{print $2}' | awk -F "\)" '{print $1}' | sed 's:^.\(.*\).$:\1:' | head -1)
|
cron_name=$(grep "new Env" $raw_file_name | awk -F "\(" '{print $2}' | awk -F "\)" '{print $1}' | sed 's:^.\(.*\).$:\1:' | head -1)
|
||||||
[[ -z $cron_name ]] && cron_name="$raw_file_name"
|
[[ -z $cron_name ]] && cron_name="$raw_file_name"
|
||||||
[[ -z $cron_line ]] && cron_line=$(grep "cron:" $raw_file_name | awk -F ":" '{print $2}' | head -1 | xargs)
|
[[ -z $cron_line ]] && cron_line=$(grep "cron:" $raw_file_name | awk -F ":" '{print $2}' | head -1 | xargs)
|
||||||
[[ -z $cron_line ]] && cron_line=$(grep "cron " $raw_file_name | awk -F "cron \"" '{print $2}' | awk -F "\" " '{print $1}' | head -1 | xargs)
|
[[ -z $cron_line ]] && cron_line=$(grep "cron " $raw_file_name | awk -F "cron \"" '{print $2}' | awk -F "\" " '{print $1}' | head -1 | xargs)
|
||||||
[[ -z $cron_line ]] && cron_line="$default_cron"
|
[[ -z $cron_line ]] && cron_line="$default_cron"
|
||||||
if [[ -z $cron_id ]]; then
|
if [[ -z $cron_id ]]; then
|
||||||
result=$(add_cron_api "$cron_line:$cmd_task $filename:$cron_name")
|
result=$(add_cron_api "$cron_line:$cmd_task $filename:$cron_name")
|
||||||
echo -e "$result\n"
|
echo -e "$result\n"
|
||||||
notify_api "新增任务通知" "\n$result"
|
notify_api "新增任务通知" "\n$result"
|
||||||
# update_cron_api "$cron_line:$cmd_task $filename:$cron_name:$cron_id"
|
# update_cron_api "$cron_line:$cmd_task $filename:$cron_name:$cron_id"
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo -e "下载 ${raw_file_name} 失败,保留之前正常下载的版本...\n"
|
|
||||||
[[ -f "$dir_raw/${raw_file_name}.new" ]] && rm -f "$dir_raw/${raw_file_name}.new"
|
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
echo -e "下载 ${raw_file_name} 失败,保留之前正常下载的版本...\n"
|
||||||
|
[[ -f "$dir_raw/${raw_file_name}.new" ]] && rm -f "$dir_raw/${raw_file_name}.new"
|
||||||
|
fi
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
## 调用用户自定义的extra.sh
|
## 调用用户自定义的extra.sh
|
||||||
run_extra_shell() {
|
run_extra_shell() {
|
||||||
if [[ ${EnableExtraShell} == true ]]; then
|
if [[ ${EnableExtraShell} == true ]]; then
|
||||||
if [[ -f $file_extra_shell ]]; then
|
if [[ -f $file_extra_shell ]]; then
|
||||||
echo -e "--------------------------------------------------------------\n"
|
echo -e "--------------------------------------------------------------\n"
|
||||||
. $file_extra_shell
|
. $file_extra_shell
|
||||||
else
|
else
|
||||||
echo -e "$file_extra_shell文件不存在,跳过执行...\n"
|
echo -e "$file_extra_shell文件不存在,跳过执行...\n"
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
## 脚本用法
|
## 脚本用法
|
||||||
usage() {
|
usage() {
|
||||||
echo -e "本脚本用法:"
|
echo -e "本脚本用法:"
|
||||||
echo -e "1. $cmd_update update # 更新并重启青龙"
|
echo -e "1. $cmd_update update # 更新并重启青龙"
|
||||||
echo -e "2. $cmd_update extra # 运行自定义脚本"
|
echo -e "2. $cmd_update extra # 运行自定义脚本"
|
||||||
echo -e "3. $cmd_update raw <fileurl> # 更新单个脚本文件"
|
echo -e "3. $cmd_update raw <fileurl> # 更新单个脚本文件"
|
||||||
echo -e "4. $cmd_update repo <repourl> <path> <blacklist> <dependence> <branch> <extensions> # 更新单个仓库的脚本"
|
echo -e "4. $cmd_update repo <repourl> <path> <blacklist> <dependence> <branch> <extensions> # 更新单个仓库的脚本"
|
||||||
echo -e "5. $cmd_update rmlog <days> # 删除旧日志"
|
echo -e "5. $cmd_update rmlog <days> # 删除旧日志"
|
||||||
echo -e "6. $cmd_update bot # 启动tg-bot"
|
echo -e "6. $cmd_update bot # 启动tg-bot"
|
||||||
echo -e "7. $cmd_update check # 检测青龙环境并修复"
|
echo -e "7. $cmd_update check # 检测青龙环境并修复"
|
||||||
echo -e "8. $cmd_update resetlet # 重置登录错误次数"
|
echo -e "8. $cmd_update resetlet # 重置登录错误次数"
|
||||||
echo -e "9. $cmd_update resettfa # 禁用两步登录"
|
echo -e "9. $cmd_update resettfa # 禁用两步登录"
|
||||||
}
|
}
|
||||||
|
|
||||||
## 更新qinglong
|
## 更新qinglong
|
||||||
update_qinglong() {
|
update_qinglong() {
|
||||||
patch_version
|
patch_version &>/dev/null
|
||||||
|
|
||||||
export isFirstStartServer=false
|
export isFirstStartServer=false
|
||||||
|
|
||||||
local no_restart="$1"
|
local all_branch=$(git branch -a)
|
||||||
local all_branch=$(git branch -a)
|
local primary_branch="master"
|
||||||
local primary_branch="master"
|
if [[ "${all_branch}" =~ "${current_branch}" ]]; then
|
||||||
if [[ "${all_branch}" =~ "${current_branch}" ]]; then
|
primary_branch="${current_branch}"
|
||||||
primary_branch="${current_branch}"
|
fi
|
||||||
fi
|
[[ -f $dir_root/package.json ]] && ql_depend_old=$(cat $dir_root/package.json)
|
||||||
[[ -f $dir_root/package.json ]] && ql_depend_old=$(cat $dir_root/package.json)
|
reset_romote_url ${dir_root} "https://github.com/whyour/qinglong.git" ${primary_branch}
|
||||||
reset_romote_url ${dir_root} "https://github.com/whyour/qinglong.git" ${primary_branch}
|
git_pull_scripts $dir_root ${primary_branch}
|
||||||
git_pull_scripts $dir_root ${primary_branch}
|
|
||||||
|
|
||||||
if [[ $exit_status -eq 0 ]]; then
|
if [[ $exit_status -eq 0 ]]; then
|
||||||
echo -e "\n更新青龙源文件成功...\n"
|
echo -e "\n更新青龙源文件成功...\n"
|
||||||
cp -f $file_config_sample $dir_config/config.sample.sh
|
cp -f $file_config_sample $dir_config/config.sample.sh
|
||||||
detect_config_version
|
detect_config_version
|
||||||
update_depend
|
update_depend
|
||||||
|
|
||||||
[[ -f $dir_root/package.json ]] && ql_depend_new=$(cat $dir_root/package.json)
|
[[ -f $dir_root/package.json ]] && ql_depend_new=$(cat $dir_root/package.json)
|
||||||
[[ "$ql_depend_old" != "$ql_depend_new" ]] && npm_install_2 $dir_root
|
[[ "$ql_depend_old" != "$ql_depend_new" ]] && npm_install_2 $dir_root
|
||||||
else
|
|
||||||
echo -e "\n更新青龙源文件失败,请检查原因...\n"
|
|
||||||
fi
|
|
||||||
|
|
||||||
local url="https://github.com/whyour/qinglong-static.git"
|
|
||||||
if [[ -d ${ql_static_repo}/.git ]]; then
|
|
||||||
reset_romote_url ${ql_static_repo} ${url} ${primary_branch}
|
|
||||||
git_pull_scripts ${ql_static_repo} ${primary_branch}
|
|
||||||
else
|
|
||||||
git_clone_scripts ${url} ${ql_static_repo} ${primary_branch}
|
|
||||||
fi
|
|
||||||
if [[ $exit_status -eq 0 ]]; then
|
|
||||||
echo -e "\n更新青龙静态资源成功...\n"
|
|
||||||
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/*
|
|
||||||
cp -rf $ql_static_repo/* $dir_static
|
|
||||||
if [[ $no_restart != "no-restart" ]]; then
|
|
||||||
nginx -s reload 2>/dev/null || nginx -c /etc/nginx/nginx.conf
|
|
||||||
echo -e "重启面板中..."
|
|
||||||
sleep 3
|
|
||||||
reload_pm2
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo -e "\n更新青龙静态资源失败,请检查原因...\n"
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
update_qinglong_static "$1" "$primary_branch"
|
||||||
|
else
|
||||||
|
echo -e "\n更新青龙源文件失败,请检查网络...\n"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
patch_version() {
|
update_qinglong_static() {
|
||||||
# 兼容pnpm@7
|
local no_restart="$1"
|
||||||
pnpm setup &>/dev/null
|
local primary_branch="$2"
|
||||||
source ~/.bashrc
|
local url="https://github.com/whyour/qinglong-static.git"
|
||||||
pnpm install -g &>/dev/null
|
if [[ -d ${ql_static_repo}/.git ]]; then
|
||||||
|
reset_romote_url ${ql_static_repo} ${url} ${primary_branch}
|
||||||
|
git_pull_scripts ${ql_static_repo} ${primary_branch}
|
||||||
|
else
|
||||||
|
git_clone_scripts ${url} ${ql_static_repo} ${primary_branch}
|
||||||
|
fi
|
||||||
|
if [[ $exit_status -eq 0 ]]; then
|
||||||
|
echo -e "\n更新青龙静态资源成功...\n"
|
||||||
|
local static_version=$(cat $dir_root/src/version.ts | perl -pe "s|.*\'(.*)\';\.*|\1|" | head -1)
|
||||||
|
echo -e "\n当前版本 $static_version...\n"
|
||||||
|
|
||||||
if [[ -f "$dir_root/db/cookie.db" ]]; then
|
rm -rf $dir_static/*
|
||||||
echo -e "检测到旧的db文件,拷贝为新db...\n"
|
cp -rf $ql_static_repo/* $dir_static
|
||||||
mv $dir_root/db/cookie.db $dir_root/db/env.db
|
if [[ $no_restart != "no-restart" ]]; then
|
||||||
rm -rf $dir_root/db/cookie.db
|
nginx -s reload 2>/dev/null || nginx -c /etc/nginx/nginx.conf
|
||||||
echo
|
echo -e "重启面板中..."
|
||||||
|
sleep 3
|
||||||
|
reload_pm2
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
if ! type ts-node &>/dev/null; then
|
echo -e "\n更新青龙静态资源失败,请检查网络...\n"
|
||||||
pnpm add -g ts-node typescript tslib
|
fi
|
||||||
fi
|
|
||||||
|
|
||||||
git config --global pull.rebase false
|
|
||||||
|
|
||||||
cp -f $dir_root/.env.example $dir_root/.env
|
|
||||||
|
|
||||||
if [[ -d "$dir_root/db" ]]; then
|
|
||||||
echo -e "检测到旧的db目录,拷贝到data目录...\n"
|
|
||||||
cp -rf $dir_root/config $dir_root/data
|
|
||||||
echo
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -d "$dir_root/scripts" ]]; then
|
|
||||||
echo -e "检测到旧的scripts目录,拷贝到data目录...\n"
|
|
||||||
cp -rf $dir_root/scripts $dir_root/data
|
|
||||||
echo
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -d "$dir_root/log" ]]; then
|
|
||||||
echo -e "检测到旧的log目录,拷贝到data目录...\n"
|
|
||||||
cp -rf $dir_root/log $dir_root/data
|
|
||||||
echo
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -d "$dir_root/config" ]]; then
|
|
||||||
echo -e "检测到旧的config目录,拷贝到data目录...\n"
|
|
||||||
cp -rf $dir_root/config $dir_root/data
|
|
||||||
echo
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ $PipMirror ]]; then
|
|
||||||
pip3 config set global.index-url $PipMirror
|
|
||||||
fi
|
|
||||||
if [[ $NpmMirror ]]; then
|
|
||||||
npm config set registry $NpmMirror
|
|
||||||
fi
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
## 对比脚本
|
## 对比脚本
|
||||||
diff_scripts() {
|
diff_scripts() {
|
||||||
local dir_current=$(pwd)
|
local dir_current=$(pwd)
|
||||||
local repo_path="$1"
|
local repo_path="$1"
|
||||||
local author="$2"
|
local author="$2"
|
||||||
local path="$3"
|
local path="$3"
|
||||||
local blackword="$4"
|
local blackword="$4"
|
||||||
local dependence="$5"
|
local dependence="$5"
|
||||||
local extensions="$6"
|
local extensions="$6"
|
||||||
|
|
||||||
gen_list_repo "$repo_path" "$author" "$path" "$blackword" "$dependence" "$extensions"
|
gen_list_repo "$repo_path" "$author" "$path" "$blackword" "$dependence" "$extensions"
|
||||||
|
|
||||||
local list_add="$dir_list_tmp/${uniq_path}_add.list"
|
local list_add="$dir_list_tmp/${uniq_path}_add.list"
|
||||||
local list_drop="$dir_list_tmp/${uniq_path}_drop.list"
|
local list_drop="$dir_list_tmp/${uniq_path}_drop.list"
|
||||||
diff_cron "$dir_list_tmp/${uniq_path}_scripts.list" "$dir_list_tmp/${uniq_path}_user.list" $list_add $list_drop
|
diff_cron "$dir_list_tmp/${uniq_path}_scripts.list" "$dir_list_tmp/${uniq_path}_user.list" $list_add $list_drop
|
||||||
|
|
||||||
if [[ -s $list_drop ]]; then
|
if [[ -s $list_drop ]]; then
|
||||||
output_list_add_drop $list_drop "失效"
|
output_list_add_drop $list_drop "失效"
|
||||||
if [[ ${AutoDelCron} == true ]]; then
|
if [[ ${AutoDelCron} == true ]]; then
|
||||||
del_cron $list_drop $uniq_path
|
del_cron $list_drop $uniq_path
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
if [[ -s $list_add ]]; then
|
fi
|
||||||
output_list_add_drop $list_add "新"
|
if [[ -s $list_add ]]; then
|
||||||
if [[ ${AutoAddCron} == true ]]; then
|
output_list_add_drop $list_add "新"
|
||||||
add_cron $list_add $uniq_path
|
if [[ ${AutoAddCron} == true ]]; then
|
||||||
fi
|
add_cron $list_add $uniq_path
|
||||||
fi
|
fi
|
||||||
cd $dir_current
|
fi
|
||||||
|
cd $dir_current
|
||||||
}
|
}
|
||||||
|
|
||||||
## 生成脚本的路径清单文件
|
## 生成脚本的路径清单文件
|
||||||
gen_list_repo() {
|
gen_list_repo() {
|
||||||
local dir_current=$(pwd)
|
local dir_current=$(pwd)
|
||||||
local repo_path="$1"
|
local repo_path="$1"
|
||||||
local author="$2"
|
local author="$2"
|
||||||
local path="$3"
|
local path="$3"
|
||||||
local blackword="$4"
|
local blackword="$4"
|
||||||
local dependence="$5"
|
local dependence="$5"
|
||||||
|
|
||||||
rm -f $dir_list_tmp/${uniq_path}*.list &>/dev/null
|
rm -f $dir_list_tmp/${uniq_path}*.list &>/dev/null
|
||||||
|
|
||||||
|
cd ${repo_path}
|
||||||
|
|
||||||
|
local cmd="find ."
|
||||||
|
local index=0
|
||||||
|
if [[ $6 ]]; then
|
||||||
|
file_extensions="$6"
|
||||||
|
if [[ $file_extensions =~ "|" ]]; then
|
||||||
|
file_extensions=$(echo $file_extensions | sed 's/|/ /g')
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
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
|
||||||
|
if [[ $blackword ]]; then
|
||||||
|
files=$(echo "$files" | egrep -v $blackword)
|
||||||
|
fi
|
||||||
|
|
||||||
|
cp -f $file_notify_js "${dir_scripts}/${uniq_path}"
|
||||||
|
cp -f $file_notify_py "${dir_scripts}/${uniq_path}"
|
||||||
|
|
||||||
|
if [[ $dependence ]]; then
|
||||||
cd ${repo_path}
|
cd ${repo_path}
|
||||||
|
results=$(eval $cmd | sed 's/^..//' | egrep $dependence)
|
||||||
local cmd="find ."
|
for _file in ${results}; do
|
||||||
local index=0
|
file_path=$(dirname $_file)
|
||||||
if [[ $6 ]]; then
|
make_dir "${dir_scripts}/${uniq_path}/${file_path}"
|
||||||
file_extensions="$6"
|
cp -f $_file "${dir_scripts}/${uniq_path}/${file_path}"
|
||||||
if [[ $file_extensions =~ "|" ]]; then
|
|
||||||
file_extensions=$(echo $file_extensions | sed 's/|/ /g')
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
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
|
done
|
||||||
files=$(eval $cmd | sed 's/^..//')
|
fi
|
||||||
if [[ $path ]]; then
|
|
||||||
files=$(echo "$files" | egrep $path)
|
|
||||||
fi
|
|
||||||
if [[ $blackword ]]; then
|
|
||||||
files=$(echo "$files" | egrep -v $blackword)
|
|
||||||
fi
|
|
||||||
|
|
||||||
cp -f $file_notify_js "${dir_scripts}/${uniq_path}"
|
if [[ -d $dir_dep ]]; then
|
||||||
cp -f $file_notify_py "${dir_scripts}/${uniq_path}"
|
cp -rf $dir_dep/* "${dir_scripts}/${uniq_path}" &>/dev/null
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ $dependence ]]; then
|
for file in ${files}; do
|
||||||
cd ${repo_path}
|
filename=$(basename $file)
|
||||||
results=$(eval $cmd | sed 's/^..//' | egrep $dependence)
|
cp -f $file "$dir_scripts/${uniq_path}/${filename}"
|
||||||
for _file in ${results}; do
|
echo "${uniq_path}/${filename}" >>"$dir_list_tmp/${uniq_path}_scripts.list"
|
||||||
file_path=$(dirname $_file)
|
cron_id=$(cat $list_crontab_user | grep -E "$cmd_task ${uniq_path}_${filename}" | perl -pe "s|.*ID=(.*) $cmd_task ${uniq_path}_${filename}\.*|\1|" | head -1 | awk -F " " '{print $1}')
|
||||||
make_dir "${dir_scripts}/${uniq_path}/${file_path}"
|
if [[ $cron_id ]]; then
|
||||||
cp -f $_file "${dir_scripts}/${uniq_path}/${file_path}"
|
result=$(update_cron_command_api "$cmd_task ${uniq_path}/${filename}:$cron_id")
|
||||||
done
|
|
||||||
fi
|
fi
|
||||||
|
done
|
||||||
if [[ -d $dir_dep ]]; then
|
grep -E "${cmd_task} ${uniq_path}" ${list_crontab_user} | perl -pe "s|.*ID=(.*) ${cmd_task} (${uniq_path}.*)\.*|\2|" | awk -F " " '{print $1}' | sort -u >"$dir_list_tmp/${uniq_path}_user.list"
|
||||||
cp -rf $dir_dep/* "${dir_scripts}/${uniq_path}" &>/dev/null
|
cd $dir_current
|
||||||
fi
|
|
||||||
|
|
||||||
for file in ${files}; do
|
|
||||||
filename=$(basename $file)
|
|
||||||
cp -f $file "$dir_scripts/${uniq_path}/${filename}"
|
|
||||||
echo "${uniq_path}/${filename}" >>"$dir_list_tmp/${uniq_path}_scripts.list"
|
|
||||||
cron_id=$(cat $list_crontab_user | grep -E "$cmd_task ${uniq_path}_${filename}" | perl -pe "s|.*ID=(.*) $cmd_task ${uniq_path}_${filename}\.*|\1|" | head -1 | awk -F " " '{print $1}')
|
|
||||||
if [[ $cron_id ]]; then
|
|
||||||
result=$(update_cron_command_api "$cmd_task ${uniq_path}/${filename}:$cron_id")
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
grep -E "${cmd_task} ${uniq_path}" ${list_crontab_user} | perl -pe "s|.*ID=(.*) ${cmd_task} (${uniq_path}.*)\.*|\2|" | awk -F " " '{print $1}' | sort -u >"$dir_list_tmp/${uniq_path}_user.list"
|
|
||||||
cd $dir_current
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get_uniq_path() {
|
get_uniq_path() {
|
||||||
local url="$1"
|
local url="$1"
|
||||||
local branch="$2"
|
local branch="$2"
|
||||||
local urlTmp="${url%*/}"
|
local urlTmp="${url%*/}"
|
||||||
local repoTmp="${urlTmp##*/}"
|
local repoTmp="${urlTmp##*/}"
|
||||||
local repo="${repoTmp%.*}"
|
local repo="${repoTmp%.*}"
|
||||||
local tmp="${url%/*}"
|
local tmp="${url%/*}"
|
||||||
local authorTmp1="${tmp##*/}"
|
local authorTmp1="${tmp##*/}"
|
||||||
local authorTmp2="${authorTmp1##*:}"
|
local authorTmp2="${authorTmp1##*:}"
|
||||||
local author="${authorTmp2##*.}"
|
local author="${authorTmp2##*.}"
|
||||||
|
|
||||||
uniq_path="${author}_${repo}"
|
uniq_path="${author}_${repo}"
|
||||||
[[ $branch ]] && uniq_path="${uniq_path}_${branch}"
|
[[ $branch ]] && uniq_path="${uniq_path}_${branch}"
|
||||||
}
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
## for ql update
|
## for ql update
|
||||||
show_log="false"
|
show_log="false"
|
||||||
while getopts ":l" opt
|
while getopts ":l" opt; do
|
||||||
do
|
case $opt in
|
||||||
case $opt in
|
l)
|
||||||
l)
|
show_log="true"
|
||||||
show_log="true"
|
;;
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
[[ "$show_log" == "true" ]] && shift $(($OPTIND - 1))
|
|
||||||
|
|
||||||
local p1=$1
|
|
||||||
local p2=$2
|
|
||||||
local p3=$3
|
|
||||||
local p4=$4
|
|
||||||
local p5=$5
|
|
||||||
local p6=$6
|
|
||||||
local p7=$7
|
|
||||||
local log_time=$(date "+%Y-%m-%d-%H-%M-%S")
|
|
||||||
local log_path="$dir_log/update/${log_time}_$p1.log"
|
|
||||||
local begin_time=$(date '+%Y-%m-%d %H:%M:%S')
|
|
||||||
|
|
||||||
case $p1 in
|
|
||||||
update)
|
|
||||||
cmd=">> $log_path 2>&1"
|
|
||||||
[[ "$show_log" == "true" ]] && cmd=""
|
|
||||||
eval echo -e "## 开始执行... $begin_time\n" $cmd
|
|
||||||
[[ -f $task_error_log_path ]] && eval cat $task_error_log_path $cmd
|
|
||||||
eval update_qinglong "$2" $cmd
|
|
||||||
;;
|
|
||||||
extra)
|
|
||||||
echo -e "## 开始执行... $begin_time\n" >>$log_path
|
|
||||||
[[ -f $task_error_log_path ]] && cat $task_error_log_path >>$log_path
|
|
||||||
run_extra_shell >>$log_path
|
|
||||||
;;
|
|
||||||
repo)
|
|
||||||
get_uniq_path "$p2" "$p6"
|
|
||||||
if [[ -n $p2 ]]; then
|
|
||||||
update_repo "$p2" "$p3" "$p4" "$p5" "$p6" "$p7"
|
|
||||||
else
|
|
||||||
echo -e "命令输入错误...\n"
|
|
||||||
usage
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
raw)
|
|
||||||
get_uniq_path "$p2"
|
|
||||||
if [[ -n $p2 ]]; then
|
|
||||||
update_raw "$p2"
|
|
||||||
else
|
|
||||||
echo -e "命令输入错误...\n"
|
|
||||||
usage
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
rmlog)
|
|
||||||
echo -e "## 开始执行... $begin_time\n" >>$log_path
|
|
||||||
[[ -f $task_error_log_path ]] && cat $task_error_log_path >>$log_path
|
|
||||||
. $dir_shell/rmlog.sh "$p2" >>$log_path
|
|
||||||
;;
|
|
||||||
bot)
|
|
||||||
echo -e "## 开始执行... $begin_time\n" >>$log_path
|
|
||||||
[[ -f $task_error_log_path ]] && cat $task_error_log_path >>$log_path
|
|
||||||
. $dir_shell/bot.sh >>$log_path
|
|
||||||
;;
|
|
||||||
check)
|
|
||||||
echo -e "## 开始执行... $begin_time\n" >>$log_path
|
|
||||||
[[ -f $task_error_log_path ]] && cat $task_error_log_path >>$log_path
|
|
||||||
. $dir_shell/check.sh >>$log_path
|
|
||||||
;;
|
|
||||||
resetlet)
|
|
||||||
echo -e "## 开始执行... $begin_time\n" >>$log_path
|
|
||||||
auth_value=$(cat $file_auth_user | jq '.retries =0' -c)
|
|
||||||
echo -e "重置登录错误次数成功 \n $auth_value" >>$log_path
|
|
||||||
echo "$auth_value" >$file_auth_user
|
|
||||||
;;
|
|
||||||
resettfa)
|
|
||||||
echo -e "## 开始执行... $begin_time\n" >>$log_path
|
|
||||||
auth_value=$(cat $file_auth_user | jq '.twoFactorActivated =false' | jq '.twoFactorActived =false' -c)
|
|
||||||
echo -e "禁用两步验证成功 \n $auth_value" >>$log_path
|
|
||||||
echo "$auth_value" >$file_auth_user
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo -e "命令输入错误...\n"
|
|
||||||
usage
|
|
||||||
;;
|
|
||||||
esac
|
esac
|
||||||
local end_time=$(date '+%Y-%m-%d %H:%M:%S')
|
done
|
||||||
local diff_time=$(diff_time "%Y-%m-%d %H:%M:%S" "$begin_time" "$end_time")
|
[[ "$show_log" == "true" ]] && shift $(($OPTIND - 1))
|
||||||
if [[ $p1 != "repo" ]] && [[ $p1 != "raw" ]]; then
|
|
||||||
echo -e "\n## 执行结束... $end_time 耗时 $diff_time 秒" >>$log_path
|
local p1=$1
|
||||||
cat $log_path
|
local p2=$2
|
||||||
|
local p3=$3
|
||||||
|
local p4=$4
|
||||||
|
local p5=$5
|
||||||
|
local p6=$6
|
||||||
|
local p7=$7
|
||||||
|
local log_time=$(date "+%Y-%m-%d-%H-%M-%S")
|
||||||
|
local log_path="$dir_log/update/${log_time}_$p1.log"
|
||||||
|
local begin_time=$(date '+%Y-%m-%d %H:%M:%S')
|
||||||
|
|
||||||
|
case $p1 in
|
||||||
|
update)
|
||||||
|
cmd=">> $log_path 2>&1"
|
||||||
|
[[ "$show_log" == "true" ]] && cmd=""
|
||||||
|
eval echo -e "## 开始执行... $begin_time\n" $cmd
|
||||||
|
[[ -f $task_error_log_path ]] && eval cat $task_error_log_path $cmd
|
||||||
|
eval update_qinglong "$2" $cmd
|
||||||
|
;;
|
||||||
|
extra)
|
||||||
|
echo -e "## 开始执行... $begin_time\n" >>$log_path
|
||||||
|
[[ -f $task_error_log_path ]] && cat $task_error_log_path >>$log_path
|
||||||
|
run_extra_shell >>$log_path
|
||||||
|
;;
|
||||||
|
repo)
|
||||||
|
get_uniq_path "$p2" "$p6"
|
||||||
|
if [[ -n $p2 ]]; then
|
||||||
|
update_repo "$p2" "$p3" "$p4" "$p5" "$p6" "$p7"
|
||||||
|
else
|
||||||
|
echo -e "命令输入错误...\n"
|
||||||
|
usage
|
||||||
fi
|
fi
|
||||||
|
;;
|
||||||
|
raw)
|
||||||
|
get_uniq_path "$p2"
|
||||||
|
if [[ -n $p2 ]]; then
|
||||||
|
update_raw "$p2"
|
||||||
|
else
|
||||||
|
echo -e "命令输入错误...\n"
|
||||||
|
usage
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
rmlog)
|
||||||
|
echo -e "## 开始执行... $begin_time\n" >>$log_path
|
||||||
|
[[ -f $task_error_log_path ]] && cat $task_error_log_path >>$log_path
|
||||||
|
. $dir_shell/rmlog.sh "$p2" >>$log_path
|
||||||
|
;;
|
||||||
|
bot)
|
||||||
|
echo -e "## 开始执行... $begin_time\n" >>$log_path
|
||||||
|
[[ -f $task_error_log_path ]] && cat $task_error_log_path >>$log_path
|
||||||
|
. $dir_shell/bot.sh >>$log_path
|
||||||
|
;;
|
||||||
|
check)
|
||||||
|
echo -e "## 开始执行... $begin_time\n" >>$log_path
|
||||||
|
[[ -f $task_error_log_path ]] && cat $task_error_log_path >>$log_path
|
||||||
|
. $dir_shell/check.sh >>$log_path
|
||||||
|
;;
|
||||||
|
resetlet)
|
||||||
|
echo -e "## 开始执行... $begin_time\n" >>$log_path
|
||||||
|
auth_value=$(cat $file_auth_user | jq '.retries =0' -c)
|
||||||
|
echo -e "重置登录错误次数成功 \n $auth_value" >>$log_path
|
||||||
|
echo "$auth_value" >$file_auth_user
|
||||||
|
;;
|
||||||
|
resettfa)
|
||||||
|
echo -e "## 开始执行... $begin_time\n" >>$log_path
|
||||||
|
auth_value=$(cat $file_auth_user | jq '.twoFactorActivated =false' | jq '.twoFactorActived =false' -c)
|
||||||
|
echo -e "禁用两步验证成功 \n $auth_value" >>$log_path
|
||||||
|
echo "$auth_value" >$file_auth_user
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo -e "命令输入错误...\n"
|
||||||
|
usage
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
local end_time=$(date '+%Y-%m-%d %H:%M:%S')
|
||||||
|
local diff_time=$(diff_time "%Y-%m-%d %H:%M:%S" "$begin_time" "$end_time")
|
||||||
|
if [[ $p1 != "repo" ]] && [[ $p1 != "raw" ]]; then
|
||||||
|
echo -e "\n## 执行结束... $end_time 耗时 $diff_time 秒" >>$log_path
|
||||||
|
cat $log_path
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
main "$@"
|
main "$@"
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
import { useMemo, useState } from 'react';
|
||||||
|
|
||||||
|
export default (
|
||||||
|
treeData: any[],
|
||||||
|
searchValue: string,
|
||||||
|
{
|
||||||
|
treeNodeFilterProp,
|
||||||
|
}: {
|
||||||
|
treeNodeFilterProp: string;
|
||||||
|
},
|
||||||
|
) => {
|
||||||
|
return useMemo(() => {
|
||||||
|
const keys: string[] = [];
|
||||||
|
|
||||||
|
if (!searchValue) {
|
||||||
|
return { treeData, keys };
|
||||||
|
}
|
||||||
|
|
||||||
|
const upperStr = searchValue.toUpperCase();
|
||||||
|
function filterOptionFunc(_: string, dataNode: any[]) {
|
||||||
|
const value = dataNode[treeNodeFilterProp as any];
|
||||||
|
|
||||||
|
return String(value).toUpperCase().includes(upperStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
function dig(list: any[], keepAll: boolean = false): any[] {
|
||||||
|
return list
|
||||||
|
.map((dataNode) => {
|
||||||
|
const children = dataNode.children;
|
||||||
|
|
||||||
|
const match = keepAll || filterOptionFunc!(searchValue, dataNode);
|
||||||
|
const childList = dig(children || [], match);
|
||||||
|
|
||||||
|
if (match || childList.length) {
|
||||||
|
childList.length && keys.push(dataNode.key);
|
||||||
|
return {
|
||||||
|
...dataNode,
|
||||||
|
children: childList,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
})
|
||||||
|
.filter((node) => node);
|
||||||
|
}
|
||||||
|
|
||||||
|
return { treeData: dig(treeData), keys };
|
||||||
|
}, [treeData, searchValue, treeNodeFilterProp]);
|
||||||
|
};
|
||||||
@@ -68,18 +68,18 @@ export default {
|
|||||||
icon: <IconFont type="ql-icon-dependence" />,
|
icon: <IconFont type="ql-icon-dependence" />,
|
||||||
component: '@/pages/dependence/index',
|
component: '@/pages/dependence/index',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: '/log',
|
||||||
|
name: '日志管理',
|
||||||
|
icon: <IconFont type="ql-icon-log" />,
|
||||||
|
component: '@/pages/log/index',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: '/diff',
|
path: '/diff',
|
||||||
name: '对比工具',
|
name: '对比工具',
|
||||||
icon: <IconFont type="ql-icon-diff" />,
|
icon: <IconFont type="ql-icon-diff" />,
|
||||||
component: '@/pages/diff/index',
|
component: '@/pages/diff/index',
|
||||||
},
|
},
|
||||||
{
|
|
||||||
path: '/log',
|
|
||||||
name: '任务日志',
|
|
||||||
icon: <IconFont type="ql-icon-log" />,
|
|
||||||
component: '@/pages/log/index',
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
path: '/setting',
|
path: '/setting',
|
||||||
name: '系统设置',
|
name: '系统设置',
|
||||||
|
|||||||
+21
-24
@@ -161,7 +161,7 @@
|
|||||||
&.env-wrapper,
|
&.env-wrapper,
|
||||||
&.config-wrapper {
|
&.config-wrapper {
|
||||||
.CodeMirror {
|
.CodeMirror {
|
||||||
width: calc(100vw - 80px);
|
width: calc(100vw - 24px);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -243,31 +243,28 @@
|
|||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
}
|
}
|
||||||
|
|
||||||
[data-dark='true'] {
|
/* Change autocomplete styles in WebKit */
|
||||||
/* Change autocomplete styles in WebKit */
|
input:-webkit-autofill,
|
||||||
input:-webkit-autofill,
|
input:-webkit-autofill:hover,
|
||||||
input:-webkit-autofill:hover,
|
input:-webkit-autofill:focus,
|
||||||
input:-webkit-autofill:focus,
|
textarea:-webkit-autofill,
|
||||||
textarea:-webkit-autofill,
|
textarea:-webkit-autofill:hover,
|
||||||
textarea:-webkit-autofill:hover,
|
textarea:-webkit-autofill:focus,
|
||||||
textarea:-webkit-autofill:focus,
|
select:-webkit-autofill,
|
||||||
select:-webkit-autofill,
|
select:-webkit-autofill:hover,
|
||||||
select:-webkit-autofill:hover,
|
select:-webkit-autofill:focus {
|
||||||
select:-webkit-autofill:focus {
|
border: none;
|
||||||
border: 1px solid @border-color-base;
|
box-shadow: none;
|
||||||
box-shadow: none;
|
transition: background-color 5000s ease-in-out 0s;
|
||||||
transition: background-color 5000s ease-in-out 0s;
|
-webkit-text-fill-color: @text-color;
|
||||||
-webkit-text-fill-color: @text-color;
|
}
|
||||||
caret-color: #e8e6f3 !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
::placeholder {
|
::placeholder {
|
||||||
opacity: 0.5 !important;
|
opacity: 0.5 !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.ant-select-selection-placeholder {
|
.ant-select-selection-placeholder {
|
||||||
opacity: 0.5 !important;
|
opacity: 0.5 !important;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.ant-pro-basicLayout-content {
|
.ant-pro-basicLayout-content {
|
||||||
|
|||||||
+10
-6
@@ -20,6 +20,9 @@ import { message, Badge, Modal, Avatar, Dropdown, Menu, Image } from 'antd';
|
|||||||
import SockJS from 'sockjs-client';
|
import SockJS from 'sockjs-client';
|
||||||
import * as Sentry from '@sentry/react';
|
import * as Sentry from '@sentry/react';
|
||||||
import { init } from '../utils/init';
|
import { init } from '../utils/init';
|
||||||
|
import 'codemirror/mode/javascript/javascript';
|
||||||
|
import 'codemirror/mode/python/python';
|
||||||
|
import 'codemirror/mode/shell/shell';
|
||||||
|
|
||||||
export interface SharedContext {
|
export interface SharedContext {
|
||||||
headerStyle: React.CSSProperties;
|
headerStyle: React.CSSProperties;
|
||||||
@@ -41,6 +44,7 @@ export default function () {
|
|||||||
const ws = useRef<any>(null);
|
const ws = useRef<any>(null);
|
||||||
const [socketMessage, setSocketMessage] = useState<any>();
|
const [socketMessage, setSocketMessage] = useState<any>();
|
||||||
const [collapsed, setCollapsed] = useState(false);
|
const [collapsed, setCollapsed] = useState(false);
|
||||||
|
const [initLoading, setInitLoading] = useState<boolean>(true);
|
||||||
const {
|
const {
|
||||||
enable: enableDarkMode,
|
enable: enableDarkMode,
|
||||||
disable: disableDarkMode,
|
disable: disableDarkMode,
|
||||||
@@ -64,17 +68,15 @@ export default function () {
|
|||||||
setSystemInfo(data);
|
setSystemInfo(data);
|
||||||
if (!data.isInitialized) {
|
if (!data.isInitialized) {
|
||||||
history.push('/initialization');
|
history.push('/initialization');
|
||||||
setLoading(false);
|
|
||||||
} else {
|
} else {
|
||||||
getUser();
|
getUser();
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
message.error(data);
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
});
|
})
|
||||||
|
.finally(() => setInitLoading(false));
|
||||||
};
|
};
|
||||||
|
|
||||||
const getUser = (needLoading = true) => {
|
const getUser = (needLoading = true) => {
|
||||||
@@ -87,8 +89,6 @@ export default function () {
|
|||||||
if (location.pathname === '/') {
|
if (location.pathname === '/') {
|
||||||
history.push('/crontab');
|
history.push('/crontab');
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
message.error(data);
|
|
||||||
}
|
}
|
||||||
needLoading && setLoading(false);
|
needLoading && setLoading(false);
|
||||||
})
|
})
|
||||||
@@ -196,6 +196,10 @@ export default function () {
|
|||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
if (initLoading) {
|
||||||
|
return <PageLoading />;
|
||||||
|
}
|
||||||
|
|
||||||
if (['/login', '/initialization', '/error'].includes(location.pathname)) {
|
if (['/login', '/initialization', '/error'].includes(location.pathname)) {
|
||||||
document.title = `${
|
document.title = `${
|
||||||
(config.documentTitleMap as any)[location.pathname]
|
(config.documentTitleMap as any)[location.pathname]
|
||||||
|
|||||||
@@ -25,8 +25,10 @@ const Config = () => {
|
|||||||
const [confirmLoading, setConfirmLoading] = useState(false);
|
const [confirmLoading, setConfirmLoading] = useState(false);
|
||||||
|
|
||||||
const getConfig = (name: string) => {
|
const getConfig = (name: string) => {
|
||||||
request.get(`${config.apiPrefix}configs/${name}`).then((data: any) => {
|
request.get(`${config.apiPrefix}configs/${name}`).then(({ code, data }) => {
|
||||||
setValue(data.data);
|
if (code === 200) {
|
||||||
|
setValue(data);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -34,8 +36,10 @@ const Config = () => {
|
|||||||
setLoading(true);
|
setLoading(true);
|
||||||
request
|
request
|
||||||
.get(`${config.apiPrefix}configs/files`)
|
.get(`${config.apiPrefix}configs/files`)
|
||||||
.then((data: any) => {
|
.then(({ code, data }) => {
|
||||||
setData(data.data);
|
if (code === 200) {
|
||||||
|
setData(data);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.finally(() => setLoading(false));
|
.finally(() => setLoading(false));
|
||||||
};
|
};
|
||||||
@@ -50,8 +54,10 @@ const Config = () => {
|
|||||||
.post(`${config.apiPrefix}configs/save`, {
|
.post(`${config.apiPrefix}configs/save`, {
|
||||||
data: { content, name: select },
|
data: { content, name: select },
|
||||||
})
|
})
|
||||||
.then((data: any) => {
|
.then(({ code, data }) => {
|
||||||
message.success(data.message);
|
if (code === 200) {
|
||||||
|
message.success('保存成功');
|
||||||
|
}
|
||||||
setConfirmLoading(false);
|
setConfirmLoading(false);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -103,7 +103,6 @@ const CronDetailModal = ({
|
|||||||
fontSize: 12,
|
fontSize: 12,
|
||||||
lineNumbersMinChars: 3,
|
lineNumbersMinChars: 3,
|
||||||
fontFamily: 'Source Code Pro',
|
fontFamily: 'Source Code Pro',
|
||||||
folding: false,
|
|
||||||
glyphMargin: false,
|
glyphMargin: false,
|
||||||
wordWrap: 'on',
|
wordWrap: 'on',
|
||||||
}}
|
}}
|
||||||
@@ -123,9 +122,11 @@ const CronDetailModal = ({
|
|||||||
.get(
|
.get(
|
||||||
`${config.apiPrefix}logs/${item.filename}?path=${item.directory || ''}`,
|
`${config.apiPrefix}logs/${item.filename}?path=${item.directory || ''}`,
|
||||||
)
|
)
|
||||||
.then((data) => {
|
.then(({ code, data }) => {
|
||||||
setLog(data.data);
|
if (code === 200) {
|
||||||
setIsLogModalVisible(true);
|
setLog(data);
|
||||||
|
setIsLogModalVisible(true);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -137,9 +138,9 @@ const CronDetailModal = ({
|
|||||||
setLoading(true);
|
setLoading(true);
|
||||||
request
|
request
|
||||||
.get(`${config.apiPrefix}crons/${cron.id}/logs`)
|
.get(`${config.apiPrefix}crons/${cron.id}/logs`)
|
||||||
.then((data: any) => {
|
.then(({ code, data }) => {
|
||||||
if (data.code === 200) {
|
if (code === 200) {
|
||||||
setLogs(data.data);
|
setLogs(data);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.finally(() => setLoading(false));
|
.finally(() => setLoading(false));
|
||||||
@@ -165,8 +166,10 @@ const CronDetailModal = ({
|
|||||||
setScriptInfo({ parent: p, filename: s });
|
setScriptInfo({ parent: p, filename: s });
|
||||||
request
|
request
|
||||||
.get(`${config.apiPrefix}scripts/${s}?path=${p || ''}`)
|
.get(`${config.apiPrefix}scripts/${s}?path=${p || ''}`)
|
||||||
.then((data) => {
|
.then(({ code, data }) => {
|
||||||
setValue(data.data);
|
if (code === 200) {
|
||||||
|
setValue(data);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
setValidTabs([validTabs[0]]);
|
setValidTabs([validTabs[0]]);
|
||||||
@@ -198,12 +201,10 @@ const CronDetailModal = ({
|
|||||||
content,
|
content,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then((_data: any) => {
|
.then(({ code, data }) => {
|
||||||
if (_data.code === 200) {
|
if (code === 200) {
|
||||||
setValue(content);
|
setValue(content);
|
||||||
message.success(`保存成功`);
|
message.success(`保存成功`);
|
||||||
} else {
|
|
||||||
message.error(_data);
|
|
||||||
}
|
}
|
||||||
resolve(null);
|
resolve(null);
|
||||||
})
|
})
|
||||||
@@ -231,14 +232,12 @@ const CronDetailModal = ({
|
|||||||
onOk() {
|
onOk() {
|
||||||
request
|
request
|
||||||
.put(`${config.apiPrefix}crons/run`, { data: [currentCron.id] })
|
.put(`${config.apiPrefix}crons/run`, { data: [currentCron.id] })
|
||||||
.then((data: any) => {
|
.then(({ code, data }) => {
|
||||||
if (data.code === 200) {
|
if (code === 200) {
|
||||||
setCurrentCron({ ...currentCron, status: CrontabStatus.running });
|
setCurrentCron({ ...currentCron, status: CrontabStatus.running });
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
getLogs();
|
getLogs();
|
||||||
}, 1000);
|
}, 1000);
|
||||||
} else {
|
|
||||||
message.error(data);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -263,11 +262,9 @@ const CronDetailModal = ({
|
|||||||
onOk() {
|
onOk() {
|
||||||
request
|
request
|
||||||
.put(`${config.apiPrefix}crons/stop`, { data: [currentCron.id] })
|
.put(`${config.apiPrefix}crons/stop`, { data: [currentCron.id] })
|
||||||
.then((data: any) => {
|
.then(({ code, data }) => {
|
||||||
if (data.code === 200) {
|
if (code === 200) {
|
||||||
setCurrentCron({ ...currentCron, status: CrontabStatus.idle });
|
setCurrentCron({ ...currentCron, status: CrontabStatus.idle });
|
||||||
} else {
|
|
||||||
message.error(data);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -300,14 +297,12 @@ const CronDetailModal = ({
|
|||||||
data: [currentCron.id],
|
data: [currentCron.id],
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.then((data: any) => {
|
.then(({ code, data }) => {
|
||||||
if (data.code === 200) {
|
if (code === 200) {
|
||||||
setCurrentCron({
|
setCurrentCron({
|
||||||
...currentCron,
|
...currentCron,
|
||||||
isDisabled: currentCron.isDisabled === 1 ? 0 : 1,
|
isDisabled: currentCron.isDisabled === 1 ? 0 : 1,
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
message.error(data);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -340,14 +335,12 @@ const CronDetailModal = ({
|
|||||||
data: [currentCron.id],
|
data: [currentCron.id],
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.then((data: any) => {
|
.then(({ code, data }) => {
|
||||||
if (data.code === 200) {
|
if (code === 200) {
|
||||||
setCurrentCron({
|
setCurrentCron({
|
||||||
...currentCron,
|
...currentCron,
|
||||||
isPinned: currentCron.isPinned === 1 ? 0 : 1,
|
isPinned: currentCron.isPinned === 1 ? 0 : 1,
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
message.error(data);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
+50
-58
@@ -433,20 +433,22 @@ const Crontab = () => {
|
|||||||
}
|
}
|
||||||
request
|
request
|
||||||
.get(url)
|
.get(url)
|
||||||
.then((_data: any) => {
|
.then(({ code, data: _data }) => {
|
||||||
const { data, total } = _data.data;
|
if (code === 200) {
|
||||||
setValue(
|
const { data, total } = _data;
|
||||||
data.map((x) => {
|
setValue(
|
||||||
return {
|
data.map((x) => {
|
||||||
...x,
|
return {
|
||||||
nextRunTime: cron_parser
|
...x,
|
||||||
.parseExpression(x.schedule)
|
nextRunTime: cron_parser
|
||||||
.next()
|
.parseExpression(x.schedule)
|
||||||
.toDate(),
|
.next()
|
||||||
};
|
.toDate(),
|
||||||
}),
|
};
|
||||||
);
|
}),
|
||||||
setTotal(total);
|
);
|
||||||
|
setTotal(total);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.finally(() => setLoading(false));
|
.finally(() => setLoading(false));
|
||||||
};
|
};
|
||||||
@@ -476,8 +478,8 @@ const Crontab = () => {
|
|||||||
onOk() {
|
onOk() {
|
||||||
request
|
request
|
||||||
.delete(`${config.apiPrefix}crons`, { data: [record.id] })
|
.delete(`${config.apiPrefix}crons`, { data: [record.id] })
|
||||||
.then((data: any) => {
|
.then(({ code, data }) => {
|
||||||
if (data.code === 200) {
|
if (code === 200) {
|
||||||
message.success('删除成功');
|
message.success('删除成功');
|
||||||
const result = [...value];
|
const result = [...value];
|
||||||
const i = result.findIndex((x) => x.id === record.id);
|
const i = result.findIndex((x) => x.id === record.id);
|
||||||
@@ -485,8 +487,6 @@ const Crontab = () => {
|
|||||||
result.splice(i, 1);
|
result.splice(i, 1);
|
||||||
setValue(result);
|
setValue(result);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
message.error(data);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -511,8 +511,8 @@ const Crontab = () => {
|
|||||||
onOk() {
|
onOk() {
|
||||||
request
|
request
|
||||||
.put(`${config.apiPrefix}crons/run`, { data: [record.id] })
|
.put(`${config.apiPrefix}crons/run`, { data: [record.id] })
|
||||||
.then((data: any) => {
|
.then(({ code, data }) => {
|
||||||
if (data.code === 200) {
|
if (code === 200) {
|
||||||
const result = [...value];
|
const result = [...value];
|
||||||
const i = result.findIndex((x) => x.id === record.id);
|
const i = result.findIndex((x) => x.id === record.id);
|
||||||
if (i !== -1) {
|
if (i !== -1) {
|
||||||
@@ -522,8 +522,6 @@ const Crontab = () => {
|
|||||||
});
|
});
|
||||||
setValue(result);
|
setValue(result);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
message.error(data);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -548,8 +546,8 @@ const Crontab = () => {
|
|||||||
onOk() {
|
onOk() {
|
||||||
request
|
request
|
||||||
.put(`${config.apiPrefix}crons/stop`, { data: [record.id] })
|
.put(`${config.apiPrefix}crons/stop`, { data: [record.id] })
|
||||||
.then((data: any) => {
|
.then(({ code, data }) => {
|
||||||
if (data.code === 200) {
|
if (code === 200) {
|
||||||
const result = [...value];
|
const result = [...value];
|
||||||
const i = result.findIndex((x) => x.id === record.id);
|
const i = result.findIndex((x) => x.id === record.id);
|
||||||
if (i !== -1) {
|
if (i !== -1) {
|
||||||
@@ -560,8 +558,6 @@ const Crontab = () => {
|
|||||||
});
|
});
|
||||||
setValue(result);
|
setValue(result);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
message.error(data);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -594,8 +590,8 @@ const Crontab = () => {
|
|||||||
data: [record.id],
|
data: [record.id],
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.then((data: any) => {
|
.then(({ code, data }) => {
|
||||||
if (data.code === 200) {
|
if (code === 200) {
|
||||||
const newStatus = record.isDisabled === 1 ? 0 : 1;
|
const newStatus = record.isDisabled === 1 ? 0 : 1;
|
||||||
const result = [...value];
|
const result = [...value];
|
||||||
const i = result.findIndex((x) => x.id === record.id);
|
const i = result.findIndex((x) => x.id === record.id);
|
||||||
@@ -606,8 +602,6 @@ const Crontab = () => {
|
|||||||
});
|
});
|
||||||
setValue(result);
|
setValue(result);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
message.error(data);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -640,8 +634,8 @@ const Crontab = () => {
|
|||||||
data: [record.id],
|
data: [record.id],
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.then((data: any) => {
|
.then(({ code, data }) => {
|
||||||
if (data.code === 200) {
|
if (code === 200) {
|
||||||
const newStatus = record.isPinned === 1 ? 0 : 1;
|
const newStatus = record.isPinned === 1 ? 0 : 1;
|
||||||
const result = [...value];
|
const result = [...value];
|
||||||
const i = result.findIndex((x) => x.id === record.id);
|
const i = result.findIndex((x) => x.id === record.id);
|
||||||
@@ -652,8 +646,6 @@ const Crontab = () => {
|
|||||||
});
|
});
|
||||||
setValue(result);
|
setValue(result);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
message.error(data);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -755,19 +747,21 @@ const Crontab = () => {
|
|||||||
const getCronDetail = (cron: any) => {
|
const getCronDetail = (cron: any) => {
|
||||||
request
|
request
|
||||||
.get(`${config.apiPrefix}crons/${cron.id}`)
|
.get(`${config.apiPrefix}crons/${cron.id}`)
|
||||||
.then((data: any) => {
|
.then(({ code, data }) => {
|
||||||
const index = value.findIndex((x) => x.id === cron.id);
|
if (code === 200) {
|
||||||
const result = [...value];
|
const index = value.findIndex((x) => x.id === cron.id);
|
||||||
data.data.nextRunTime = cron_parser
|
const result = [...value];
|
||||||
.parseExpression(data.data.schedule)
|
data.nextRunTime = cron_parser
|
||||||
.next()
|
.parseExpression(data.schedule)
|
||||||
.toDate();
|
.next()
|
||||||
if (index !== -1) {
|
.toDate();
|
||||||
result.splice(index, 1, {
|
if (index !== -1) {
|
||||||
...cron,
|
result.splice(index, 1, {
|
||||||
...data.data,
|
...cron,
|
||||||
});
|
...data,
|
||||||
setValue(result);
|
});
|
||||||
|
setValue(result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.finally(() => setLoading(false));
|
.finally(() => setLoading(false));
|
||||||
@@ -795,13 +789,11 @@ const Crontab = () => {
|
|||||||
onOk() {
|
onOk() {
|
||||||
request
|
request
|
||||||
.delete(`${config.apiPrefix}crons`, { data: selectedRowIds })
|
.delete(`${config.apiPrefix}crons`, { data: selectedRowIds })
|
||||||
.then((data: any) => {
|
.then(({ code, data }) => {
|
||||||
if (data.code === 200) {
|
if (code === 200) {
|
||||||
message.success('批量删除成功');
|
message.success('批量删除成功');
|
||||||
setSelectedRowIds([]);
|
setSelectedRowIds([]);
|
||||||
getCrons();
|
getCrons();
|
||||||
} else {
|
|
||||||
message.error(data);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -820,11 +812,9 @@ const Crontab = () => {
|
|||||||
.put(`${config.apiPrefix}crons/${OperationPath[operationStatus]}`, {
|
.put(`${config.apiPrefix}crons/${OperationPath[operationStatus]}`, {
|
||||||
data: selectedRowIds,
|
data: selectedRowIds,
|
||||||
})
|
})
|
||||||
.then((data: any) => {
|
.then(({ code, data }) => {
|
||||||
if (data.code === 200) {
|
if (code === 200) {
|
||||||
getCrons();
|
getCrons();
|
||||||
} else {
|
|
||||||
message.error(data);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -1029,9 +1019,11 @@ const Crontab = () => {
|
|||||||
setLoading(true);
|
setLoading(true);
|
||||||
request
|
request
|
||||||
.get(`${config.apiPrefix}crons/views`)
|
.get(`${config.apiPrefix}crons/views`)
|
||||||
.then((data: any) => {
|
.then(({ code, data }) => {
|
||||||
setCronViews(data.data);
|
if (code === 200) {
|
||||||
setEnabledCronViews(data.data.filter((x) => !x.isDisabled));
|
setCronViews(data);
|
||||||
|
setEnabledCronViews(data.filter((x) => !x.isDisabled));
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
|||||||
@@ -41,9 +41,12 @@ const CronLogModal = ({
|
|||||||
}
|
}
|
||||||
request
|
request
|
||||||
.get(logUrl ? logUrl : `${config.apiPrefix}crons/${cron.id}/log`)
|
.get(logUrl ? logUrl : `${config.apiPrefix}crons/${cron.id}/log`)
|
||||||
.then((data: any) => {
|
.then(({ code, data }) => {
|
||||||
if (localStorage.getItem('logCron') === String(cron.id)) {
|
if (
|
||||||
const log = data.data as string;
|
code === 200 &&
|
||||||
|
localStorage.getItem('logCron') === String(cron.id)
|
||||||
|
) {
|
||||||
|
const log = data as string;
|
||||||
setValue(log || '暂无日志');
|
setValue(log || '暂无日志');
|
||||||
setExecuting(
|
setExecuting(
|
||||||
log && !log.includes('执行结束') && !log.includes('重启面板'),
|
log && !log.includes('执行结束') && !log.includes('重启面板'),
|
||||||
|
|||||||
@@ -32,8 +32,6 @@ const CronModal = ({
|
|||||||
if (code === 200) {
|
if (code === 200) {
|
||||||
message.success(cron ? '更新Cron成功' : '新建Cron成功');
|
message.success(cron ? '更新Cron成功' : '新建Cron成功');
|
||||||
handleCancel(data);
|
handleCancel(data);
|
||||||
} else {
|
|
||||||
message.error(data);
|
|
||||||
}
|
}
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
@@ -142,8 +140,6 @@ const CronLabelModal = ({
|
|||||||
action === 'post' ? '添加Labels成功' : '删除Labels成功',
|
action === 'post' ? '添加Labels成功' : '删除Labels成功',
|
||||||
);
|
);
|
||||||
handleCancel(true);
|
handleCancel(true);
|
||||||
} else {
|
|
||||||
message.error(data);
|
|
||||||
}
|
}
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -66,9 +66,7 @@ const ViewCreateModal = ({
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
if (code !== 200) {
|
if (code === 200) {
|
||||||
message.error(data);
|
|
||||||
} else {
|
|
||||||
handleCancel(data);
|
handleCancel(data);
|
||||||
}
|
}
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
|||||||
@@ -141,12 +141,10 @@ const ViewManageModal = ({
|
|||||||
onOk() {
|
onOk() {
|
||||||
request
|
request
|
||||||
.delete(`${config.apiPrefix}crons/views`, { data: [record.id] })
|
.delete(`${config.apiPrefix}crons/views`, { data: [record.id] })
|
||||||
.then((data: any) => {
|
.then(({ code, data }) => {
|
||||||
if (data.code === 200) {
|
if (code === 200) {
|
||||||
message.success('删除成功');
|
message.success('删除成功');
|
||||||
cronViewChange();
|
cronViewChange();
|
||||||
} else {
|
|
||||||
message.error(data);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -162,14 +160,12 @@ const ViewManageModal = ({
|
|||||||
.put(`${config.apiPrefix}crons/views/${checked ? 'enable' : 'disable'}`, {
|
.put(`${config.apiPrefix}crons/views/${checked ? 'enable' : 'disable'}`, {
|
||||||
data: [record.id],
|
data: [record.id],
|
||||||
})
|
})
|
||||||
.then((data: any) => {
|
.then(({ code, data }) => {
|
||||||
if (data.code === 200) {
|
if (code === 200) {
|
||||||
const _list = [...list];
|
const _list = [...list];
|
||||||
_list.splice(index, 1, { ...list[index], isDisabled: !checked });
|
_list.splice(index, 1, { ...list[index], isDisabled: !checked });
|
||||||
setList(_list);
|
setList(_list);
|
||||||
cronViewChange();
|
cronViewChange();
|
||||||
} else {
|
|
||||||
message.error(data);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -190,15 +186,13 @@ const ViewManageModal = ({
|
|||||||
.put(`${config.apiPrefix}crons/views/move`, {
|
.put(`${config.apiPrefix}crons/views/move`, {
|
||||||
data: { fromIndex: dragIndex, toIndex: hoverIndex, id: dragRow.id },
|
data: { fromIndex: dragIndex, toIndex: hoverIndex, id: dragRow.id },
|
||||||
})
|
})
|
||||||
.then((data: any) => {
|
.then(({ code, data }) => {
|
||||||
if (data.code === 200) {
|
if (code === 200) {
|
||||||
const newData = [...list];
|
const newData = [...list];
|
||||||
newData.splice(dragIndex, 1);
|
newData.splice(dragIndex, 1);
|
||||||
newData.splice(hoverIndex, 0, { ...dragRow, ...data.data });
|
newData.splice(hoverIndex, 0, { ...dragRow, ...data });
|
||||||
setList(newData);
|
setList(newData);
|
||||||
cronViewChange();
|
cronViewChange();
|
||||||
} else {
|
|
||||||
message.error(data);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -175,8 +175,10 @@ const Dependence = () => {
|
|||||||
.get(
|
.get(
|
||||||
`${config.apiPrefix}dependencies?searchValue=${searchText}&type=${type}`,
|
`${config.apiPrefix}dependencies?searchValue=${searchText}&type=${type}`,
|
||||||
)
|
)
|
||||||
.then((data: any) => {
|
.then(({ code, data }) => {
|
||||||
setValue(data.data);
|
if (code === 200) {
|
||||||
|
setValue(data);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.finally(() => setLoading(false));
|
.finally(() => setLoading(false));
|
||||||
};
|
};
|
||||||
@@ -212,18 +214,14 @@ const Dependence = () => {
|
|||||||
.delete(`${config.apiPrefix}dependencies${force ? '/force' : ''}`, {
|
.delete(`${config.apiPrefix}dependencies${force ? '/force' : ''}`, {
|
||||||
data: [record.id],
|
data: [record.id],
|
||||||
})
|
})
|
||||||
.then((data: any) => {
|
.then(({ code, data }) => {
|
||||||
if (data.code === 200) {
|
if (code === 200 && force) {
|
||||||
if (force) {
|
const i = value.findIndex((x) => x.id === data.data[0].id);
|
||||||
const i = value.findIndex((x) => x.id === data.data[0].id);
|
if (i !== -1) {
|
||||||
if (i !== -1) {
|
const result = [...value];
|
||||||
const result = [...value];
|
result.splice(i, 1);
|
||||||
result.splice(i, 1);
|
setValue(result);
|
||||||
setValue(result);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
message.error(data);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -250,11 +248,9 @@ const Dependence = () => {
|
|||||||
.put(`${config.apiPrefix}dependencies/reinstall`, {
|
.put(`${config.apiPrefix}dependencies/reinstall`, {
|
||||||
data: [record.id],
|
data: [record.id],
|
||||||
})
|
})
|
||||||
.then((data: any) => {
|
.then(({ code, data }) => {
|
||||||
if (data.code === 200) {
|
if (code === 200) {
|
||||||
handleDependence(data.data[0]);
|
handleDependence(data[0]);
|
||||||
} else {
|
|
||||||
message.error(data);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -309,12 +305,10 @@ const Dependence = () => {
|
|||||||
.delete(`${config.apiPrefix}dependencies${forceUrl}`, {
|
.delete(`${config.apiPrefix}dependencies${forceUrl}`, {
|
||||||
data: selectedRowIds,
|
data: selectedRowIds,
|
||||||
})
|
})
|
||||||
.then((data: any) => {
|
.then(({ code, data }) => {
|
||||||
if (data.code === 200) {
|
if (code === 200) {
|
||||||
setSelectedRowIds([]);
|
setSelectedRowIds([]);
|
||||||
getDependencies();
|
getDependencies();
|
||||||
} else {
|
|
||||||
message.error(data);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -333,12 +327,10 @@ const Dependence = () => {
|
|||||||
.put(`${config.apiPrefix}dependencies/reinstall`, {
|
.put(`${config.apiPrefix}dependencies/reinstall`, {
|
||||||
data: selectedRowIds,
|
data: selectedRowIds,
|
||||||
})
|
})
|
||||||
.then((data: any) => {
|
.then(({ code, data }) => {
|
||||||
if (data.code === 200) {
|
if (code === 200) {
|
||||||
setSelectedRowIds([]);
|
setSelectedRowIds([]);
|
||||||
getDependencies();
|
getDependencies();
|
||||||
} else {
|
|
||||||
message.error(data);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -351,15 +343,17 @@ const Dependence = () => {
|
|||||||
const getDependenceDetail = (dependence: any) => {
|
const getDependenceDetail = (dependence: any) => {
|
||||||
request
|
request
|
||||||
.get(`${config.apiPrefix}dependencies/${dependence.id}`)
|
.get(`${config.apiPrefix}dependencies/${dependence.id}`)
|
||||||
.then((data: any) => {
|
.then(({ code, data }) => {
|
||||||
const index = value.findIndex((x) => x.id === dependence.id);
|
if (code === 200) {
|
||||||
const result = [...value];
|
const index = value.findIndex((x) => x.id === dependence.id);
|
||||||
if (index !== -1) {
|
const result = [...value];
|
||||||
result.splice(index, 1, {
|
if (index !== -1) {
|
||||||
...dependence,
|
result.splice(index, 1, {
|
||||||
...data.data,
|
...dependence,
|
||||||
});
|
...data,
|
||||||
setValue(result);
|
});
|
||||||
|
setValue(result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.finally(() => setLoading(false));
|
.finally(() => setLoading(false));
|
||||||
|
|||||||
@@ -48,9 +48,12 @@ const DependenceLogModal = ({
|
|||||||
setLoading(true);
|
setLoading(true);
|
||||||
request
|
request
|
||||||
.get(`${config.apiPrefix}dependencies/${dependence.id}`)
|
.get(`${config.apiPrefix}dependencies/${dependence.id}`)
|
||||||
.then((data: any) => {
|
.then(({ code, data }) => {
|
||||||
if (localStorage.getItem('logDependence') === String(dependence.id)) {
|
if (
|
||||||
const log = (data.data.log || []).join('') as string;
|
code === 200 &&
|
||||||
|
localStorage.getItem('logDependence') === String(dependence.id)
|
||||||
|
) {
|
||||||
|
const log = (data.log || []).join('') as string;
|
||||||
setValue(log);
|
setValue(log);
|
||||||
setExecuting(!log.includes('结束时间'));
|
setExecuting(!log.includes('结束时间'));
|
||||||
setIsRemoveFailed(log.includes('删除失败'));
|
setIsRemoveFailed(log.includes('删除失败'));
|
||||||
@@ -67,8 +70,10 @@ const DependenceLogModal = ({
|
|||||||
.delete(`${config.apiPrefix}dependencies/force`, {
|
.delete(`${config.apiPrefix}dependencies/force`, {
|
||||||
data: [dependence.id],
|
data: [dependence.id],
|
||||||
})
|
})
|
||||||
.then((data: any) => {
|
.then(({ code, data }) => {
|
||||||
cancel(true);
|
if (code === 200) {
|
||||||
|
cancel(true);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
setRemoveLoading(false);
|
setRemoveLoading(false);
|
||||||
|
|||||||
@@ -53,9 +53,7 @@ const DependenceModal = ({
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
if (code !== 200) {
|
if (code === 200) {
|
||||||
message.error(data);
|
|
||||||
} else {
|
|
||||||
handleCancel(data);
|
handleCancel(data);
|
||||||
}
|
}
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
|||||||
+22
-10
@@ -22,15 +22,23 @@ const Diff = () => {
|
|||||||
const editorRef = useRef<any>(null);
|
const editorRef = useRef<any>(null);
|
||||||
|
|
||||||
const getConfig = () => {
|
const getConfig = () => {
|
||||||
request.get(`${config.apiPrefix}configs/${current}`).then((data) => {
|
request
|
||||||
setCurrentValue(data.data);
|
.get(`${config.apiPrefix}configs/${current}`)
|
||||||
});
|
.then(({ code, data }) => {
|
||||||
|
if (code === 200) {
|
||||||
|
setCurrentValue(data);
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const getSample = () => {
|
const getSample = () => {
|
||||||
request.get(`${config.apiPrefix}configs/${origin}`).then((data) => {
|
request
|
||||||
setOriginValue(data.data);
|
.get(`${config.apiPrefix}configs/${origin}`)
|
||||||
});
|
.then(({ code, data }) => {
|
||||||
|
if (code === 200) {
|
||||||
|
setOriginValue(data);
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateConfig = () => {
|
const updateConfig = () => {
|
||||||
@@ -42,8 +50,10 @@ const Diff = () => {
|
|||||||
.post(`${config.apiPrefix}configs/save`, {
|
.post(`${config.apiPrefix}configs/save`, {
|
||||||
data: { content, name: current },
|
data: { content, name: current },
|
||||||
})
|
})
|
||||||
.then((data: any) => {
|
.then(({ code, data }) => {
|
||||||
message.success(data.message);
|
if (code === 200) {
|
||||||
|
message.success('保存成功');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -51,8 +61,10 @@ const Diff = () => {
|
|||||||
setLoading(true);
|
setLoading(true);
|
||||||
request
|
request
|
||||||
.get(`${config.apiPrefix}configs/files`)
|
.get(`${config.apiPrefix}configs/files`)
|
||||||
.then((data: any) => {
|
.then(({ code, data }) => {
|
||||||
setFiles(data.data);
|
if (code === 200) {
|
||||||
|
setFiles(data);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.finally(() => setLoading(false));
|
.finally(() => setLoading(false));
|
||||||
};
|
};
|
||||||
|
|||||||
Vendored
-2
@@ -28,8 +28,6 @@ const EditNameModal = ({
|
|||||||
if (code === 200) {
|
if (code === 200) {
|
||||||
message.success('更新环境变量名称成功');
|
message.success('更新环境变量名称成功');
|
||||||
handleCancel();
|
handleCancel();
|
||||||
} else {
|
|
||||||
message.error(data);
|
|
||||||
}
|
}
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Vendored
+14
-22
@@ -255,8 +255,10 @@ const Env = () => {
|
|||||||
setLoading(true);
|
setLoading(true);
|
||||||
request
|
request
|
||||||
.get(`${config.apiPrefix}envs?searchValue=${searchText}`)
|
.get(`${config.apiPrefix}envs?searchValue=${searchText}`)
|
||||||
.then((data: any) => {
|
.then(({ code, data }) => {
|
||||||
setValue(data.data);
|
if (code === 200) {
|
||||||
|
setValue(data);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.finally(() => setLoading(false));
|
.finally(() => setLoading(false));
|
||||||
};
|
};
|
||||||
@@ -284,8 +286,8 @@ const Env = () => {
|
|||||||
data: [record.id],
|
data: [record.id],
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.then((data: any) => {
|
.then(({ code, data }) => {
|
||||||
if (data.code === 200) {
|
if (code === 200) {
|
||||||
message.success(
|
message.success(
|
||||||
`${record.status === Status.已禁用 ? '启用' : '禁用'}成功`,
|
`${record.status === Status.已禁用 ? '启用' : '禁用'}成功`,
|
||||||
);
|
);
|
||||||
@@ -297,8 +299,6 @@ const Env = () => {
|
|||||||
status: newStatus,
|
status: newStatus,
|
||||||
});
|
});
|
||||||
setValue(result);
|
setValue(result);
|
||||||
} else {
|
|
||||||
message.error(data);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -333,14 +333,12 @@ const Env = () => {
|
|||||||
onOk() {
|
onOk() {
|
||||||
request
|
request
|
||||||
.delete(`${config.apiPrefix}envs`, { data: [record.id] })
|
.delete(`${config.apiPrefix}envs`, { data: [record.id] })
|
||||||
.then((data: any) => {
|
.then(({ code, data }) => {
|
||||||
if (data.code === 200) {
|
if (code === 200) {
|
||||||
message.success('删除成功');
|
message.success('删除成功');
|
||||||
const result = [...value];
|
const result = [...value];
|
||||||
result.splice(index, 1);
|
result.splice(index, 1);
|
||||||
setValue(result);
|
setValue(result);
|
||||||
} else {
|
|
||||||
message.error(data);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -390,14 +388,12 @@ const Env = () => {
|
|||||||
.put(`${config.apiPrefix}envs/${dragRow.id}/move`, {
|
.put(`${config.apiPrefix}envs/${dragRow.id}/move`, {
|
||||||
data: { fromIndex: dragIndex, toIndex: hoverIndex },
|
data: { fromIndex: dragIndex, toIndex: hoverIndex },
|
||||||
})
|
})
|
||||||
.then((data: any) => {
|
.then(({ code, data }) => {
|
||||||
if (data.code === 200) {
|
if (code === 200) {
|
||||||
const newData = [...value];
|
const newData = [...value];
|
||||||
newData.splice(dragIndex, 1);
|
newData.splice(dragIndex, 1);
|
||||||
newData.splice(hoverIndex, 0, { ...dragRow, ...data.data });
|
newData.splice(hoverIndex, 0, { ...dragRow, ...data.data });
|
||||||
setValue([...newData]);
|
setValue([...newData]);
|
||||||
} else {
|
|
||||||
message.error(data);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -426,13 +422,11 @@ const Env = () => {
|
|||||||
onOk() {
|
onOk() {
|
||||||
request
|
request
|
||||||
.delete(`${config.apiPrefix}envs`, { data: selectedRowIds })
|
.delete(`${config.apiPrefix}envs`, { data: selectedRowIds })
|
||||||
.then((data: any) => {
|
.then(({ code, data }) => {
|
||||||
if (data.code === 200) {
|
if (code === 200) {
|
||||||
message.success('批量删除成功');
|
message.success('批量删除成功');
|
||||||
setSelectedRowIds([]);
|
setSelectedRowIds([]);
|
||||||
getEnvs();
|
getEnvs();
|
||||||
} else {
|
|
||||||
message.error(data);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -451,11 +445,9 @@ const Env = () => {
|
|||||||
.put(`${config.apiPrefix}envs/${OperationPath[operationStatus]}`, {
|
.put(`${config.apiPrefix}envs/${OperationPath[operationStatus]}`, {
|
||||||
data: selectedRowIds,
|
data: selectedRowIds,
|
||||||
})
|
})
|
||||||
.then((data: any) => {
|
.then(({ code, data }) => {
|
||||||
if (data.code === 200) {
|
if (code === 200) {
|
||||||
getEnvs();
|
getEnvs();
|
||||||
} else {
|
|
||||||
message.error(data);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
Vendored
-2
@@ -44,8 +44,6 @@ const EnvModal = ({
|
|||||||
if (code === 200) {
|
if (code === 200) {
|
||||||
message.success(env ? '更新变量成功' : '新建变量成功');
|
message.success(env ? '更新变量成功' : '新建变量成功');
|
||||||
handleCancel(data);
|
handleCancel(data);
|
||||||
} else {
|
|
||||||
message.error(data);
|
|
||||||
}
|
}
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
|
|||||||
@@ -17,8 +17,10 @@ const Error = () => {
|
|||||||
setLoading(true);
|
setLoading(true);
|
||||||
request
|
request
|
||||||
.get(`${config.apiPrefix}public/panel/log`)
|
.get(`${config.apiPrefix}public/panel/log`)
|
||||||
.then((data: any) => {
|
.then(({ code, data }) => {
|
||||||
setData(data.data);
|
if (code === 200) {
|
||||||
|
setData(data);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.finally(() => setLoading(false));
|
.finally(() => setLoading(false));
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -41,11 +41,9 @@ const Initialization = () => {
|
|||||||
password: values.password,
|
password: values.password,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then((data) => {
|
.then(({ code, data }) => {
|
||||||
if (data.code === 200) {
|
if (code === 200) {
|
||||||
next();
|
next();
|
||||||
} else {
|
|
||||||
message.error(data.message);
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.finally(() => setLoading(false));
|
.finally(() => setLoading(false));
|
||||||
@@ -59,11 +57,9 @@ const Initialization = () => {
|
|||||||
...values,
|
...values,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then((_data: any) => {
|
.then(({ code, data }) => {
|
||||||
if (_data && _data.code === 200) {
|
if (code === 200) {
|
||||||
next();
|
next();
|
||||||
} else {
|
|
||||||
message.error(_data.message);
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.finally(() => setLoading(false));
|
.finally(() => setLoading(false));
|
||||||
|
|||||||
+150
-60
@@ -1,5 +1,15 @@
|
|||||||
import { useState, useEffect, useCallback, Key, useRef } from 'react';
|
import { useState, useEffect, useCallback, Key, useRef } from 'react';
|
||||||
import { TreeSelect, Tree, Input, Empty } from 'antd';
|
import {
|
||||||
|
TreeSelect,
|
||||||
|
Tree,
|
||||||
|
Input,
|
||||||
|
Empty,
|
||||||
|
Button,
|
||||||
|
message,
|
||||||
|
Modal,
|
||||||
|
Tooltip,
|
||||||
|
Typography,
|
||||||
|
} from 'antd';
|
||||||
import config from '@/utils/config';
|
import config from '@/utils/config';
|
||||||
import { PageContainer } from '@ant-design/pro-layout';
|
import { PageContainer } from '@ant-design/pro-layout';
|
||||||
import Editor from '@monaco-editor/react';
|
import Editor from '@monaco-editor/react';
|
||||||
@@ -9,54 +19,33 @@ import { Controlled as CodeMirror } from 'react-codemirror2';
|
|||||||
import SplitPane from 'react-split-pane';
|
import SplitPane from 'react-split-pane';
|
||||||
import { useOutletContext } from '@umijs/max';
|
import { useOutletContext } from '@umijs/max';
|
||||||
import { SharedContext } from '@/layouts';
|
import { SharedContext } from '@/layouts';
|
||||||
|
import { DeleteOutlined } from '@ant-design/icons';
|
||||||
|
import { depthFirstSearch } from '@/utils';
|
||||||
|
import { debounce, uniq } from 'lodash';
|
||||||
|
import useFilterTreeData from '@/hooks/useFilterTreeData';
|
||||||
|
|
||||||
function getFilterData(keyword: string, data: any) {
|
const { Text } = Typography;
|
||||||
const expandedKeys: string[] = [];
|
|
||||||
if (keyword) {
|
|
||||||
const tree: any = [];
|
|
||||||
data.forEach((item: any) => {
|
|
||||||
if (item.title.toLocaleLowerCase().includes(keyword)) {
|
|
||||||
tree.push(item);
|
|
||||||
} else {
|
|
||||||
const children: any[] = [];
|
|
||||||
(item.children || []).forEach((subItem: any) => {
|
|
||||||
if (subItem.title.toLocaleLowerCase().includes(keyword)) {
|
|
||||||
children.push(subItem);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (children.length > 0) {
|
|
||||||
tree.push({
|
|
||||||
...item,
|
|
||||||
children,
|
|
||||||
});
|
|
||||||
expandedKeys.push(item.key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return { tree, expandedKeys };
|
|
||||||
}
|
|
||||||
return { tree: data, expandedKeys };
|
|
||||||
}
|
|
||||||
|
|
||||||
const Log = () => {
|
const Log = () => {
|
||||||
const { headerStyle, isPhone, theme } = useOutletContext<SharedContext>();
|
const { headerStyle, isPhone, theme } = useOutletContext<SharedContext>();
|
||||||
const [title, setTitle] = useState('请选择日志文件');
|
|
||||||
const [value, setValue] = useState('请选择日志文件');
|
const [value, setValue] = useState('请选择日志文件');
|
||||||
const [select, setSelect] = useState<any>();
|
const [select, setSelect] = useState<string>('');
|
||||||
const [data, setData] = useState<any[]>([]);
|
const [data, setData] = useState<any[]>([]);
|
||||||
const [filterData, setFilterData] = useState<any[]>([]);
|
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [height, setHeight] = useState<number>();
|
const [height, setHeight] = useState<number>();
|
||||||
const treeDom = useRef<any>();
|
const treeDom = useRef<any>();
|
||||||
const [expandedKeys, setExpandedKeys] = useState<string[]>([]);
|
const [expandedKeys, setExpandedKeys] = useState<string[]>([]);
|
||||||
|
const [currentNode, setCurrentNode] = useState<any>();
|
||||||
|
const [searchValue, setSearchValue] = useState('');
|
||||||
|
|
||||||
const getLogs = () => {
|
const getLogs = () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
request
|
request
|
||||||
.get(`${config.apiPrefix}logs`)
|
.get(`${config.apiPrefix}logs`)
|
||||||
.then((data) => {
|
.then(({ code, data }) => {
|
||||||
setData(data.data);
|
if (code === 200) {
|
||||||
setFilterData(data.data);
|
setData(data);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.finally(() => setLoading(false));
|
.finally(() => setLoading(false));
|
||||||
};
|
};
|
||||||
@@ -64,18 +53,27 @@ const Log = () => {
|
|||||||
const getLog = (node: any) => {
|
const getLog = (node: any) => {
|
||||||
request
|
request
|
||||||
.get(`${config.apiPrefix}logs/${node.title}?path=${node.parent || ''}`)
|
.get(`${config.apiPrefix}logs/${node.title}?path=${node.parent || ''}`)
|
||||||
.then((data) => {
|
.then(({ code, data }) => {
|
||||||
setValue(data.data);
|
if (code === 200) {
|
||||||
|
setValue(data);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const onSelect = (value: any, node: any) => {
|
const onSelect = (value: any, node: any) => {
|
||||||
|
setCurrentNode(node);
|
||||||
|
setSelect(value);
|
||||||
|
|
||||||
if (node.key === select || !value) {
|
if (node.key === select || !value) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (node.type === 'directory') {
|
||||||
|
setValue('请选择日志文件');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
setValue('加载中...');
|
setValue('加载中...');
|
||||||
setSelect(value);
|
|
||||||
setTitle(node.key);
|
|
||||||
getLog(node);
|
getLog(node);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -86,41 +84,129 @@ const Log = () => {
|
|||||||
const onSearch = useCallback(
|
const onSearch = useCallback(
|
||||||
(e) => {
|
(e) => {
|
||||||
const keyword = e.target.value;
|
const keyword = e.target.value;
|
||||||
const { tree, expandedKeys } = getFilterData(
|
debounceSearch(keyword);
|
||||||
keyword.toLocaleLowerCase(),
|
|
||||||
data,
|
|
||||||
);
|
|
||||||
setFilterData(tree);
|
|
||||||
setExpandedKeys(expandedKeys);
|
|
||||||
},
|
},
|
||||||
[data, setFilterData],
|
[data],
|
||||||
|
);
|
||||||
|
|
||||||
|
const debounceSearch = useCallback(
|
||||||
|
debounce((keyword) => {
|
||||||
|
setSearchValue(keyword);
|
||||||
|
}, 300),
|
||||||
|
[data],
|
||||||
|
);
|
||||||
|
|
||||||
|
const { treeData: filterData, keys: searchExpandedKeys } = useFilterTreeData(
|
||||||
|
data,
|
||||||
|
searchValue,
|
||||||
|
{ treeNodeFilterProp: 'title' },
|
||||||
);
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setExpandedKeys(uniq([...expandedKeys, ...searchExpandedKeys]));
|
||||||
|
}, [searchExpandedKeys]);
|
||||||
|
|
||||||
|
const deleteFile = () => {
|
||||||
|
Modal.confirm({
|
||||||
|
title: `确认删除`,
|
||||||
|
content: (
|
||||||
|
<>
|
||||||
|
确认删除
|
||||||
|
<Text style={{ wordBreak: 'break-all' }} type="warning">
|
||||||
|
{select}
|
||||||
|
</Text>
|
||||||
|
文件{currentNode.type === 'directory' ? '夹下所以日志' : ''}
|
||||||
|
,删除后不可恢复
|
||||||
|
</>
|
||||||
|
),
|
||||||
|
onOk() {
|
||||||
|
request
|
||||||
|
.delete(`${config.apiPrefix}logs`, {
|
||||||
|
data: {
|
||||||
|
filename: currentNode.title,
|
||||||
|
path: currentNode.parent || '',
|
||||||
|
type: currentNode.type,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.then(({ code }) => {
|
||||||
|
if (code === 200) {
|
||||||
|
message.success(`删除成功`);
|
||||||
|
let newData = [...data];
|
||||||
|
if (currentNode.parent) {
|
||||||
|
newData = depthFirstSearch(
|
||||||
|
newData,
|
||||||
|
(c) => c.key === currentNode.key,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
const index = newData.findIndex(
|
||||||
|
(x) => x.key === currentNode.key,
|
||||||
|
);
|
||||||
|
if (index !== -1) {
|
||||||
|
newData.splice(index, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setData(newData);
|
||||||
|
initState();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onCancel() {
|
||||||
|
console.log('Cancel');
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const initState = () => {
|
||||||
|
setSelect('');
|
||||||
|
setCurrentNode(null);
|
||||||
|
setValue('请选择脚本文件');
|
||||||
|
};
|
||||||
|
|
||||||
|
const onExpand = (expKeys: any) => {
|
||||||
|
setExpandedKeys(expKeys);
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getLogs();
|
getLogs();
|
||||||
if (treeDom && treeDom.current) {
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (treeDom.current) {
|
||||||
setHeight(treeDom.current.clientHeight);
|
setHeight(treeDom.current.clientHeight);
|
||||||
}
|
}
|
||||||
}, []);
|
}, [treeDom.current, data]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PageContainer
|
<PageContainer
|
||||||
className="ql-container-wrapper log-wrapper"
|
className="ql-container-wrapper log-wrapper"
|
||||||
title={title}
|
title={select}
|
||||||
loading={loading}
|
loading={loading}
|
||||||
extra={
|
extra={
|
||||||
isPhone && [
|
isPhone
|
||||||
<TreeSelect
|
? [
|
||||||
className="log-select"
|
<TreeSelect
|
||||||
value={select}
|
className="log-select"
|
||||||
dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
|
value={select}
|
||||||
treeData={data}
|
dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
|
||||||
placeholder="请选择日志"
|
treeData={data}
|
||||||
fieldNames={{ value: 'key', label: 'title' }}
|
placeholder="请选择日志"
|
||||||
showSearch
|
fieldNames={{ value: 'key' }}
|
||||||
onSelect={onSelect}
|
treeNodeFilterProp="title"
|
||||||
/>,
|
showSearch
|
||||||
]
|
allowClear
|
||||||
|
onSelect={onSelect}
|
||||||
|
/>,
|
||||||
|
]
|
||||||
|
: [
|
||||||
|
<Tooltip title="删除">
|
||||||
|
<Button
|
||||||
|
type="primary"
|
||||||
|
disabled={!select}
|
||||||
|
onClick={deleteFile}
|
||||||
|
icon={<DeleteOutlined />}
|
||||||
|
/>
|
||||||
|
</Tooltip>,
|
||||||
|
]
|
||||||
}
|
}
|
||||||
header={{
|
header={{
|
||||||
style: headerStyle,
|
style: headerStyle,
|
||||||
@@ -128,6 +214,7 @@ const Log = () => {
|
|||||||
>
|
>
|
||||||
<div className={`${styles['log-container']} log-container`}>
|
<div className={`${styles['log-container']} log-container`}>
|
||||||
{!isPhone && (
|
{!isPhone && (
|
||||||
|
/*// @ts-ignore*/
|
||||||
<SplitPane split="vertical" size={200} maxSize={-100}>
|
<SplitPane split="vertical" size={200} maxSize={-100}>
|
||||||
<div className={styles['left-tree-container']}>
|
<div className={styles['left-tree-container']}>
|
||||||
{data.length > 0 ? (
|
{data.length > 0 ? (
|
||||||
@@ -140,6 +227,7 @@ const Log = () => {
|
|||||||
></Input.Search>
|
></Input.Search>
|
||||||
<div className={styles['left-tree-scroller']} ref={treeDom}>
|
<div className={styles['left-tree-scroller']} ref={treeDom}>
|
||||||
<Tree
|
<Tree
|
||||||
|
expandAction="click"
|
||||||
className={styles['left-tree']}
|
className={styles['left-tree']}
|
||||||
treeData={filterData}
|
treeData={filterData}
|
||||||
showIcon={true}
|
showIcon={true}
|
||||||
@@ -147,6 +235,8 @@ const Log = () => {
|
|||||||
selectedKeys={[select]}
|
selectedKeys={[select]}
|
||||||
showLine={{ showLeafIcon: true }}
|
showLine={{ showLeafIcon: true }}
|
||||||
onSelect={onTreeSelect}
|
onSelect={onTreeSelect}
|
||||||
|
expandedKeys={expandedKeys}
|
||||||
|
onExpand={onExpand}
|
||||||
></Tree>
|
></Tree>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
|
|||||||
+16
-24
@@ -40,15 +40,7 @@ const Login = () => {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
if (data.code === 420) {
|
checkResponse(data, values);
|
||||||
setLoginInfo({
|
|
||||||
username: values.username,
|
|
||||||
password: values.password,
|
|
||||||
});
|
|
||||||
setTwoFactor(true);
|
|
||||||
} else {
|
|
||||||
checkResponse(data);
|
|
||||||
}
|
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
})
|
})
|
||||||
.catch(function (error) {
|
.catch(function (error) {
|
||||||
@@ -64,11 +56,7 @@ const Login = () => {
|
|||||||
data: { ...loginInfo, code: values.code },
|
data: { ...loginInfo, code: values.code },
|
||||||
})
|
})
|
||||||
.then((data: any) => {
|
.then((data: any) => {
|
||||||
if (data.code === 430) {
|
checkResponse(data);
|
||||||
message.error(data.message);
|
|
||||||
} else {
|
|
||||||
checkResponse(data);
|
|
||||||
}
|
|
||||||
setVerifying(false);
|
setVerifying(false);
|
||||||
})
|
})
|
||||||
.catch((error: any) => {
|
.catch((error: any) => {
|
||||||
@@ -77,8 +65,11 @@ const Login = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const checkResponse = (data: any) => {
|
const checkResponse = (
|
||||||
if (data.code === 200) {
|
{ code, data, message: _message }: any,
|
||||||
|
values?: any,
|
||||||
|
) => {
|
||||||
|
if (code === 200) {
|
||||||
const {
|
const {
|
||||||
token,
|
token,
|
||||||
lastip,
|
lastip,
|
||||||
@@ -86,7 +77,7 @@ const Login = () => {
|
|||||||
lastlogon,
|
lastlogon,
|
||||||
retries = 0,
|
retries = 0,
|
||||||
platform,
|
platform,
|
||||||
} = data.data;
|
} = data;
|
||||||
localStorage.setItem(config.authKey, token);
|
localStorage.setItem(config.authKey, token);
|
||||||
notification.success({
|
notification.success({
|
||||||
message: '登录成功!',
|
message: '登录成功!',
|
||||||
@@ -105,13 +96,14 @@ const Login = () => {
|
|||||||
});
|
});
|
||||||
reloadUser(true);
|
reloadUser(true);
|
||||||
history.push('/crontab');
|
history.push('/crontab');
|
||||||
} else if (data.code === 100) {
|
} else if (code === 410) {
|
||||||
message.warn(data.message);
|
setWaitTime(data);
|
||||||
} else if (data.code === 410) {
|
} else if (code === 420) {
|
||||||
message.error(data.message);
|
setLoginInfo({
|
||||||
setWaitTime(data.data);
|
username: values.username,
|
||||||
} else {
|
password: values.password,
|
||||||
message.error(data.message);
|
});
|
||||||
|
setTwoFactor(true);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -67,8 +67,10 @@ const EditModal = ({
|
|||||||
const getDetail = (node: any) => {
|
const getDetail = (node: any) => {
|
||||||
request
|
request
|
||||||
.get(`${config.apiPrefix}scripts/${node.title}?path=${node.parent || ''}`)
|
.get(`${config.apiPrefix}scripts/${node.title}?path=${node.parent || ''}`)
|
||||||
.then((data) => {
|
.then(({ code, data }) => {
|
||||||
setValue(data.data);
|
if (code === 200) {
|
||||||
|
setValue(data);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -83,8 +85,10 @@ const EditModal = ({
|
|||||||
content,
|
content,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then((data) => {
|
.then(({ code, data }) => {
|
||||||
setIsRunning(true);
|
if (code === 200) {
|
||||||
|
setIsRunning(true);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -101,8 +105,10 @@ const EditModal = ({
|
|||||||
content,
|
content,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then((data) => {
|
.then(({ code, data }) => {
|
||||||
setIsRunning(false);
|
if (code === 200) {
|
||||||
|
setIsRunning(false);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -216,6 +222,7 @@ const EditModal = ({
|
|||||||
onClose={cancel}
|
onClose={cancel}
|
||||||
open={visible}
|
open={visible}
|
||||||
>
|
>
|
||||||
|
{/* @ts-ignore */}
|
||||||
<SplitPane
|
<SplitPane
|
||||||
split="vertical"
|
split="vertical"
|
||||||
minSize={200}
|
minSize={200}
|
||||||
|
|||||||
@@ -57,8 +57,6 @@ const EditScriptNameModal = ({
|
|||||||
path,
|
path,
|
||||||
key: `${key}${filename}`,
|
key: `${key}${filename}`,
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
message.error(data);
|
|
||||||
}
|
}
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
})
|
})
|
||||||
|
|||||||
+78
-92
@@ -37,37 +37,11 @@ import { history, useOutletContext, useLocation } from '@umijs/max';
|
|||||||
import { parse } from 'query-string';
|
import { parse } from 'query-string';
|
||||||
import { depthFirstSearch } from '@/utils';
|
import { depthFirstSearch } from '@/utils';
|
||||||
import { SharedContext } from '@/layouts';
|
import { SharedContext } from '@/layouts';
|
||||||
|
import useFilterTreeData from '@/hooks/useFilterTreeData';
|
||||||
|
import { uniq } from 'lodash';
|
||||||
|
|
||||||
const { Text } = Typography;
|
const { Text } = Typography;
|
||||||
|
|
||||||
function getFilterData(keyword: string, data: any) {
|
|
||||||
const expandedKeys: string[] = [];
|
|
||||||
if (keyword) {
|
|
||||||
const tree: any = [];
|
|
||||||
data.forEach((item: any) => {
|
|
||||||
if (item.title.toLocaleLowerCase().includes(keyword)) {
|
|
||||||
tree.push(item);
|
|
||||||
} else {
|
|
||||||
const children: any[] = [];
|
|
||||||
(item.children || []).forEach((subItem: any) => {
|
|
||||||
if (subItem.title.toLocaleLowerCase().includes(keyword)) {
|
|
||||||
children.push(subItem);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (children.length > 0) {
|
|
||||||
tree.push({
|
|
||||||
...item,
|
|
||||||
children,
|
|
||||||
});
|
|
||||||
expandedKeys.push(item.key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return { tree, expandedKeys };
|
|
||||||
}
|
|
||||||
return { tree: data, expandedKeys };
|
|
||||||
}
|
|
||||||
|
|
||||||
const LangMap: any = {
|
const LangMap: any = {
|
||||||
'.py': 'python',
|
'.py': 'python',
|
||||||
'.js': 'javascript',
|
'.js': 'javascript',
|
||||||
@@ -78,11 +52,9 @@ const LangMap: any = {
|
|||||||
const Script = () => {
|
const Script = () => {
|
||||||
const { headerStyle, isPhone, theme, socketMessage } =
|
const { headerStyle, isPhone, theme, socketMessage } =
|
||||||
useOutletContext<SharedContext>();
|
useOutletContext<SharedContext>();
|
||||||
const [title, setTitle] = useState('请选择脚本文件');
|
|
||||||
const [value, setValue] = useState('请选择脚本文件');
|
const [value, setValue] = useState('请选择脚本文件');
|
||||||
const [select, setSelect] = useState<any>();
|
const [select, setSelect] = useState<string>('');
|
||||||
const [data, setData] = useState<any[]>([]);
|
const [data, setData] = useState<any[]>([]);
|
||||||
const [filterData, setFilterData] = useState<any[]>([]);
|
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [mode, setMode] = useState('');
|
const [mode, setMode] = useState('');
|
||||||
const [height, setHeight] = useState<number>();
|
const [height, setHeight] = useState<number>();
|
||||||
@@ -99,10 +71,11 @@ const Script = () => {
|
|||||||
setLoading(true);
|
setLoading(true);
|
||||||
request
|
request
|
||||||
.get(`${config.apiPrefix}scripts`)
|
.get(`${config.apiPrefix}scripts`)
|
||||||
.then((data) => {
|
.then(({ code, data }) => {
|
||||||
setData(data.data);
|
if (code === 200) {
|
||||||
setFilterData(data.data);
|
setData(data);
|
||||||
initGetScript();
|
initGetScript();
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.finally(() => setLoading(false));
|
.finally(() => setLoading(false));
|
||||||
};
|
};
|
||||||
@@ -110,8 +83,10 @@ const Script = () => {
|
|||||||
const getDetail = (node: any) => {
|
const getDetail = (node: any) => {
|
||||||
request
|
request
|
||||||
.get(`${config.apiPrefix}scripts/${node.title}?path=${node.parent || ''}`)
|
.get(`${config.apiPrefix}scripts/${node.title}?path=${node.parent || ''}`)
|
||||||
.then((data) => {
|
.then(({ code, data }) => {
|
||||||
setValue(data.data);
|
if (code === 200) {
|
||||||
|
setValue(data);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -132,22 +107,24 @@ const Script = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const onSelect = (value: any, node: any) => {
|
const onSelect = (value: any, node: any) => {
|
||||||
|
setSelect(node.key);
|
||||||
|
setCurrentNode(node);
|
||||||
|
|
||||||
if (node.key === select || !value) {
|
if (node.key === select || !value) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setValue('加载中...');
|
|
||||||
|
if (node.type === 'directory') {
|
||||||
|
setValue('请选择脚本文件');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const newMode = value ? LangMap[value.slice(-3)] : '';
|
const newMode = value ? LangMap[value.slice(-3)] : '';
|
||||||
setMode(isPhone && newMode === 'typescript' ? 'javascript' : newMode);
|
setMode(isPhone && newMode === 'typescript' ? 'javascript' : newMode);
|
||||||
setSelect(node.key);
|
setValue('加载中...');
|
||||||
setTitle(node.key);
|
|
||||||
setCurrentNode(node);
|
|
||||||
getDetail(node);
|
getDetail(node);
|
||||||
};
|
};
|
||||||
|
|
||||||
const onExpand = (expKeys: any) => {
|
|
||||||
setExpandedKeys(expKeys);
|
|
||||||
};
|
|
||||||
|
|
||||||
const onTreeSelect = useCallback(
|
const onTreeSelect = useCallback(
|
||||||
(keys: Key[], e: any) => {
|
(keys: Key[], e: any) => {
|
||||||
const content = editorRef.current
|
const content = editorRef.current
|
||||||
@@ -178,22 +155,30 @@ const Script = () => {
|
|||||||
const keyword = e.target.value;
|
const keyword = e.target.value;
|
||||||
debounceSearch(keyword);
|
debounceSearch(keyword);
|
||||||
},
|
},
|
||||||
[data, setFilterData],
|
[data],
|
||||||
);
|
);
|
||||||
|
|
||||||
const debounceSearch = useCallback(
|
const debounceSearch = useCallback(
|
||||||
debounce((keyword) => {
|
debounce((keyword) => {
|
||||||
setSearchValue(keyword);
|
setSearchValue(keyword);
|
||||||
const { tree, expandedKeys } = getFilterData(
|
|
||||||
keyword.toLocaleLowerCase(),
|
|
||||||
data,
|
|
||||||
);
|
|
||||||
setExpandedKeys(expandedKeys);
|
|
||||||
setFilterData(tree);
|
|
||||||
}, 300),
|
}, 300),
|
||||||
[data, setFilterData],
|
[data],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const { treeData: filterData, keys: searchExpandedKeys } = useFilterTreeData(
|
||||||
|
data,
|
||||||
|
searchValue,
|
||||||
|
{ treeNodeFilterProp: 'title' },
|
||||||
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setExpandedKeys(uniq([...expandedKeys, ...searchExpandedKeys]));
|
||||||
|
}, [searchExpandedKeys]);
|
||||||
|
|
||||||
|
const onExpand = (expKeys: any) => {
|
||||||
|
setExpandedKeys(expKeys);
|
||||||
|
};
|
||||||
|
|
||||||
const editFile = () => {
|
const editFile = () => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
setIsEditing(true);
|
setIsEditing(true);
|
||||||
@@ -231,13 +216,11 @@ const Script = () => {
|
|||||||
content,
|
content,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then((_data: any) => {
|
.then(({ code, data }) => {
|
||||||
if (_data.code === 200) {
|
if (code === 200) {
|
||||||
message.success(`保存成功`);
|
message.success(`保存成功`);
|
||||||
setValue(content);
|
setValue(content);
|
||||||
setIsEditing(false);
|
setIsEditing(false);
|
||||||
} else {
|
|
||||||
message.error(_data);
|
|
||||||
}
|
}
|
||||||
resolve(null);
|
resolve(null);
|
||||||
})
|
})
|
||||||
@@ -255,10 +238,11 @@ const Script = () => {
|
|||||||
title: `确认删除`,
|
title: `确认删除`,
|
||||||
content: (
|
content: (
|
||||||
<>
|
<>
|
||||||
确认删除文件
|
确认删除
|
||||||
<Text style={{ wordBreak: 'break-all' }} type="warning">
|
<Text style={{ wordBreak: 'break-all' }} type="warning">
|
||||||
{select}
|
{select}
|
||||||
</Text>{' '}
|
</Text>
|
||||||
|
文件{currentNode.type === 'directory' ? '夹及其子文件' : ''}
|
||||||
,删除后不可恢复
|
,删除后不可恢复
|
||||||
</>
|
</>
|
||||||
),
|
),
|
||||||
@@ -268,24 +252,18 @@ const Script = () => {
|
|||||||
data: {
|
data: {
|
||||||
filename: currentNode.title,
|
filename: currentNode.title,
|
||||||
path: currentNode.parent || '',
|
path: currentNode.parent || '',
|
||||||
|
type: currentNode.type,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then((_data: any) => {
|
.then(({ code }) => {
|
||||||
if (_data.code === 200) {
|
if (code === 200) {
|
||||||
message.success(`删除成功`);
|
message.success(`删除成功`);
|
||||||
let newData = [...data];
|
let newData = [...data];
|
||||||
if (currentNode.parent) {
|
if (currentNode.parent) {
|
||||||
const parentNodeIndex = newData.findIndex(
|
newData = depthFirstSearch(
|
||||||
(x) => x.key === currentNode.parent,
|
newData,
|
||||||
|
(c) => c.key === currentNode.key,
|
||||||
);
|
);
|
||||||
const parentNode = newData[parentNodeIndex];
|
|
||||||
const index = parentNode.children.findIndex(
|
|
||||||
(y) => y.key === currentNode.key,
|
|
||||||
);
|
|
||||||
if (index !== -1 && parentNodeIndex !== -1) {
|
|
||||||
parentNode.children.splice(index, 1);
|
|
||||||
newData.splice(parentNodeIndex, 1, { ...parentNode });
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
const index = newData.findIndex(
|
const index = newData.findIndex(
|
||||||
(x) => x.key === currentNode.key,
|
(x) => x.key === currentNode.key,
|
||||||
@@ -295,8 +273,7 @@ const Script = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
setData(newData);
|
setData(newData);
|
||||||
} else {
|
initState();
|
||||||
message.error(_data);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -346,30 +323,35 @@ const Script = () => {
|
|||||||
filename: currentNode.title,
|
filename: currentNode.title,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then((_data: any) => {
|
.then(({ code, data }) => {
|
||||||
const blob = new Blob([_data], { type: 'application/json' });
|
if (code === 200) {
|
||||||
const url = URL.createObjectURL(blob);
|
const blob = new Blob([data], { type: 'application/json' });
|
||||||
const a = document.createElement('a');
|
const url = URL.createObjectURL(blob);
|
||||||
a.href = url;
|
const a = document.createElement('a');
|
||||||
a.download = currentNode.title;
|
a.href = url;
|
||||||
document.documentElement.appendChild(a);
|
a.download = currentNode.title;
|
||||||
a.click();
|
document.documentElement.appendChild(a);
|
||||||
document.documentElement.removeChild(a);
|
a.click();
|
||||||
|
document.documentElement.removeChild(a);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
const initState = () => {
|
||||||
const word = searchValue || '';
|
setSelect('');
|
||||||
const { tree } = getFilterData(word.toLocaleLowerCase(), data);
|
setCurrentNode(null);
|
||||||
setFilterData(tree);
|
setValue('请选择脚本文件');
|
||||||
}, [data]);
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getScripts();
|
getScripts();
|
||||||
if (treeDom && treeDom.current) {
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (treeDom.current) {
|
||||||
setHeight(treeDom.current.clientHeight);
|
setHeight(treeDom.current.clientHeight);
|
||||||
}
|
}
|
||||||
}, []);
|
}, [treeDom.current, data]);
|
||||||
|
|
||||||
const action = (key: string | number) => {
|
const action = (key: string | number) => {
|
||||||
switch (key) {
|
switch (key) {
|
||||||
@@ -438,19 +420,22 @@ const Script = () => {
|
|||||||
return (
|
return (
|
||||||
<PageContainer
|
<PageContainer
|
||||||
className="ql-container-wrapper log-wrapper"
|
className="ql-container-wrapper log-wrapper"
|
||||||
title={title}
|
title={select}
|
||||||
loading={loading}
|
loading={loading}
|
||||||
extra={
|
extra={
|
||||||
isPhone
|
isPhone
|
||||||
? [
|
? [
|
||||||
<TreeSelect
|
<TreeSelect
|
||||||
|
treeExpandAction="click"
|
||||||
className="log-select"
|
className="log-select"
|
||||||
value={select}
|
value={select}
|
||||||
dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
|
dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
|
||||||
treeData={data}
|
treeData={data}
|
||||||
placeholder="请选择脚本"
|
placeholder="请选择脚本"
|
||||||
fieldNames={{ value: 'key', label: 'title' }}
|
fieldNames={{ value: 'key' }}
|
||||||
|
treeNodeFilterProp="title"
|
||||||
showSearch
|
showSearch
|
||||||
|
allowClear
|
||||||
onSelect={onSelect}
|
onSelect={onSelect}
|
||||||
/>,
|
/>,
|
||||||
<Dropdown overlay={menu} trigger={['click']}>
|
<Dropdown overlay={menu} trigger={['click']}>
|
||||||
@@ -506,6 +491,7 @@ const Script = () => {
|
|||||||
>
|
>
|
||||||
<div className={`${styles['log-container']} log-container`}>
|
<div className={`${styles['log-container']} log-container`}>
|
||||||
{!isPhone && (
|
{!isPhone && (
|
||||||
|
/*// @ts-ignore*/
|
||||||
<SplitPane split="vertical" size={200} maxSize={-100}>
|
<SplitPane split="vertical" size={200} maxSize={-100}>
|
||||||
<div className={styles['left-tree-container']}>
|
<div className={styles['left-tree-container']}>
|
||||||
{data.length > 0 ? (
|
{data.length > 0 ? (
|
||||||
@@ -518,6 +504,7 @@ const Script = () => {
|
|||||||
></Input.Search>
|
></Input.Search>
|
||||||
<div className={styles['left-tree-scroller']} ref={treeDom}>
|
<div className={styles['left-tree-scroller']} ref={treeDom}>
|
||||||
<Tree
|
<Tree
|
||||||
|
expandAction="click"
|
||||||
className={styles['left-tree']}
|
className={styles['left-tree']}
|
||||||
treeData={filterData}
|
treeData={filterData}
|
||||||
showIcon={true}
|
showIcon={true}
|
||||||
@@ -554,7 +541,6 @@ const Script = () => {
|
|||||||
readOnly: !isEditing,
|
readOnly: !isEditing,
|
||||||
fontSize: 12,
|
fontSize: 12,
|
||||||
lineNumbersMinChars: 3,
|
lineNumbersMinChars: 3,
|
||||||
folding: false,
|
|
||||||
glyphMargin: false,
|
glyphMargin: false,
|
||||||
}}
|
}}
|
||||||
onMount={(editor) => {
|
onMount={(editor) => {
|
||||||
|
|||||||
@@ -26,8 +26,6 @@ const SaveModal = ({
|
|||||||
if (code === 200) {
|
if (code === 200) {
|
||||||
message.success('保存文件成功');
|
message.success('保存文件成功');
|
||||||
handleCancel(data);
|
handleCancel(data);
|
||||||
} else {
|
|
||||||
message.error(data);
|
|
||||||
}
|
}
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -26,8 +26,6 @@ const SettingModal = ({
|
|||||||
if (code === 200) {
|
if (code === 200) {
|
||||||
message.success('保存文件成功');
|
message.success('保存文件成功');
|
||||||
handleCancel(data);
|
handleCancel(data);
|
||||||
} else {
|
|
||||||
message.error(data);
|
|
||||||
}
|
}
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -30,8 +30,6 @@ const AppModal = ({
|
|||||||
if (code === 200) {
|
if (code === 200) {
|
||||||
message.success(app ? '更新应用成功' : '新建应用成功');
|
message.success(app ? '更新应用成功' : '新建应用成功');
|
||||||
handleCancel(data);
|
handleCancel(data);
|
||||||
} else {
|
|
||||||
message.error(data);
|
|
||||||
}
|
}
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -17,17 +17,14 @@ const CheckUpdate = ({ socketMessage }: any) => {
|
|||||||
message.loading('检查更新中...', 0);
|
message.loading('检查更新中...', 0);
|
||||||
request
|
request
|
||||||
.put(`${config.apiPrefix}system/update-check`)
|
.put(`${config.apiPrefix}system/update-check`)
|
||||||
.then((_data: any) => {
|
.then(({ code, data }) => {
|
||||||
message.destroy();
|
message.destroy();
|
||||||
const { code, data } = _data;
|
|
||||||
if (code === 200) {
|
if (code === 200) {
|
||||||
if (data.hasNewVersion) {
|
if (data.hasNewVersion) {
|
||||||
showConfirmUpdateModal(data);
|
showConfirmUpdateModal(data);
|
||||||
} else {
|
} else {
|
||||||
showForceUpdateModal();
|
showForceUpdateModal();
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
message.error(data);
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((error: any) => {
|
.catch((error: any) => {
|
||||||
@@ -105,6 +102,7 @@ const CheckUpdate = ({ socketMessage }: any) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const showUpdatingModal = () => {
|
const showUpdatingModal = () => {
|
||||||
|
setValue('');
|
||||||
modalRef.current = Modal.info({
|
modalRef.current = Modal.info({
|
||||||
width: 600,
|
width: 600,
|
||||||
maskClosable: false,
|
maskClosable: false,
|
||||||
@@ -140,7 +138,12 @@ const CheckUpdate = ({ socketMessage }: any) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const newMessage = `${value}${_message}`;
|
const newMessage = `${value}${_message}`;
|
||||||
|
const updateFailed = newMessage.includes('失败,请检查');
|
||||||
|
|
||||||
modalRef.current.update({
|
modalRef.current.update({
|
||||||
|
maskClosable: updateFailed,
|
||||||
|
closable: updateFailed,
|
||||||
|
okButtonProps: { disabled: !updateFailed },
|
||||||
content: (
|
content: (
|
||||||
<div style={{ height: '60vh', overflowY: 'auto' }}>
|
<div style={{ height: '60vh', overflowY: 'auto' }}>
|
||||||
<pre
|
<pre
|
||||||
@@ -157,6 +160,11 @@ const CheckUpdate = ({ socketMessage }: any) => {
|
|||||||
</div>
|
</div>
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (updateFailed && !value.includes('失败,请检查')) {
|
||||||
|
message.error('更新失败,请检查网络及日志或稍后再试');
|
||||||
|
}
|
||||||
|
|
||||||
setValue(newMessage);
|
setValue(newMessage);
|
||||||
|
|
||||||
document.getElementById('log-identifier') &&
|
document.getElementById('log-identifier') &&
|
||||||
|
|||||||
+24
-20
@@ -144,8 +144,10 @@ const Setting = () => {
|
|||||||
setLoading(true);
|
setLoading(true);
|
||||||
request
|
request
|
||||||
.get(`${config.apiPrefix}apps`)
|
.get(`${config.apiPrefix}apps`)
|
||||||
.then((data: any) => {
|
.then(({ code, data }) => {
|
||||||
setDataSource(data.data);
|
if (code === 200) {
|
||||||
|
setDataSource(data);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.finally(() => setLoading(false));
|
.finally(() => setLoading(false));
|
||||||
};
|
};
|
||||||
@@ -175,14 +177,12 @@ const Setting = () => {
|
|||||||
onOk() {
|
onOk() {
|
||||||
request
|
request
|
||||||
.delete(`${config.apiPrefix}apps`, { data: [record.id] })
|
.delete(`${config.apiPrefix}apps`, { data: [record.id] })
|
||||||
.then((data: any) => {
|
.then(({ code, data }) => {
|
||||||
if (data.code === 200) {
|
if (code === 200) {
|
||||||
message.success('删除成功');
|
message.success('删除成功');
|
||||||
const result = [...dataSource];
|
const result = [...dataSource];
|
||||||
result.splice(index, 1);
|
result.splice(index, 1);
|
||||||
setDataSource(result);
|
setDataSource(result);
|
||||||
} else {
|
|
||||||
message.error(data);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -209,12 +209,10 @@ const Setting = () => {
|
|||||||
onOk() {
|
onOk() {
|
||||||
request
|
request
|
||||||
.put(`${config.apiPrefix}apps/${record.id}/reset-secret`)
|
.put(`${config.apiPrefix}apps/${record.id}/reset-secret`)
|
||||||
.then((data: any) => {
|
.then(({ code, data }) => {
|
||||||
if (data.code === 200) {
|
if (code === 200) {
|
||||||
message.success('重置成功');
|
message.success('重置成功');
|
||||||
handleApp(data.data);
|
handleApp(data);
|
||||||
} else {
|
|
||||||
message.error(data);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -247,8 +245,10 @@ const Setting = () => {
|
|||||||
const getLoginLog = () => {
|
const getLoginLog = () => {
|
||||||
request
|
request
|
||||||
.get(`${config.apiPrefix}user/login-log`)
|
.get(`${config.apiPrefix}user/login-log`)
|
||||||
.then((data: any) => {
|
.then(({ code, data }) => {
|
||||||
setLoginLogData(data.data);
|
if (code === 200) {
|
||||||
|
setLoginLogData(data);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch((error: any) => {
|
.catch((error: any) => {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
@@ -271,8 +271,10 @@ const Setting = () => {
|
|||||||
const getNotification = () => {
|
const getNotification = () => {
|
||||||
request
|
request
|
||||||
.get(`${config.apiPrefix}user/notification`)
|
.get(`${config.apiPrefix}user/notification`)
|
||||||
.then((data: any) => {
|
.then(({ code, data }) => {
|
||||||
setNotificationInfo(data.data);
|
if (code === 200) {
|
||||||
|
setNotificationInfo(data);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch((error: any) => {
|
.catch((error: any) => {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
@@ -282,9 +284,9 @@ const Setting = () => {
|
|||||||
const getLogRemoveFrequency = () => {
|
const getLogRemoveFrequency = () => {
|
||||||
request
|
request
|
||||||
.get(`${config.apiPrefix}system/log/remove`)
|
.get(`${config.apiPrefix}system/log/remove`)
|
||||||
.then((data: any) => {
|
.then(({ code, data }) => {
|
||||||
if (data.data.info) {
|
if (code === 200 && data.info) {
|
||||||
const { frequency } = data.data.info;
|
const { frequency } = data.info;
|
||||||
setLogRemoveFrequency(frequency);
|
setLogRemoveFrequency(frequency);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -299,8 +301,10 @@ const Setting = () => {
|
|||||||
.put(`${config.apiPrefix}system/log/remove`, {
|
.put(`${config.apiPrefix}system/log/remove`, {
|
||||||
data: { frequency: logRemoveFrequency },
|
data: { frequency: logRemoveFrequency },
|
||||||
})
|
})
|
||||||
.then((data: any) => {
|
.then(({ code, data }) => {
|
||||||
message.success('更新成功');
|
if (code === 200) {
|
||||||
|
message.success('更新成功');
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch((error: any) => {
|
.catch((error: any) => {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
|
|||||||
@@ -23,11 +23,9 @@ const NotificationSetting = ({ data }: any) => {
|
|||||||
...values,
|
...values,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then((_data: any) => {
|
.then(({ code, data }) => {
|
||||||
if (_data && _data.code === 200) {
|
if (code === 200) {
|
||||||
message.success(values.type ? '通知发送成功' : '通知关闭成功');
|
message.success(values.type ? '通知发送成功' : '通知关闭成功');
|
||||||
} else {
|
|
||||||
message.error(_data.message);
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((error: any) => {
|
.catch((error: any) => {
|
||||||
@@ -75,22 +73,20 @@ const NotificationSetting = ({ data }: any) => {
|
|||||||
rules={[{ required: x.required }]}
|
rules={[{ required: x.required }]}
|
||||||
style={{ maxWidth: 400 }}
|
style={{ maxWidth: 400 }}
|
||||||
>
|
>
|
||||||
{
|
{x.items ? (
|
||||||
x.items ? (
|
<Select placeholder={x.placeholder || `请选择${x.label}`}>
|
||||||
<Select placeholder={x.placeholder || `请选择${x.label}`}>
|
{x.items.map((y) => (
|
||||||
{x.items.map((y) => (
|
<Option key={y.value} value={y.value}>
|
||||||
<Option key={y.value} value={y.value}>
|
{y.label || y.value}
|
||||||
{y.label || y.value}
|
</Option>
|
||||||
</Option>
|
))}
|
||||||
))}
|
</Select>
|
||||||
</Select>
|
) : (
|
||||||
) : (
|
<Input.TextArea
|
||||||
<Input.TextArea
|
autoSize={true}
|
||||||
autoSize={true}
|
placeholder={x.placeholder || `请输入${x.label}`}
|
||||||
placeholder={x.placeholder || `请输入${x.label}`}
|
/>
|
||||||
/>
|
)}
|
||||||
)
|
|
||||||
}
|
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
))}
|
))}
|
||||||
<Button type="primary" htmlType="submit">
|
<Button type="primary" htmlType="submit">
|
||||||
|
|||||||
@@ -27,9 +27,11 @@ const SecuritySettings = ({ user, userChange }: any) => {
|
|||||||
password: values.password,
|
password: values.password,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then((data: any) => {
|
.then(({ code, data }) => {
|
||||||
localStorage.removeItem(config.authKey);
|
if (code === 200) {
|
||||||
history.push('/login');
|
localStorage.removeItem(config.authKey);
|
||||||
|
history.push('/login');
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch((error: any) => {
|
.catch((error: any) => {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
@@ -48,8 +50,8 @@ const SecuritySettings = ({ user, userChange }: any) => {
|
|||||||
const deactiveTowFactor = () => {
|
const deactiveTowFactor = () => {
|
||||||
request
|
request
|
||||||
.put(`${config.apiPrefix}user/two-factor/deactive`)
|
.put(`${config.apiPrefix}user/two-factor/deactive`)
|
||||||
.then((data: any) => {
|
.then(({ code, data }) => {
|
||||||
if (data.data) {
|
if (code === 200 && data) {
|
||||||
setTwoFactorActivated(false);
|
setTwoFactorActivated(false);
|
||||||
userChange();
|
userChange();
|
||||||
}
|
}
|
||||||
@@ -63,14 +65,16 @@ const SecuritySettings = ({ user, userChange }: any) => {
|
|||||||
setLoading(true);
|
setLoading(true);
|
||||||
request
|
request
|
||||||
.put(`${config.apiPrefix}user/two-factor/active`, { data: { code } })
|
.put(`${config.apiPrefix}user/two-factor/active`, { data: { code } })
|
||||||
.then((data: any) => {
|
.then(({ code, data }) => {
|
||||||
if (data.data) {
|
if (code === 200) {
|
||||||
message.success('激活成功');
|
if (data) {
|
||||||
setTwoFactoring(false);
|
message.success('激活成功');
|
||||||
setTwoFactorActivated(true);
|
setTwoFactoring(false);
|
||||||
userChange();
|
setTwoFactorActivated(true);
|
||||||
} else {
|
userChange();
|
||||||
message.success('验证失败');
|
} else {
|
||||||
|
message.success('验证失败');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((error: any) => {
|
.catch((error: any) => {
|
||||||
@@ -82,8 +86,10 @@ const SecuritySettings = ({ user, userChange }: any) => {
|
|||||||
const getTwoFactorInfo = () => {
|
const getTwoFactorInfo = () => {
|
||||||
request
|
request
|
||||||
.get(`${config.apiPrefix}user/two-factor/init`)
|
.get(`${config.apiPrefix}user/two-factor/init`)
|
||||||
.then((data: any) => {
|
.then(({ code, data }) => {
|
||||||
setTwoFactorInfo(data.data);
|
if (code === 200) {
|
||||||
|
setTwoFactorInfo(data);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch((error: any) => {
|
.catch((error: any) => {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
|
|||||||
@@ -263,8 +263,8 @@ const Subscription = () => {
|
|||||||
onOk() {
|
onOk() {
|
||||||
request
|
request
|
||||||
.put(`${config.apiPrefix}subscriptions/run`, { data: [record.id] })
|
.put(`${config.apiPrefix}subscriptions/run`, { data: [record.id] })
|
||||||
.then((data: any) => {
|
.then(({ code, data }) => {
|
||||||
if (data.code === 200) {
|
if (code === 200) {
|
||||||
const result = [...value];
|
const result = [...value];
|
||||||
const i = result.findIndex((x) => x.id === record.id);
|
const i = result.findIndex((x) => x.id === record.id);
|
||||||
if (i !== -1) {
|
if (i !== -1) {
|
||||||
@@ -274,8 +274,6 @@ const Subscription = () => {
|
|||||||
});
|
});
|
||||||
setValue(result);
|
setValue(result);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
message.error(data);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -300,8 +298,8 @@ const Subscription = () => {
|
|||||||
onOk() {
|
onOk() {
|
||||||
request
|
request
|
||||||
.put(`${config.apiPrefix}subscriptions/stop`, { data: [record.id] })
|
.put(`${config.apiPrefix}subscriptions/stop`, { data: [record.id] })
|
||||||
.then((data: any) => {
|
.then(({ code, data }) => {
|
||||||
if (data.code === 200) {
|
if (code === 200) {
|
||||||
const result = [...value];
|
const result = [...value];
|
||||||
const i = result.findIndex((x) => x.id === record.id);
|
const i = result.findIndex((x) => x.id === record.id);
|
||||||
if (i !== -1) {
|
if (i !== -1) {
|
||||||
@@ -312,8 +310,6 @@ const Subscription = () => {
|
|||||||
});
|
});
|
||||||
setValue(result);
|
setValue(result);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
message.error(data);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -327,9 +323,11 @@ const Subscription = () => {
|
|||||||
setLoading(true);
|
setLoading(true);
|
||||||
request
|
request
|
||||||
.get(`${config.apiPrefix}subscriptions?searchValue=${searchText}`)
|
.get(`${config.apiPrefix}subscriptions?searchValue=${searchText}`)
|
||||||
.then((data: any) => {
|
.then(({ code, data }) => {
|
||||||
setValue(data.data);
|
if (code === 200) {
|
||||||
setCurrentPage(1);
|
setValue(data);
|
||||||
|
setCurrentPage(1);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.finally(() => setLoading(false));
|
.finally(() => setLoading(false));
|
||||||
};
|
};
|
||||||
@@ -359,8 +357,8 @@ const Subscription = () => {
|
|||||||
onOk() {
|
onOk() {
|
||||||
request
|
request
|
||||||
.delete(`${config.apiPrefix}subscriptions`, { data: [record.id] })
|
.delete(`${config.apiPrefix}subscriptions`, { data: [record.id] })
|
||||||
.then((data: any) => {
|
.then(({ code, data }) => {
|
||||||
if (data.code === 200) {
|
if (code === 200) {
|
||||||
message.success('删除成功');
|
message.success('删除成功');
|
||||||
const result = [...value];
|
const result = [...value];
|
||||||
const i = result.findIndex((x) => x.id === record.id);
|
const i = result.findIndex((x) => x.id === record.id);
|
||||||
@@ -368,8 +366,6 @@ const Subscription = () => {
|
|||||||
result.splice(i, 1);
|
result.splice(i, 1);
|
||||||
setValue(result);
|
setValue(result);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
message.error(data);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -402,8 +398,8 @@ const Subscription = () => {
|
|||||||
data: [record.id],
|
data: [record.id],
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.then((data: any) => {
|
.then(({ code, data }) => {
|
||||||
if (data.code === 200) {
|
if (code === 200) {
|
||||||
const newStatus = record.is_disabled === 1 ? 0 : 1;
|
const newStatus = record.is_disabled === 1 ? 0 : 1;
|
||||||
const result = [...value];
|
const result = [...value];
|
||||||
const i = result.findIndex((x) => x.id === record.id);
|
const i = result.findIndex((x) => x.id === record.id);
|
||||||
@@ -414,8 +410,6 @@ const Subscription = () => {
|
|||||||
});
|
});
|
||||||
setValue(result);
|
setValue(result);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
message.error(data);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -36,11 +36,12 @@ const SubscriptionLogModal = ({
|
|||||||
? logUrl
|
? logUrl
|
||||||
: `${config.apiPrefix}subscriptions/${subscription.id}/log`,
|
: `${config.apiPrefix}subscriptions/${subscription.id}/log`,
|
||||||
)
|
)
|
||||||
.then((data: any) => {
|
.then(({ code, data }) => {
|
||||||
if (
|
if (
|
||||||
|
code === 200 &&
|
||||||
localStorage.getItem('logSubscription') === String(subscription.id)
|
localStorage.getItem('logSubscription') === String(subscription.id)
|
||||||
) {
|
) {
|
||||||
const log = data.data as string;
|
const log = data as string;
|
||||||
setValue(log || '暂无日志');
|
setValue(log || '暂无日志');
|
||||||
setExecuting(log && !log.includes('执行结束'));
|
setExecuting(log && !log.includes('执行结束'));
|
||||||
if (log && !log.includes('执行结束')) {
|
if (log && !log.includes('执行结束')) {
|
||||||
|
|||||||
@@ -40,8 +40,6 @@ const SubscriptionModal = ({
|
|||||||
if (code === 200) {
|
if (code === 200) {
|
||||||
message.success(subscription ? '更新订阅成功' : '新建订阅成功');
|
message.success(subscription ? '更新订阅成功' : '新建订阅成功');
|
||||||
handleCancel(data);
|
handleCancel(data);
|
||||||
} else {
|
|
||||||
message.error(data);
|
|
||||||
}
|
}
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
@@ -190,8 +188,8 @@ const SubscriptionModal = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const onPaste = useCallback((e: any) => {
|
const onPaste = useCallback((e: any) => {
|
||||||
const text = e.clipboardData.getData('text');
|
const text = e.clipboardData.getData('text') as string;
|
||||||
if (!subscription && text.includes('ql ')) {
|
if (text.startsWith('ql ')) {
|
||||||
const [
|
const [
|
||||||
,
|
,
|
||||||
type,
|
type,
|
||||||
@@ -225,6 +223,13 @@ const SubscriptionModal = ({
|
|||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const onNamePaste = useCallback((e) => {
|
||||||
|
const text = e.clipboardData.getData('text') as string;
|
||||||
|
if (text.startsWith('ql ')) {
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (visible) {
|
if (visible) {
|
||||||
window.addEventListener('paste', onPaste);
|
window.addEventListener('paste', onPaste);
|
||||||
@@ -243,35 +248,9 @@ const SubscriptionModal = ({
|
|||||||
}
|
}
|
||||||
}, [subscription, visible]);
|
}, [subscription, visible]);
|
||||||
|
|
||||||
const isFirefox = navigator.userAgent.includes('Firefox');
|
|
||||||
const isSafari =
|
|
||||||
navigator.userAgent.includes('Safari') &&
|
|
||||||
!navigator.userAgent.includes('Chrome');
|
|
||||||
const isQQBrowser = navigator.userAgent.includes('QQBrowser');
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
title={
|
title={subscription ? '编辑订阅' : '新建订阅'}
|
||||||
subscription ? (
|
|
||||||
'编辑订阅'
|
|
||||||
) : (
|
|
||||||
<span>
|
|
||||||
新建订阅
|
|
||||||
<small
|
|
||||||
style={{
|
|
||||||
color: '#999',
|
|
||||||
fontWeight: 400,
|
|
||||||
fontSize: isFirefox ? 9 : 12,
|
|
||||||
marginLeft: 2,
|
|
||||||
zoom: isSafari ? 0.66 : 0.8,
|
|
||||||
letterSpacing: isQQBrowser ? -2 : 0,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
支持repo/raw命令,粘贴导入
|
|
||||||
</small>
|
|
||||||
</span>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
open={visible}
|
open={visible}
|
||||||
forceRender
|
forceRender
|
||||||
centered
|
centered
|
||||||
@@ -291,7 +270,10 @@ const SubscriptionModal = ({
|
|||||||
>
|
>
|
||||||
<Form form={form} name="form_in_modal" layout="vertical">
|
<Form form={form} name="form_in_modal" layout="vertical">
|
||||||
<Form.Item name="name" label="名称">
|
<Form.Item name="name" label="名称">
|
||||||
<Input placeholder="请输入订阅名" />
|
<Input
|
||||||
|
placeholder="支持拷贝ql repo/raw命令,粘贴导入"
|
||||||
|
onPaste={onNamePaste}
|
||||||
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item
|
<Form.Item
|
||||||
name="type"
|
name="type"
|
||||||
|
|||||||
+3
-3
@@ -56,7 +56,7 @@ export default {
|
|||||||
value: 'scripts',
|
value: 'scripts',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: '任务日志',
|
name: '日志管理',
|
||||||
value: 'logs',
|
value: 'logs',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -74,7 +74,7 @@ export default {
|
|||||||
subscriptions: '订阅管理',
|
subscriptions: '订阅管理',
|
||||||
configs: '配置文件',
|
configs: '配置文件',
|
||||||
scripts: '脚本管理',
|
scripts: '脚本管理',
|
||||||
logs: '任务日志',
|
logs: '日志管理',
|
||||||
dependencies: '依赖管理',
|
dependencies: '依赖管理',
|
||||||
system: '系统信息',
|
system: '系统信息',
|
||||||
},
|
},
|
||||||
@@ -263,7 +263,7 @@ export default {
|
|||||||
'/config': '配置文件',
|
'/config': '配置文件',
|
||||||
'/script': '脚本管理',
|
'/script': '脚本管理',
|
||||||
'/diff': '对比工具',
|
'/diff': '对比工具',
|
||||||
'/log': '任务日志',
|
'/log': '日志管理',
|
||||||
'/setting': '系统设置',
|
'/setting': '系统设置',
|
||||||
'/error': '错误日志',
|
'/error': '错误日志',
|
||||||
},
|
},
|
||||||
|
|||||||
+17
-1
@@ -54,7 +54,23 @@ _request.interceptors.request.use((url, options) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
_request.interceptors.response.use(async (response) => {
|
_request.interceptors.response.use(async (response) => {
|
||||||
const res = await response.clone();
|
const responseStatus = response.status;
|
||||||
|
if ([502, 504].includes(responseStatus)) {
|
||||||
|
message.error('服务异常,请稍后刷新!');
|
||||||
|
history.push('/error');
|
||||||
|
} else if (responseStatus === 401) {
|
||||||
|
if (history.location.pathname !== '/login') {
|
||||||
|
localStorage.removeItem(config.authKey);
|
||||||
|
history.push('/login');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const res = await response.clone().json();
|
||||||
|
if (res.code !== 200) {
|
||||||
|
const msg = res.message || res.data;
|
||||||
|
msg && message.error(msg);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
return response;
|
return response;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+6
-1
@@ -244,7 +244,7 @@ export function exportJson(name: string, data: string) {
|
|||||||
|
|
||||||
export function depthFirstSearch<
|
export function depthFirstSearch<
|
||||||
T extends Record<string, any> & { children?: T[] },
|
T extends Record<string, any> & { children?: T[] },
|
||||||
>(children: T[], condition: (column: T) => boolean, item: T) {
|
>(children: T[], condition: (column: T) => boolean, item?: T) {
|
||||||
const c = [...children];
|
const c = [...children];
|
||||||
const keys = [];
|
const keys = [];
|
||||||
|
|
||||||
@@ -252,6 +252,11 @@ export function depthFirstSearch<
|
|||||||
if (!cls) return;
|
if (!cls) return;
|
||||||
for (let i = 0; i < cls?.length; i++) {
|
for (let i = 0; i < cls?.length; i++) {
|
||||||
if (condition(cls[i])) {
|
if (condition(cls[i])) {
|
||||||
|
if (!item) {
|
||||||
|
cls.splice(i, 1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (cls[i].children) {
|
if (cls[i].children) {
|
||||||
cls[i].children!.unshift(item);
|
cls[i].children!.unshift(item);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+7
-7
@@ -1,8 +1,8 @@
|
|||||||
export const version = '2.14.4';
|
export const version = '2.14.6';
|
||||||
export const changeLogLink = 'https://t.me/jiao_long/331';
|
export const changeLogLink = 'https://t.me/jiao_long/333';
|
||||||
export const changeLog = `2.14.4 版本说明
|
export const changeLog = `2.14.6 版本说明
|
||||||
1. 通知设置新增自定义通知
|
1. 任务执行日志增加资源占用说明
|
||||||
2. 脚本管理支持新建文件夹
|
2. 配置文件config.sh增加资源配置参数CpuWarn/MemoryWarn/DiskWarn
|
||||||
3. 依赖管理增加批量重新安装
|
3. 修复脚本管理和日志管理搜索
|
||||||
4. 修复创建应用错误
|
4. 其他bug修复
|
||||||
`;
|
`;
|
||||||
|
|||||||
Reference in New Issue
Block a user