mirror of
https://github.com/whyour/qinglong.git
synced 2026-08-12 19:30:48 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ac6de4911a | ||
|
|
1628e05ece | ||
|
|
7b7e03b503 | ||
|
|
8d14c9dae1 | ||
|
|
4d6d0a55e7 | ||
|
|
8ab2dc3280 | ||
|
|
3f54048127 | ||
|
|
47c2c61f33 | ||
|
|
47d2fc24bc | ||
|
|
7a8a8ab9b3 | ||
|
|
2ac4581d54 | ||
|
|
68ad01e0e8 | ||
|
|
cdeca4b808 | ||
|
|
55945e4cd1 | ||
|
|
b39036f8f8 | ||
|
|
f07093d29f | ||
|
|
11c789c71c | ||
|
|
81898f9dd7 | ||
|
|
6dba8ae72d | ||
|
|
c47896e787 | ||
|
|
14cb1f7788 |
@@ -1,3 +1,4 @@
|
|||||||
|
UPDATE_PORT=5300
|
||||||
PUBLIC_PORT=5400
|
PUBLIC_PORT=5400
|
||||||
CRON_PORT=5500
|
CRON_PORT=5500
|
||||||
BACK_PORT=5600
|
BACK_PORT=5600
|
||||||
|
|||||||
@@ -16,6 +16,11 @@ export default defineConfig({
|
|||||||
favicons: [`https://qn.whyour.cn/favicon.svg`],
|
favicons: [`https://qn.whyour.cn/favicon.svg`],
|
||||||
publicPath: process.env.NODE_ENV === 'production' ? './' : '/',
|
publicPath: process.env.NODE_ENV === 'production' ? './' : '/',
|
||||||
proxy: {
|
proxy: {
|
||||||
|
[`${baseUrl}api/update`]: {
|
||||||
|
target: 'http://127.0.0.1:5300/',
|
||||||
|
changeOrigin: true,
|
||||||
|
pathRewrite: { [`^${baseUrl}api/update`]: '/api' },
|
||||||
|
},
|
||||||
[`${baseUrl}api/public`]: {
|
[`${baseUrl}api/public`]: {
|
||||||
target: 'http://127.0.0.1:5400/',
|
target: 'http://127.0.0.1:5400/',
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
|
|||||||
@@ -134,4 +134,20 @@ export default (app: Router) => {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
route.put(
|
||||||
|
'/cancel',
|
||||||
|
celebrate({
|
||||||
|
body: Joi.array().items(Joi.number().required()),
|
||||||
|
}),
|
||||||
|
async (req: Request, res: Response, next: NextFunction) => {
|
||||||
|
try {
|
||||||
|
const dependenceService = Container.get(DependenceService);
|
||||||
|
await dependenceService.cancel(req.body);
|
||||||
|
return res.send({ code: 200 });
|
||||||
|
} catch (e) {
|
||||||
|
return next(e);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ export default {
|
|||||||
port: parseInt(process.env.BACK_PORT as string, 10),
|
port: parseInt(process.env.BACK_PORT as string, 10),
|
||||||
cronPort: parseInt(process.env.CRON_PORT as string, 10),
|
cronPort: parseInt(process.env.CRON_PORT as string, 10),
|
||||||
publicPort: parseInt(process.env.PUBLIC_PORT as string, 10),
|
publicPort: parseInt(process.env.PUBLIC_PORT as string, 10),
|
||||||
|
updatePort: parseInt(process.env.UPDATE_PORT as string, 10),
|
||||||
secret: process.env.SECRET || createRandomString(16, 32),
|
secret: process.env.SECRET || createRandomString(16, 32),
|
||||||
logs: {
|
logs: {
|
||||||
level: process.env.LOG_LEVEL || 'silly',
|
level: process.env.LOG_LEVEL || 'silly',
|
||||||
|
|||||||
+33
-24
@@ -360,6 +360,35 @@ export function parseHeaders(headers: string) {
|
|||||||
return parsed;
|
return parsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function parseString(
|
||||||
|
input: string,
|
||||||
|
valueFormatFn?: (v: string) => string,
|
||||||
|
): Record<string, string> {
|
||||||
|
const regex = /(\w+):\s*((?:(?!\n\w+:).)*)/g;
|
||||||
|
const matches: Record<string, string> = {};
|
||||||
|
|
||||||
|
let match;
|
||||||
|
while ((match = regex.exec(input)) !== null) {
|
||||||
|
const [, key, value] = match;
|
||||||
|
const _key = key.trim();
|
||||||
|
if (!_key || matches[_key]) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let _value = value.trim();
|
||||||
|
|
||||||
|
try {
|
||||||
|
_value = valueFormatFn ? valueFormatFn(_value) : _value;
|
||||||
|
const jsonValue = JSON.parse(_value);
|
||||||
|
matches[_key] = jsonValue;
|
||||||
|
} catch (error) {
|
||||||
|
matches[_key] = _value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return matches;
|
||||||
|
}
|
||||||
|
|
||||||
export function parseBody(
|
export function parseBody(
|
||||||
body: string,
|
body: string,
|
||||||
contentType:
|
contentType:
|
||||||
@@ -367,33 +396,13 @@ export function parseBody(
|
|||||||
| 'multipart/form-data'
|
| 'multipart/form-data'
|
||||||
| 'application/x-www-form-urlencoded'
|
| 'application/x-www-form-urlencoded'
|
||||||
| 'text/plain',
|
| 'text/plain',
|
||||||
|
valueFormatFn?: (v: string) => string,
|
||||||
) {
|
) {
|
||||||
if (contentType === 'text/plain' || !body) {
|
if (contentType === 'text/plain' || !body) {
|
||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
const parsed: any = {};
|
const parsed = parseString(body, valueFormatFn);
|
||||||
let key;
|
|
||||||
let val;
|
|
||||||
let i;
|
|
||||||
|
|
||||||
body &&
|
|
||||||
body.split('\n').forEach(function parser(line) {
|
|
||||||
i = line.indexOf(':');
|
|
||||||
key = line.substring(0, i).trim();
|
|
||||||
val = line.substring(i + 1).trim();
|
|
||||||
|
|
||||||
if (!key || parsed[key]) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const jsonValue = JSON.parse(val);
|
|
||||||
parsed[key] = jsonValue;
|
|
||||||
} catch (error) {
|
|
||||||
parsed[key] = val;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
switch (contentType) {
|
switch (contentType) {
|
||||||
case 'multipart/form-data':
|
case 'multipart/form-data':
|
||||||
@@ -435,8 +444,8 @@ export async function killTask(pid: number) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getPid(name: string) {
|
export async function getPid(cmd: string) {
|
||||||
const taskCommand = `ps -eo pid,command | grep "${name}" | grep -v grep | awk '{print $1}' | head -1 | xargs echo -n`;
|
const taskCommand = `ps -eo pid,command | grep "${cmd}" | grep -v grep | awk '{print $1}' | head -1 | xargs echo -n`;
|
||||||
const pid = await promiseExec(taskCommand);
|
const pid = await promiseExec(taskCommand);
|
||||||
return pid ? Number(pid) : undefined;
|
return pid ? Number(pid) : undefined;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ export enum DependenceStatus {
|
|||||||
'removed',
|
'removed',
|
||||||
'removeFailed',
|
'removeFailed',
|
||||||
'queued',
|
'queued',
|
||||||
|
'cancelled',
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum DependenceTypes {
|
export enum DependenceTypes {
|
||||||
|
|||||||
@@ -5,28 +5,6 @@ import Sock from './sock';
|
|||||||
export default async ({ server }: { server: Server }) => {
|
export default async ({ server }: { server: Server }) => {
|
||||||
await Sock({ server });
|
await Sock({ server });
|
||||||
Logger.info('✌️ Sock loaded');
|
Logger.info('✌️ Sock loaded');
|
||||||
let exitTime = 0;
|
|
||||||
let timer: NodeJS.Timeout;
|
|
||||||
|
|
||||||
process.on('SIGINT', (singal) => {
|
|
||||||
Logger.warn(`Server need close, singal ${singal}`);
|
|
||||||
console.warn(`Server need close, singal ${singal}`);
|
|
||||||
exitTime++;
|
|
||||||
if (exitTime >= 3) {
|
|
||||||
Logger.warn('Forcing server close');
|
|
||||||
console.warn('Forcing server close');
|
|
||||||
clearTimeout(timer);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
server.close(() => {
|
|
||||||
if (timer) {
|
|
||||||
clearTimeout(timer);
|
|
||||||
}
|
|
||||||
timer = setTimeout(() => {
|
|
||||||
process.exit();
|
|
||||||
}, 15000);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
process.on('uncaughtException', (error) => {
|
process.on('uncaughtException', (error) => {
|
||||||
Logger.error('Uncaught exception:', error);
|
Logger.error('Uncaught exception:', error);
|
||||||
|
|||||||
@@ -0,0 +1,106 @@
|
|||||||
|
import bodyParser from 'body-parser';
|
||||||
|
import { errors } from 'celebrate';
|
||||||
|
import cors from 'cors';
|
||||||
|
import { Application, NextFunction, Request, Response } from 'express';
|
||||||
|
import jwt from 'express-jwt';
|
||||||
|
import Container from 'typedi';
|
||||||
|
import config from '../config';
|
||||||
|
import SystemService from '../services/system';
|
||||||
|
import Logger from './logger';
|
||||||
|
|
||||||
|
export default ({ app }: { app: Application }) => {
|
||||||
|
app.set('trust proxy', 'loopback');
|
||||||
|
app.use(cors());
|
||||||
|
|
||||||
|
app.use(bodyParser.json({ limit: '50mb' }));
|
||||||
|
app.use(bodyParser.urlencoded({ limit: '50mb', extended: true }));
|
||||||
|
|
||||||
|
app.use(
|
||||||
|
jwt({
|
||||||
|
secret: config.secret,
|
||||||
|
algorithms: ['HS384'],
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
app.put(
|
||||||
|
'/api/reload',
|
||||||
|
async (req: Request, res: Response, next: NextFunction) => {
|
||||||
|
try {
|
||||||
|
const systemService = Container.get(SystemService);
|
||||||
|
const result = await systemService.reloadSystem();
|
||||||
|
res.send(result);
|
||||||
|
} catch (e) {
|
||||||
|
Logger.error('🔥 error: %o', e);
|
||||||
|
return next(e);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
app.put(
|
||||||
|
'/api/system',
|
||||||
|
async (req: Request, res: Response, next: NextFunction) => {
|
||||||
|
try {
|
||||||
|
const systemService = Container.get(SystemService);
|
||||||
|
const result = await systemService.reloadSystem('system');
|
||||||
|
res.send(result);
|
||||||
|
} catch (e) {
|
||||||
|
Logger.error('🔥 error: %o', e);
|
||||||
|
return next(e);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
app.put(
|
||||||
|
'/api/data',
|
||||||
|
async (req: Request, res: Response, next: NextFunction) => {
|
||||||
|
try {
|
||||||
|
const systemService = Container.get(SystemService);
|
||||||
|
const result = await systemService.reloadSystem('data');
|
||||||
|
res.send(result);
|
||||||
|
} catch (e) {
|
||||||
|
Logger.error('🔥 error: %o', e);
|
||||||
|
return next(e);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
app.use((req, res, next) => {
|
||||||
|
const err: any = new Error('Not Found');
|
||||||
|
err['status'] = 404;
|
||||||
|
next(err);
|
||||||
|
});
|
||||||
|
|
||||||
|
app.use(errors());
|
||||||
|
|
||||||
|
app.use(
|
||||||
|
(
|
||||||
|
err: Error & { status: number },
|
||||||
|
req: Request,
|
||||||
|
res: Response,
|
||||||
|
next: NextFunction,
|
||||||
|
) => {
|
||||||
|
if (err.name === 'UnauthorizedError') {
|
||||||
|
return res
|
||||||
|
.status(err.status)
|
||||||
|
.send({ code: 401, message: err.message })
|
||||||
|
.end();
|
||||||
|
}
|
||||||
|
return next(err);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
app.use(
|
||||||
|
(
|
||||||
|
err: Error & { status: number },
|
||||||
|
req: Request,
|
||||||
|
res: Response,
|
||||||
|
next: NextFunction,
|
||||||
|
) => {
|
||||||
|
res.status(err.status || 500);
|
||||||
|
res.json({
|
||||||
|
code: err.status || 500,
|
||||||
|
message: err.message,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -14,7 +14,12 @@ import {
|
|||||||
import { spawn } from 'cross-spawn';
|
import { spawn } from 'cross-spawn';
|
||||||
import SockService from './sock';
|
import SockService from './sock';
|
||||||
import { FindOptions, Op } from 'sequelize';
|
import { FindOptions, Op } from 'sequelize';
|
||||||
import { fileExist, promiseExecSuccess } from '../config/util';
|
import {
|
||||||
|
fileExist,
|
||||||
|
getPid,
|
||||||
|
killTask,
|
||||||
|
promiseExecSuccess,
|
||||||
|
} from '../config/util';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
import taskLimit from '../shared/pLimit';
|
import taskLimit from '../shared/pLimit';
|
||||||
|
|
||||||
@@ -86,11 +91,21 @@ export default class DependenceService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async dependencies(
|
public async dependencies(
|
||||||
{ searchValue, type }: { searchValue: string; type: string },
|
{
|
||||||
sort: any = { position: -1 },
|
searchValue,
|
||||||
|
type,
|
||||||
|
status,
|
||||||
|
}: { searchValue: string; type: string; status: string },
|
||||||
|
sort: any = [],
|
||||||
query: any = {},
|
query: any = {},
|
||||||
): Promise<Dependence[]> {
|
): Promise<Dependence[]> {
|
||||||
let condition = { ...query, type: DependenceTypes[type as any] };
|
let condition = {
|
||||||
|
...query,
|
||||||
|
type: DependenceTypes[type as any],
|
||||||
|
};
|
||||||
|
if (status) {
|
||||||
|
condition.status = status.split(',').map(Number);
|
||||||
|
}
|
||||||
if (searchValue) {
|
if (searchValue) {
|
||||||
const encodeText = encodeURI(searchValue);
|
const encodeText = encodeURI(searchValue);
|
||||||
const reg = {
|
const reg = {
|
||||||
@@ -106,7 +121,7 @@ export default class DependenceService {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const result = await this.find(condition);
|
const result = await this.find(condition, sort);
|
||||||
return result as any;
|
return result as any;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw error;
|
throw error;
|
||||||
@@ -134,6 +149,28 @@ export default class DependenceService {
|
|||||||
return docs;
|
return docs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async cancel(ids: number[]) {
|
||||||
|
const docs = await DependenceModel.findAll({ where: { id: ids } });
|
||||||
|
for (const doc of docs) {
|
||||||
|
taskLimit.removeQueuedDependency(doc);
|
||||||
|
const depInstallCommand = InstallDependenceCommandTypes[doc.type];
|
||||||
|
const depUnInstallCommand = unInstallDependenceCommandTypes[doc.type];
|
||||||
|
const installCmd = `${depInstallCommand} ${doc.name.trim()}`;
|
||||||
|
const unInstallCmd = `${depUnInstallCommand} ${doc.name.trim()}`;
|
||||||
|
const pids = await Promise.all([
|
||||||
|
getPid(installCmd),
|
||||||
|
getPid(unInstallCmd),
|
||||||
|
]);
|
||||||
|
for (const pid of pids) {
|
||||||
|
pid && (await killTask(pid));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await DependenceModel.update(
|
||||||
|
{ status: DependenceStatus.cancelled },
|
||||||
|
{ where: { id: ids } },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
private async find(query: any, sort: any = []): Promise<Dependence[]> {
|
private async find(query: any, sort: any = []): Promise<Dependence[]> {
|
||||||
const docs = await DependenceModel.findAll({
|
const docs = await DependenceModel.findAll({
|
||||||
where: { ...query },
|
where: { ...query },
|
||||||
@@ -168,8 +205,14 @@ export default class DependenceService {
|
|||||||
isInstall: boolean = true,
|
isInstall: boolean = true,
|
||||||
force: boolean = false,
|
force: boolean = false,
|
||||||
) {
|
) {
|
||||||
return taskLimit.runOneByOne(() => {
|
return taskLimit.runDependeny(dependency, () => {
|
||||||
return new Promise(async (resolve) => {
|
return new Promise(async (resolve) => {
|
||||||
|
if (taskLimit.firstDependencyId !== dependency.id) {
|
||||||
|
return resolve(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
taskLimit.removeQueuedDependency(dependency);
|
||||||
|
|
||||||
const depIds = [dependency.id!];
|
const depIds = [dependency.id!];
|
||||||
const status = isInstall
|
const status = isInstall
|
||||||
? DependenceStatus.installing
|
? DependenceStatus.installing
|
||||||
@@ -317,7 +360,17 @@ export default class DependenceService {
|
|||||||
? DependenceStatus.installFailed
|
? DependenceStatus.installFailed
|
||||||
: DependenceStatus.removeFailed;
|
: DependenceStatus.removeFailed;
|
||||||
}
|
}
|
||||||
await DependenceModel.update({ status }, { where: { id: depIds } });
|
const docs = await DependenceModel.findAll({ where: { id: depIds } });
|
||||||
|
const _docIds = docs
|
||||||
|
.filter((x) => x.status !== DependenceStatus.cancelled)
|
||||||
|
.map((x) => x.id!);
|
||||||
|
|
||||||
|
if (_docIds.length > 0) {
|
||||||
|
await DependenceModel.update(
|
||||||
|
{ status },
|
||||||
|
{ where: { id: _docIds } },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// 如果删除依赖成功或者强制删除
|
// 如果删除依赖成功或者强制删除
|
||||||
if ((isSucceed || force) && !isInstall) {
|
if ((isSucceed || force) && !isInstall) {
|
||||||
|
|||||||
+7
-22
@@ -656,17 +656,14 @@ export default class NotificationService {
|
|||||||
webhookContentType,
|
webhookContentType,
|
||||||
} = this.params;
|
} = this.params;
|
||||||
|
|
||||||
const { formatBody, formatUrl } = this.formatNotifyContent(
|
if (!webhookUrl.includes('$title') && !webhookBody.includes('$title')) {
|
||||||
webhookUrl,
|
|
||||||
webhookBody,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!formatUrl && !formatBody) {
|
|
||||||
throw new Error('Url 或者 Body 中必须包含 $title');
|
throw new Error('Url 或者 Body 中必须包含 $title');
|
||||||
}
|
}
|
||||||
|
|
||||||
const headers = parseHeaders(webhookHeaders);
|
const headers = parseHeaders(webhookHeaders);
|
||||||
const body = parseBody(formatBody, webhookContentType);
|
const body = parseBody(webhookBody, webhookContentType, (v) =>
|
||||||
|
v?.replaceAll('$title', this.title)?.replaceAll('$content', this.content),
|
||||||
|
);
|
||||||
const bodyParam = this.formatBody(webhookContentType, body);
|
const bodyParam = this.formatBody(webhookContentType, body);
|
||||||
const options = {
|
const options = {
|
||||||
method: webhookMethod,
|
method: webhookMethod,
|
||||||
@@ -676,6 +673,9 @@ export default class NotificationService {
|
|||||||
...bodyParam,
|
...bodyParam,
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
|
const formatUrl = webhookUrl
|
||||||
|
?.replaceAll('$title', encodeURIComponent(this.title))
|
||||||
|
?.replaceAll('$content', encodeURIComponent(this.content));
|
||||||
const res = await got(formatUrl, options);
|
const res = await got(formatUrl, options);
|
||||||
if (String(res.statusCode).startsWith('20')) {
|
if (String(res.statusCode).startsWith('20')) {
|
||||||
return true;
|
return true;
|
||||||
@@ -700,19 +700,4 @@ export default class NotificationService {
|
|||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
private formatNotifyContent(url: string, body: string) {
|
|
||||||
if (!url.includes('$title') && !body.includes('$title')) {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
formatUrl: url
|
|
||||||
?.replaceAll('$title', encodeURIComponent(this.title))
|
|
||||||
?.replaceAll('$content', encodeURIComponent(this.content)),
|
|
||||||
formatBody: body
|
|
||||||
?.replaceAll('$title', this.title)
|
|
||||||
?.replaceAll('$content', this.content),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+34
-50
@@ -1,20 +1,13 @@
|
|||||||
|
import { spawn } from 'cross-spawn';
|
||||||
import { Response } from 'express';
|
import { Response } from 'express';
|
||||||
import { Service, Inject } from 'typedi';
|
import fs from 'fs';
|
||||||
|
import got from 'got';
|
||||||
|
import sum from 'lodash/sum';
|
||||||
|
import path from 'path';
|
||||||
|
import { Inject, Service } from 'typedi';
|
||||||
import winston from 'winston';
|
import winston from 'winston';
|
||||||
import config from '../config';
|
import config from '../config';
|
||||||
import {
|
import { TASK_COMMAND } from '../config/const';
|
||||||
AuthDataType,
|
|
||||||
AuthInfo,
|
|
||||||
SystemInstance,
|
|
||||||
SystemModel,
|
|
||||||
SystemModelInfo,
|
|
||||||
} from '../data/system';
|
|
||||||
import { NotificationInfo } from '../data/notify';
|
|
||||||
import NotificationService from './notify';
|
|
||||||
import ScheduleService, { TaskCallbacks } from './schedule';
|
|
||||||
import { spawn } from 'cross-spawn';
|
|
||||||
import SockService from './sock';
|
|
||||||
import got from 'got';
|
|
||||||
import {
|
import {
|
||||||
getPid,
|
getPid,
|
||||||
killTask,
|
killTask,
|
||||||
@@ -23,13 +16,23 @@ import {
|
|||||||
promiseExec,
|
promiseExec,
|
||||||
readDirs,
|
readDirs,
|
||||||
} from '../config/util';
|
} from '../config/util';
|
||||||
import { TASK_COMMAND } from '../config/const';
|
import {
|
||||||
|
DependenceModel,
|
||||||
|
DependenceStatus,
|
||||||
|
DependenceTypes,
|
||||||
|
} from '../data/dependence';
|
||||||
|
import { NotificationInfo } from '../data/notify';
|
||||||
|
import {
|
||||||
|
AuthDataType,
|
||||||
|
AuthInfo,
|
||||||
|
SystemInstance,
|
||||||
|
SystemModel,
|
||||||
|
SystemModelInfo,
|
||||||
|
} from '../data/system';
|
||||||
import taskLimit from '../shared/pLimit';
|
import taskLimit from '../shared/pLimit';
|
||||||
import tar from 'tar';
|
import NotificationService from './notify';
|
||||||
import path from 'path';
|
import ScheduleService, { TaskCallbacks } from './schedule';
|
||||||
import fs from 'fs';
|
import SockService from './sock';
|
||||||
import sum from 'lodash/sum';
|
|
||||||
import { DependenceModel, DependenceStatus, DependenceTypes } from '../data/dependence';
|
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class SystemService {
|
export default class SystemService {
|
||||||
@@ -139,7 +142,10 @@ export default class SystemService {
|
|||||||
}
|
}
|
||||||
let command = `cd && ${cmd}`;
|
let command = `cd && ${cmd}`;
|
||||||
const docs = await DependenceModel.findAll({
|
const docs = await DependenceModel.findAll({
|
||||||
where: { type: DependenceTypes.nodejs, status: DependenceStatus.installed },
|
where: {
|
||||||
|
type: DependenceTypes.nodejs,
|
||||||
|
status: DependenceStatus.installed,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
if (docs.length > 0) {
|
if (docs.length > 0) {
|
||||||
command += ` && pnpm i -g`;
|
command += ` && pnpm i -g`;
|
||||||
@@ -326,31 +332,10 @@ export default class SystemService {
|
|||||||
return { code: 200 };
|
return { code: 200 };
|
||||||
}
|
}
|
||||||
|
|
||||||
public async reloadSystem(target: 'system' | 'data') {
|
public async reloadSystem(target?: 'system' | 'data') {
|
||||||
const cmd = `real_time=true ql reload ${target || ''}`;
|
const cmd = `real_time=true ql reload ${target || ''}`;
|
||||||
const cp = spawn(cmd, { shell: '/bin/bash' });
|
const cp = spawn(cmd, { shell: '/bin/bash' });
|
||||||
|
cp.unref();
|
||||||
cp.stdout.on('data', (data) => {
|
|
||||||
this.sockService.sendMessage({
|
|
||||||
type: 'reloadSystem',
|
|
||||||
message: data.toString(),
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
cp.stderr.on('data', (data) => {
|
|
||||||
this.sockService.sendMessage({
|
|
||||||
type: 'reloadSystem',
|
|
||||||
message: data.toString(),
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
cp.on('error', (err) => {
|
|
||||||
this.sockService.sendMessage({
|
|
||||||
type: 'reloadSystem',
|
|
||||||
message: JSON.stringify(err),
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
return { code: 200 };
|
return { code: 200 };
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -403,10 +388,7 @@ export default class SystemService {
|
|||||||
|
|
||||||
public async exportData(res: Response) {
|
public async exportData(res: Response) {
|
||||||
try {
|
try {
|
||||||
await tar.create(
|
await promiseExec(`cd ${config.rootPath} && tar -zcvf ${config.dataTgzFile} data/`);
|
||||||
{ gzip: true, file: config.dataTgzFile, cwd: config.rootPath },
|
|
||||||
['data'],
|
|
||||||
);
|
|
||||||
res.download(config.dataTgzFile);
|
res.download(config.dataTgzFile);
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
return res.send({ code: 400, message: error.message });
|
return res.send({ code: 400, message: error.message });
|
||||||
@@ -416,8 +398,10 @@ export default class SystemService {
|
|||||||
public async importData() {
|
public async importData() {
|
||||||
try {
|
try {
|
||||||
await promiseExec(`rm -rf ${path.join(config.tmpPath, 'data')}`);
|
await promiseExec(`rm -rf ${path.join(config.tmpPath, 'data')}`);
|
||||||
await tar.x({ file: config.dataTgzFile, cwd: config.tmpPath });
|
const res = await promiseExec(
|
||||||
return { code: 200 };
|
`cd ${config.tmpPath} && tar -zxvf data.tgz`,
|
||||||
|
);
|
||||||
|
return { code: 200, data: res };
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
return { code: 400, message: error.message };
|
return { code: 400, message: error.message };
|
||||||
}
|
}
|
||||||
|
|||||||
+46
-20
@@ -2,11 +2,19 @@ import PQueue, { QueueAddOptions } from 'p-queue-cjs';
|
|||||||
import os from 'os';
|
import os from 'os';
|
||||||
import { AuthDataType, SystemModel } from '../data/system';
|
import { AuthDataType, SystemModel } from '../data/system';
|
||||||
import Logger from '../loaders/logger';
|
import Logger from '../loaders/logger';
|
||||||
|
import { Dependence } from '../data/dependence';
|
||||||
|
|
||||||
|
interface IDependencyFn<T> {
|
||||||
|
(): Promise<T>;
|
||||||
|
dependency?: Dependence;
|
||||||
|
}
|
||||||
class TaskLimit {
|
class TaskLimit {
|
||||||
private oneLimit = new PQueue({ concurrency: 1 });
|
private dependenyLimit = new PQueue({ concurrency: 1 });
|
||||||
|
private queuedDependencyIds = new Set<number>([]);
|
||||||
private updateLogLimit = new PQueue({ concurrency: 1 });
|
private updateLogLimit = new PQueue({ concurrency: 1 });
|
||||||
private cronLimit = new PQueue({ concurrency: Math.max(os.cpus().length, 4) });
|
private cronLimit = new PQueue({
|
||||||
|
concurrency: Math.max(os.cpus().length, 4),
|
||||||
|
});
|
||||||
|
|
||||||
get cronLimitActiveCount() {
|
get cronLimitActiveCount() {
|
||||||
return this.cronLimit.pending;
|
return this.cronLimit.pending;
|
||||||
@@ -16,6 +24,10 @@ class TaskLimit {
|
|||||||
return this.cronLimit.size;
|
return this.cronLimit.size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get firstDependencyId() {
|
||||||
|
return [...this.queuedDependencyIds.values()][0];
|
||||||
|
}
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.setCustomLimit();
|
this.setCustomLimit();
|
||||||
this.handleEvents();
|
this.handleEvents();
|
||||||
@@ -26,21 +38,19 @@ class TaskLimit {
|
|||||||
Logger.info(
|
Logger.info(
|
||||||
`[schedule][任务加入队列] 运行中任务数: ${this.cronLimitActiveCount}, 等待中任务数: ${this.cronLimitPendingCount}`,
|
`[schedule][任务加入队列] 运行中任务数: ${this.cronLimitActiveCount}, 等待中任务数: ${this.cronLimitPendingCount}`,
|
||||||
);
|
);
|
||||||
})
|
});
|
||||||
this.cronLimit.on('active', () => {
|
this.cronLimit.on('active', () => {
|
||||||
Logger.info(
|
Logger.info(
|
||||||
`[schedule][开始处理任务] 运行中任务数: ${this.cronLimitActiveCount + 1}, 等待中任务数: ${this.cronLimitPendingCount}`,
|
`[schedule][开始处理任务] 运行中任务数: ${
|
||||||
);
|
this.cronLimitActiveCount + 1
|
||||||
})
|
}, 等待中任务数: ${this.cronLimitPendingCount}`,
|
||||||
this.cronLimit.on('completed', (param) => {
|
|
||||||
Logger.info(
|
|
||||||
`[schedule][任务处理成功] 参数 ${JSON.stringify(param)}`,
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
this.cronLimit.on('error', error => {
|
this.cronLimit.on('completed', (param) => {
|
||||||
Logger.error(
|
Logger.info(`[schedule][任务处理成功] 参数 ${JSON.stringify(param)}`);
|
||||||
`[schedule][任务处理错误] 参数 ${JSON.stringify(error)}`,
|
});
|
||||||
);
|
this.cronLimit.on('error', (error) => {
|
||||||
|
Logger.error(`[schedule][任务处理错误] 参数 ${JSON.stringify(error)}`);
|
||||||
});
|
});
|
||||||
this.cronLimit.on('next', () => {
|
this.cronLimit.on('next', () => {
|
||||||
Logger.info(
|
Logger.info(
|
||||||
@@ -48,12 +58,16 @@ class TaskLimit {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
this.cronLimit.on('idle', () => {
|
this.cronLimit.on('idle', () => {
|
||||||
Logger.info(
|
Logger.info(`[schedule][任务队列] 空闲中...`);
|
||||||
`[schedule][任务队列] 空闲中...`,
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public removeQueuedDependency(dependency: Dependence) {
|
||||||
|
if (this.queuedDependencyIds.has(dependency.id!)) {
|
||||||
|
this.queuedDependencyIds.delete(dependency.id!);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async setCustomLimit(limit?: number) {
|
public async setCustomLimit(limit?: number) {
|
||||||
if (limit) {
|
if (limit) {
|
||||||
this.cronLimit.concurrency = limit;
|
this.cronLimit.concurrency = limit;
|
||||||
@@ -68,15 +82,27 @@ class TaskLimit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async runWithCronLimit<T>(fn: () => Promise<T>, options?: Partial<QueueAddOptions>): Promise<T | void> {
|
public async runWithCronLimit<T>(
|
||||||
|
fn: () => Promise<T>,
|
||||||
|
options?: Partial<QueueAddOptions>,
|
||||||
|
): Promise<T | void> {
|
||||||
return this.cronLimit.add(fn, options);
|
return this.cronLimit.add(fn, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
public runOneByOne<T>(fn: () => Promise<T>, options?: Partial<QueueAddOptions>): Promise<T | void> {
|
public runDependeny<T>(
|
||||||
return this.oneLimit.add(fn, options);
|
dependency: Dependence,
|
||||||
|
fn: IDependencyFn<T>,
|
||||||
|
options?: Partial<QueueAddOptions>,
|
||||||
|
): Promise<T | void> {
|
||||||
|
this.queuedDependencyIds.add(dependency.id!);
|
||||||
|
fn.dependency = dependency;
|
||||||
|
return this.dependenyLimit.add(fn, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
public updateDepLog<T>(fn: () => Promise<T>, options?: Partial<QueueAddOptions>): Promise<T | void> {
|
public updateDepLog<T>(
|
||||||
|
fn: () => Promise<T>,
|
||||||
|
options?: Partial<QueueAddOptions>,
|
||||||
|
): Promise<T | void> {
|
||||||
return this.updateLogLimit.add(fn, options);
|
return this.updateLogLimit.add(fn, options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
import 'reflect-metadata'; // We need this in order to use @Decorators
|
||||||
|
import config from './config';
|
||||||
|
import express from 'express';
|
||||||
|
import depInjectorLoader from './loaders/depInjector';
|
||||||
|
import Logger from './loaders/logger';
|
||||||
|
|
||||||
|
|
||||||
|
async function startServer() {
|
||||||
|
const app = express();
|
||||||
|
depInjectorLoader();
|
||||||
|
|
||||||
|
await require('./loaders/update').default({ app });
|
||||||
|
|
||||||
|
app
|
||||||
|
.listen(config.updatePort, () => {
|
||||||
|
Logger.debug(`✌️ 更新服务启动成功!`);
|
||||||
|
console.debug(`✌️ 更新服务启动成功!`);
|
||||||
|
process.send?.('ready');
|
||||||
|
})
|
||||||
|
.on('error', (err) => {
|
||||||
|
Logger.error(err);
|
||||||
|
console.error(err);
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
startServer();
|
||||||
+10
-4
@@ -3,11 +3,11 @@ COPY package.json .npmrc pnpm-lock.yaml /tmp/build/
|
|||||||
RUN set -x \
|
RUN set -x \
|
||||||
&& apk update \
|
&& apk update \
|
||||||
&& apk add nodejs npm git \
|
&& apk add nodejs npm git \
|
||||||
&& npm i -g pnpm@8.3.1 \
|
&& npm i -g pnpm@8.3.1 pm2 tsx \
|
||||||
&& cd /tmp/build \
|
&& cd /tmp/build \
|
||||||
&& pnpm install --prod
|
&& pnpm install --prod
|
||||||
|
|
||||||
FROM python:3.10-alpine3.18
|
FROM python:3.10-alpine
|
||||||
|
|
||||||
ARG QL_MAINTAINER="whyour"
|
ARG QL_MAINTAINER="whyour"
|
||||||
LABEL maintainer="${QL_MAINTAINER}"
|
LABEL maintainer="${QL_MAINTAINER}"
|
||||||
@@ -23,6 +23,13 @@ ENV PNPM_HOME=/root/.local/share/pnpm \
|
|||||||
QL_DIR=/ql \
|
QL_DIR=/ql \
|
||||||
QL_BRANCH=${QL_BRANCH}
|
QL_BRANCH=${QL_BRANCH}
|
||||||
|
|
||||||
|
VOLUME /ql/data
|
||||||
|
|
||||||
|
EXPOSE 5700
|
||||||
|
|
||||||
|
COPY --from=builder /usr/local/lib/node_modules/. /usr/local/lib/node_modules/
|
||||||
|
COPY --from=builder /usr/local/bin/. /usr/local/bin/
|
||||||
|
|
||||||
RUN set -x \
|
RUN set -x \
|
||||||
&& apk update -f \
|
&& apk update -f \
|
||||||
&& apk upgrade \
|
&& apk upgrade \
|
||||||
@@ -49,11 +56,10 @@ RUN set -x \
|
|||||||
&& git config --global user.email "qinglong@@users.noreply.github.com" \
|
&& git config --global user.email "qinglong@@users.noreply.github.com" \
|
||||||
&& git config --global user.name "qinglong" \
|
&& git config --global user.name "qinglong" \
|
||||||
&& git config --global http.postBuffer 524288000 \
|
&& git config --global http.postBuffer 524288000 \
|
||||||
&& npm install -g pnpm@8.3.1 pm2 tsx \
|
|
||||||
&& rm -rf /root/.pnpm-store \
|
&& rm -rf /root/.pnpm-store \
|
||||||
&& rm -rf /root/.local/share/pnpm/store \
|
&& rm -rf /root/.local/share/pnpm/store \
|
||||||
&& rm -rf /root/.cache \
|
&& rm -rf /root/.cache \
|
||||||
&& rm -rf /root/.npm
|
&& ulimit -c 0
|
||||||
|
|
||||||
ARG SOURCE_COMMIT
|
ARG SOURCE_COMMIT
|
||||||
RUN git clone --depth=1 -b ${QL_BRANCH} ${QL_URL} ${QL_DIR} \
|
RUN git clone --depth=1 -b ${QL_BRANCH} ${QL_URL} ${QL_DIR} \
|
||||||
|
|||||||
+6
-4
@@ -3,11 +3,11 @@ COPY package.json .npmrc pnpm-lock.yaml /tmp/build/
|
|||||||
RUN set -x \
|
RUN set -x \
|
||||||
&& apk update \
|
&& apk update \
|
||||||
&& apk add nodejs npm git \
|
&& apk add nodejs npm git \
|
||||||
&& npm i -g pnpm@8.3.1 \
|
&& npm i -g pnpm@8.3.1 pm2 tsx \
|
||||||
&& cd /tmp/build \
|
&& cd /tmp/build \
|
||||||
&& pnpm install --prod
|
&& pnpm install --prod
|
||||||
|
|
||||||
FROM python:3.11-alpine3.18
|
FROM python:3.11-alpine
|
||||||
|
|
||||||
ARG QL_MAINTAINER="whyour"
|
ARG QL_MAINTAINER="whyour"
|
||||||
LABEL maintainer="${QL_MAINTAINER}"
|
LABEL maintainer="${QL_MAINTAINER}"
|
||||||
@@ -27,6 +27,9 @@ VOLUME /ql/data
|
|||||||
|
|
||||||
EXPOSE 5700
|
EXPOSE 5700
|
||||||
|
|
||||||
|
COPY --from=builder /usr/local/lib/node_modules/. /usr/local/lib/node_modules/
|
||||||
|
COPY --from=builder /usr/local/bin/. /usr/local/bin/
|
||||||
|
|
||||||
RUN set -x \
|
RUN set -x \
|
||||||
&& apk update -f \
|
&& apk update -f \
|
||||||
&& apk upgrade \
|
&& apk upgrade \
|
||||||
@@ -53,11 +56,10 @@ RUN set -x \
|
|||||||
&& git config --global user.email "qinglong@@users.noreply.github.com" \
|
&& git config --global user.email "qinglong@@users.noreply.github.com" \
|
||||||
&& git config --global user.name "qinglong" \
|
&& git config --global user.name "qinglong" \
|
||||||
&& git config --global http.postBuffer 524288000 \
|
&& git config --global http.postBuffer 524288000 \
|
||||||
&& npm install -g pnpm@8.3.1 pm2 tsx \
|
|
||||||
&& rm -rf /root/.pnpm-store \
|
&& rm -rf /root/.pnpm-store \
|
||||||
&& rm -rf /root/.local/share/pnpm/store \
|
&& rm -rf /root/.local/share/pnpm/store \
|
||||||
&& rm -rf /root/.cache \
|
&& rm -rf /root/.cache \
|
||||||
&& rm -rf /root/.npm
|
&& ulimit -c 0
|
||||||
|
|
||||||
ARG SOURCE_COMMIT
|
ARG SOURCE_COMMIT
|
||||||
RUN git clone --depth=1 -b ${QL_BRANCH} ${QL_URL} ${QL_DIR} \
|
RUN git clone --depth=1 -b ${QL_BRANCH} ${QL_URL} ${QL_DIR} \
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ nginx -s reload 2>/dev/null || nginx -c /etc/nginx/nginx.conf
|
|||||||
echo -e "nginx启动成功...\n"
|
echo -e "nginx启动成功...\n"
|
||||||
|
|
||||||
echo -e "======================4. 启动pm2服务========================\n"
|
echo -e "======================4. 启动pm2服务========================\n"
|
||||||
|
reload_update
|
||||||
reload_pm2
|
reload_pm2
|
||||||
|
|
||||||
if [[ $AutoStartBot == true ]]; then
|
if [[ $AutoStartBot == true ]]; then
|
||||||
|
|||||||
@@ -6,6 +6,10 @@ upstream publicApi {
|
|||||||
server 0.0.0.0:5400;
|
server 0.0.0.0:5400;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
upstream updateApi {
|
||||||
|
server 0.0.0.0:5300;
|
||||||
|
}
|
||||||
|
|
||||||
map $http_upgrade $connection_upgrade {
|
map $http_upgrade $connection_upgrade {
|
||||||
default keep-alive;
|
default keep-alive;
|
||||||
'websocket' upgrade;
|
'websocket' upgrade;
|
||||||
@@ -16,6 +20,18 @@ server {
|
|||||||
IPV6_CONFIG
|
IPV6_CONFIG
|
||||||
ssl_session_timeout 5m;
|
ssl_session_timeout 5m;
|
||||||
|
|
||||||
|
location QL_BASE_URLapi/update/ {
|
||||||
|
proxy_set_header Host $http_host;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_pass http://updateApi/api/;
|
||||||
|
proxy_buffering off;
|
||||||
|
proxy_redirect default;
|
||||||
|
proxy_connect_timeout 1800;
|
||||||
|
proxy_send_timeout 1800;
|
||||||
|
proxy_read_timeout 1800;
|
||||||
|
}
|
||||||
|
|
||||||
location QL_BASE_URLapi/public/ {
|
location QL_BASE_URLapi/public/ {
|
||||||
proxy_set_header Host $http_host;
|
proxy_set_header Host $http_host;
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
module.exports = {
|
||||||
|
apps: [
|
||||||
|
{
|
||||||
|
name: 'update',
|
||||||
|
max_restarts: 10,
|
||||||
|
kill_timeout: 15000,
|
||||||
|
wait_ready: true,
|
||||||
|
listen_timeout: 10000,
|
||||||
|
time: true,
|
||||||
|
script: 'static/build/update.js',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
+2
-2
@@ -4,6 +4,7 @@
|
|||||||
"start": "concurrently -n w: npm:start:*",
|
"start": "concurrently -n w: npm:start:*",
|
||||||
"start:front": "max dev",
|
"start:front": "max dev",
|
||||||
"start:back": "nodemon",
|
"start:back": "nodemon",
|
||||||
|
"start:update": "ts-node -P tsconfig.back.json ./back/update.ts",
|
||||||
"start:public": "ts-node -P tsconfig.back.json ./back/public.ts",
|
"start:public": "ts-node -P tsconfig.back.json ./back/public.ts",
|
||||||
"start:rpc": "ts-node -P tsconfig.back.json ./back/schedule/index.ts",
|
"start:rpc": "ts-node -P tsconfig.back.json ./back/schedule/index.ts",
|
||||||
"build:front": "max build",
|
"build:front": "max build",
|
||||||
@@ -11,6 +12,7 @@
|
|||||||
"panel": "npm run build:back && node static/build/app.js",
|
"panel": "npm run build:back && node static/build/app.js",
|
||||||
"schedule": "npm run build:back && node static/build/schedule/index.js",
|
"schedule": "npm run build:back && node static/build/schedule/index.js",
|
||||||
"public": "npm run build:back && node static/build/public.js",
|
"public": "npm run build:back && node static/build/public.js",
|
||||||
|
"update": "npm run build:back && node static/build/update.js",
|
||||||
"gen:proto": "protoc --experimental_allow_proto3_optional --plugin=./node_modules/.bin/protoc-gen-ts_proto ./back/protos/*.proto --ts_proto_out=./ --ts_proto_opt=outputServices=grpc-js,env=node,esModuleInterop=true",
|
"gen:proto": "protoc --experimental_allow_proto3_optional --plugin=./node_modules/.bin/protoc-gen-ts_proto ./back/protos/*.proto --ts_proto_out=./ --ts_proto_opt=outputServices=grpc-js,env=node,esModuleInterop=true",
|
||||||
"prettier": "prettier --write '**/*.{js,jsx,tsx,ts,less,md,json}'",
|
"prettier": "prettier --write '**/*.{js,jsx,tsx,ts,less,md,json}'",
|
||||||
"postinstall": "max setup 2>/dev/null || true",
|
"postinstall": "max setup 2>/dev/null || true",
|
||||||
@@ -90,7 +92,6 @@
|
|||||||
"serve-handler": "^6.1.3",
|
"serve-handler": "^6.1.3",
|
||||||
"sockjs": "^0.3.24",
|
"sockjs": "^0.3.24",
|
||||||
"sqlite3": "git+https://github.com/whyour/node-sqlite3.git#v1.0.3",
|
"sqlite3": "git+https://github.com/whyour/node-sqlite3.git#v1.0.3",
|
||||||
"tar": "^6.1.15",
|
|
||||||
"toad-scheduler": "^1.6.0",
|
"toad-scheduler": "^1.6.0",
|
||||||
"typedi": "^0.10.0",
|
"typedi": "^0.10.0",
|
||||||
"uuid": "^8.3.2",
|
"uuid": "^8.3.2",
|
||||||
@@ -128,7 +129,6 @@
|
|||||||
"@types/serve-handler": "^6.1.1",
|
"@types/serve-handler": "^6.1.1",
|
||||||
"@types/sockjs": "^0.3.33",
|
"@types/sockjs": "^0.3.33",
|
||||||
"@types/sockjs-client": "^1.5.1",
|
"@types/sockjs-client": "^1.5.1",
|
||||||
"@types/tar": "^6.1.5",
|
|
||||||
"@types/uuid": "^8.3.4",
|
"@types/uuid": "^8.3.4",
|
||||||
"@types/request-ip": "0.0.41",
|
"@types/request-ip": "0.0.41",
|
||||||
"@uiw/codemirror-extensions-langs": "^4.21.9",
|
"@uiw/codemirror-extensions-langs": "^4.21.9",
|
||||||
|
|||||||
Generated
-18
@@ -112,9 +112,6 @@ dependencies:
|
|||||||
sqlite3:
|
sqlite3:
|
||||||
specifier: git+https://github.com/whyour/node-sqlite3.git#v1.0.3
|
specifier: git+https://github.com/whyour/node-sqlite3.git#v1.0.3
|
||||||
version: github.com/whyour/node-sqlite3/3a00af0b5d7603b7f1b290032507320b18a6b741
|
version: github.com/whyour/node-sqlite3/3a00af0b5d7603b7f1b290032507320b18a6b741
|
||||||
tar:
|
|
||||||
specifier: ^6.1.15
|
|
||||||
version: 6.1.15
|
|
||||||
toad-scheduler:
|
toad-scheduler:
|
||||||
specifier: ^1.6.0
|
specifier: ^1.6.0
|
||||||
version: 1.6.1
|
version: 1.6.1
|
||||||
@@ -219,9 +216,6 @@ devDependencies:
|
|||||||
'@types/sockjs-client':
|
'@types/sockjs-client':
|
||||||
specifier: ^1.5.1
|
specifier: ^1.5.1
|
||||||
version: 1.5.1
|
version: 1.5.1
|
||||||
'@types/tar':
|
|
||||||
specifier: ^6.1.5
|
|
||||||
version: 6.1.5
|
|
||||||
'@types/uuid':
|
'@types/uuid':
|
||||||
specifier: ^8.3.4
|
specifier: ^8.3.4
|
||||||
version: 8.3.4
|
version: 8.3.4
|
||||||
@@ -5128,13 +5122,6 @@ packages:
|
|||||||
'@types/node': 17.0.45
|
'@types/node': 17.0.45
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
/@types/tar@6.1.5:
|
|
||||||
resolution: {integrity: sha512-qm2I/RlZij5RofuY7vohTpYNaYcrSQlN2MyjucQc7ZweDwaEWkdN/EeNh6e9zjK6uEm6PwjdMXkcj05BxZdX1Q==}
|
|
||||||
dependencies:
|
|
||||||
'@types/node': 17.0.45
|
|
||||||
minipass: 4.2.8
|
|
||||||
dev: true
|
|
||||||
|
|
||||||
/@types/triple-beam@1.3.2:
|
/@types/triple-beam@1.3.2:
|
||||||
resolution: {integrity: sha512-txGIh+0eDFzKGC25zORnswy+br1Ha7hj5cMVwKIU7+s0U2AxxJru/jZSMU6OC9MJWP6+pc/hc6ZjyZShpsyY2g==}
|
resolution: {integrity: sha512-txGIh+0eDFzKGC25zORnswy+br1Ha7hj5cMVwKIU7+s0U2AxxJru/jZSMU6OC9MJWP6+pc/hc6ZjyZShpsyY2g==}
|
||||||
dev: false
|
dev: false
|
||||||
@@ -11090,11 +11077,6 @@ packages:
|
|||||||
yallist: 4.0.0
|
yallist: 4.0.0
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
/minipass@4.2.8:
|
|
||||||
resolution: {integrity: sha512-fNzuVyifolSLFL4NzpF+wEF4qrgqaaKX0haXPQEdQ7NKAN+WecoKMHV09YcuL/DHxrUsYQOK3MiuDf7Ip2OXfQ==}
|
|
||||||
engines: {node: '>=8'}
|
|
||||||
dev: true
|
|
||||||
|
|
||||||
/minipass@5.0.0:
|
/minipass@5.0.0:
|
||||||
resolution: {integrity: sha512-3FnjYuehv9k6ovOEbyOswadCDPX1piCfhV8ncmYtHOjuPwylVWsghTLo7rabjC3Rx5xD4HDx8Wm1xnMF7S5qFQ==}
|
resolution: {integrity: sha512-3FnjYuehv9k6ovOEbyOswadCDPX1piCfhV8ncmYtHOjuPwylVWsghTLo7rabjC3Rx5xD4HDx8Wm1xnMF7S5qFQ==}
|
||||||
engines: {node: '>=8'}
|
engines: {node: '>=8'}
|
||||||
|
|||||||
+19
-8
@@ -148,6 +148,15 @@ export AIBOTK_TYPE=""
|
|||||||
## aibotk_name (必填)填写群名或用户昵称,和上面的type类型要对应
|
## aibotk_name (必填)填写群名或用户昵称,和上面的type类型要对应
|
||||||
export AIBOTK_NAME=""
|
export AIBOTK_NAME=""
|
||||||
|
|
||||||
|
## 13. CHRONOCAT
|
||||||
|
## CHRONOCAT_URL 推送 http://127.0.0.1:16530
|
||||||
|
## CHRONOCAT_TOKEN 填写在CHRONOCAT文件生成的访问密钥
|
||||||
|
## CHRONOCAT_QQ 个人:user_id=个人QQ 群则填入group_id=QQ群 多个用英文;隔开同时支持个人和群 如:user_id=xxx;group_id=xxxx;group_id=xxxxx
|
||||||
|
## CHRONOCAT相关API https://chronocat.vercel.app/install/docker/official/
|
||||||
|
export CHRONOCAT_URL=""
|
||||||
|
export CHRONOCAT_QQ=""
|
||||||
|
export CHRONOCAT_TOKEN=""
|
||||||
|
|
||||||
## 14. SMTP
|
## 14. SMTP
|
||||||
## 邮箱服务名称,比如126、163、Gmail、QQ等,支持列表 https://github.com/nodemailer/nodemailer/blob/master/lib/well-known/services.json
|
## 邮箱服务名称,比如126、163、Gmail、QQ等,支持列表 https://github.com/nodemailer/nodemailer/blob/master/lib/well-known/services.json
|
||||||
export SMTP_SERVICE=""
|
export SMTP_SERVICE=""
|
||||||
@@ -163,13 +172,15 @@ export SMTP_NAME=""
|
|||||||
## PUSHME_KEY (必填)填写PushMe APP上获取的push_key
|
## PUSHME_KEY (必填)填写PushMe APP上获取的push_key
|
||||||
export PUSHME_KEY=""
|
export PUSHME_KEY=""
|
||||||
|
|
||||||
## 13. CHRONOCAT
|
## 15. 自定义通知
|
||||||
## CHRONOCAT_URL 推送 http://127.0.0.1:16530
|
## 自定义通知 接收回调的URL
|
||||||
## CHRONOCAT_TOKEN 填写在CHRONOCAT文件生成的访问密钥
|
export WEBHOOK_URL=""
|
||||||
## CHRONOCAT_QQ 个人:user_id=个人QQ 群则填入group_id=QQ群 多个用英文;隔开同时支持个人和群 如:user_id=xxx;group_id=xxxx;group_id=xxxxx
|
## WEBHOOK_BODY 和 WEBHOOK_HEADERS 多个参数时,直接换行或者使用 $'\n' 连接多行字符串,比如 export dd="line 1"$'\n'"line 2"
|
||||||
## CHRONOCAT相关API https://chronocat.vercel.app/install/docker/official/
|
export WEBHOOK_BODY=""
|
||||||
export CHRONOCAT_URL=""
|
export WEBHOOK_HEADERS=""
|
||||||
export CHRONOCAT_QQ=""
|
## 支持 GET/POST/PUT
|
||||||
export CHRONOCAT_TOKEN=""
|
export WEBHOOK_METHOD=""
|
||||||
|
## 支持 text/plain、application/json、multipart/form-data、application/x-www-form-urlencoded
|
||||||
|
export WEBHOOK_CONTENT_TYPE=""
|
||||||
|
|
||||||
## 其他需要的变量,脚本中需要的变量使用 export 变量名= 声明即可
|
## 其他需要的变量,脚本中需要的变量使用 export 变量名= 声明即可
|
||||||
|
|||||||
+49
-32
@@ -816,7 +816,18 @@ function ChangeUserId(desp) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function qywxamNotify(text, desp) {
|
async function qywxamNotify(text, desp) {
|
||||||
|
const MAX_LENGTH = 900;
|
||||||
|
if (desp.length > MAX_LENGTH) {
|
||||||
|
let d = desp.substr(0, MAX_LENGTH) + '\n==More==';
|
||||||
|
await do_qywxamNotify(text, d);
|
||||||
|
await qywxamNotify(text, desp.substr(MAX_LENGTH));
|
||||||
|
} else {
|
||||||
|
return await do_qywxamNotify(text, desp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function do_qywxamNotify(text, desp) {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
if (QYWX_AM) {
|
if (QYWX_AM) {
|
||||||
const QYWX_AM_AY = QYWX_AM.split(',');
|
const QYWX_AM_AY = QYWX_AM.split(',');
|
||||||
@@ -1273,18 +1284,15 @@ function chronocatNotify(title, desp) {
|
|||||||
|
|
||||||
function webhookNotify(text, desp) {
|
function webhookNotify(text, desp) {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
const { formatBody, formatUrl } = formatNotifyContentFun(
|
if (!WEBHOOK_URL.includes('$title') && !WEBHOOK_BODY.includes('$title')) {
|
||||||
WEBHOOK_URL,
|
|
||||||
WEBHOOK_BODY,
|
|
||||||
text,
|
|
||||||
desp,
|
|
||||||
);
|
|
||||||
if (!formatUrl && !formatBody) {
|
|
||||||
resolve();
|
resolve();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const headers = parseHeaders(WEBHOOK_HEADERS);
|
const headers = parseHeaders(WEBHOOK_HEADERS);
|
||||||
const body = parseBody(formatBody, WEBHOOK_CONTENT_TYPE);
|
const body = parseBody(WEBHOOK_BODY, WEBHOOK_CONTENT_TYPE, (v) =>
|
||||||
|
v?.replaceAll('$title', text)?.replaceAll('$content', desp),
|
||||||
|
);
|
||||||
const bodyParam = formatBodyFun(WEBHOOK_CONTENT_TYPE, body);
|
const bodyParam = formatBodyFun(WEBHOOK_CONTENT_TYPE, body);
|
||||||
const options = {
|
const options = {
|
||||||
method: WEBHOOK_METHOD,
|
method: WEBHOOK_METHOD,
|
||||||
@@ -1296,6 +1304,10 @@ function webhookNotify(text, desp) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (WEBHOOK_METHOD) {
|
if (WEBHOOK_METHOD) {
|
||||||
|
const formatUrl = WEBHOOK_URL.replaceAll(
|
||||||
|
'$title',
|
||||||
|
encodeURIComponent(text),
|
||||||
|
).replaceAll('$content', encodeURIComponent(desp));
|
||||||
got(formatUrl, options).then((resp) => {
|
got(formatUrl, options).then((resp) => {
|
||||||
try {
|
try {
|
||||||
if (resp.statusCode !== 200) {
|
if (resp.statusCode !== 200) {
|
||||||
@@ -1315,6 +1327,32 @@ function webhookNotify(text, desp) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function parseString(input, valueFormatFn) {
|
||||||
|
const regex = /(\w+):\s*((?:(?!\n\w+:).)*)/g;
|
||||||
|
const matches = {};
|
||||||
|
|
||||||
|
let match;
|
||||||
|
while ((match = regex.exec(input)) !== null) {
|
||||||
|
const [, key, value] = match;
|
||||||
|
const _key = key.trim();
|
||||||
|
if (!_key || matches[_key]) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let _value = value.trim();
|
||||||
|
|
||||||
|
try {
|
||||||
|
_value = valueFormatFn ? valueFormatFn(_value) : _value;
|
||||||
|
const jsonValue = JSON.parse(_value);
|
||||||
|
matches[_key] = jsonValue;
|
||||||
|
} catch (error) {
|
||||||
|
matches[_key] = _value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return matches;
|
||||||
|
}
|
||||||
|
|
||||||
function parseHeaders(headers) {
|
function parseHeaders(headers) {
|
||||||
if (!headers) return {};
|
if (!headers) return {};
|
||||||
|
|
||||||
@@ -1339,33 +1377,12 @@ function parseHeaders(headers) {
|
|||||||
return parsed;
|
return parsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseBody(body, contentType) {
|
function parseBody(body, contentType, valueFormatFn) {
|
||||||
if (contentType === 'text/plain' || !body) {
|
if (contentType === 'text/plain' || !body) {
|
||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
const parsed = {};
|
const parsed = parseString(body, valueFormatFn);
|
||||||
let key;
|
|
||||||
let val;
|
|
||||||
let i;
|
|
||||||
|
|
||||||
body &&
|
|
||||||
body.split('\n').forEach(function parser(line) {
|
|
||||||
i = line.indexOf(':');
|
|
||||||
key = line.substring(0, i).trim();
|
|
||||||
val = line.substring(i + 1).trim();
|
|
||||||
|
|
||||||
if (!key || parsed[key]) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const jsonValue = JSON.parse(val);
|
|
||||||
parsed[key] = jsonValue;
|
|
||||||
} catch (error) {
|
|
||||||
parsed[key] = val;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
switch (contentType) {
|
switch (contentType) {
|
||||||
case 'multipart/form-data':
|
case 'multipart/form-data':
|
||||||
|
|||||||
+287
-146
@@ -123,19 +123,19 @@ for k in push_config:
|
|||||||
push_config[k] = v
|
push_config[k] = v
|
||||||
|
|
||||||
|
|
||||||
def bark(title: str, content: str) -> None:
|
def bark(title: str, content: str, **kwargs) -> None:
|
||||||
"""
|
"""
|
||||||
使用 bark 推送消息。
|
使用 bark 推送消息。
|
||||||
"""
|
"""
|
||||||
if not push_config.get("BARK_PUSH"):
|
if not (push_config.get("BARK_PUSH") or kwargs.get("BARK_PUSH")):
|
||||||
print("bark 服务的 BARK_PUSH 未设置!!\n取消推送")
|
print("bark 服务的 BARK_PUSH 未设置!!\n取消推送")
|
||||||
return
|
return
|
||||||
print("bark 服务启动")
|
print("bark 服务启动")
|
||||||
|
BARK_PUSH = kwargs.get("BARK_PUSH", push_config.get("BARK_PUSH"))
|
||||||
if push_config.get("BARK_PUSH").startswith("http"):
|
if BARK_PUSH.startswith("http"):
|
||||||
url = f'{push_config.get("BARK_PUSH")}/{urllib.parse.quote_plus(title)}/{urllib.parse.quote_plus(content)}'
|
url = f"{BARK_PUSH}/{urllib.parse.quote_plus(title)}/{urllib.parse.quote_plus(content)}"
|
||||||
else:
|
else:
|
||||||
url = f'https://api.day.app/{push_config.get("BARK_PUSH")}/{urllib.parse.quote_plus(title)}/{urllib.parse.quote_plus(content)}'
|
url = f"https://api.day.app/{BARK_PUSH}/{urllib.parse.quote_plus(title)}/{urllib.parse.quote_plus(content)}"
|
||||||
|
|
||||||
bark_params = {
|
bark_params = {
|
||||||
"BARK_ARCHIVE": "isArchive",
|
"BARK_ARCHIVE": "isArchive",
|
||||||
@@ -149,11 +149,12 @@ def bark(title: str, content: str) -> None:
|
|||||||
for pair in filter(
|
for pair in filter(
|
||||||
lambda pairs: pairs[0].startswith("BARK_")
|
lambda pairs: pairs[0].startswith("BARK_")
|
||||||
and pairs[0] != "BARK_PUSH"
|
and pairs[0] != "BARK_PUSH"
|
||||||
and pairs[1]
|
and (pairs[1] or kwargs.get(pairs[0]))
|
||||||
and bark_params.get(pairs[0]),
|
and bark_params.get(pairs[0]),
|
||||||
push_config.items(),
|
push_config.items(),
|
||||||
):
|
):
|
||||||
params += f"{bark_params.get(pair[0])}={pair[1]}&"
|
value = kwargs.get(pair[0], pair[1])
|
||||||
|
params += f"{bark_params.get(pair[0])}={value}&"
|
||||||
if params:
|
if params:
|
||||||
url = url + "?" + params.rstrip("&")
|
url = url + "?" + params.rstrip("&")
|
||||||
response = requests.get(url).json()
|
response = requests.get(url).json()
|
||||||
@@ -164,31 +165,40 @@ def bark(title: str, content: str) -> None:
|
|||||||
print("bark 推送失败!")
|
print("bark 推送失败!")
|
||||||
|
|
||||||
|
|
||||||
def console(title: str, content: str) -> None:
|
def console(title: str, content: str, **kwargs) -> None:
|
||||||
"""
|
"""
|
||||||
使用 控制台 推送消息。
|
使用 控制台 推送消息。
|
||||||
"""
|
"""
|
||||||
print(f"{title}\n\n{content}")
|
print(f"{title}\n\n{content}")
|
||||||
|
|
||||||
|
|
||||||
def dingding_bot(title: str, content: str) -> None:
|
def dingding_bot(title: str, content: str, **kwargs) -> None:
|
||||||
"""
|
"""
|
||||||
使用 钉钉机器人 推送消息。
|
使用 钉钉机器人 推送消息。
|
||||||
"""
|
"""
|
||||||
if not push_config.get("DD_BOT_SECRET") or not push_config.get("DD_BOT_TOKEN"):
|
if not (
|
||||||
|
(kwargs.get("DD_BOT_SECRET") and kwargs.get("DD_BOT_TOKEN"))
|
||||||
|
or (push_config.get("DD_BOT_SECRET") and push_config.get("DD_BOT_TOKEN"))
|
||||||
|
):
|
||||||
print("钉钉机器人 服务的 DD_BOT_SECRET 或者 DD_BOT_TOKEN 未设置!!\n取消推送")
|
print("钉钉机器人 服务的 DD_BOT_SECRET 或者 DD_BOT_TOKEN 未设置!!\n取消推送")
|
||||||
return
|
return
|
||||||
print("钉钉机器人 服务启动")
|
print("钉钉机器人 服务启动")
|
||||||
|
if kwargs.get("DD_BOT_SECRET") and kwargs.get("DD_BOT_TOKEN"):
|
||||||
|
DD_BOT_SECRET = kwargs.get("DD_BOT_SECRET")
|
||||||
|
DD_BOT_TOKEN = kwargs.get("DD_BOT_TOKEN")
|
||||||
|
else:
|
||||||
|
DD_BOT_SECRET = push_config.get("DD_BOT_SECRET")
|
||||||
|
DD_BOT_TOKEN = push_config.get("DD_BOT_TOKEN")
|
||||||
|
|
||||||
timestamp = str(round(time.time() * 1000))
|
timestamp = str(round(time.time() * 1000))
|
||||||
secret_enc = push_config.get("DD_BOT_SECRET").encode("utf-8")
|
secret_enc = DD_BOT_SECRET.encode("utf-8")
|
||||||
string_to_sign = "{}\n{}".format(timestamp, push_config.get("DD_BOT_SECRET"))
|
string_to_sign = "{}\n{}".format(timestamp, DD_BOT_SECRET)
|
||||||
string_to_sign_enc = string_to_sign.encode("utf-8")
|
string_to_sign_enc = string_to_sign.encode("utf-8")
|
||||||
hmac_code = hmac.new(
|
hmac_code = hmac.new(
|
||||||
secret_enc, string_to_sign_enc, digestmod=hashlib.sha256
|
secret_enc, string_to_sign_enc, digestmod=hashlib.sha256
|
||||||
).digest()
|
).digest()
|
||||||
sign = urllib.parse.quote_plus(base64.b64encode(hmac_code))
|
sign = urllib.parse.quote_plus(base64.b64encode(hmac_code))
|
||||||
url = f'https://oapi.dingtalk.com/robot/send?access_token={push_config.get("DD_BOT_TOKEN")}×tamp={timestamp}&sign={sign}'
|
url = f"https://oapi.dingtalk.com/robot/send?access_token={DD_BOT_TOKEN}×tamp={timestamp}&sign={sign}"
|
||||||
headers = {"Content-Type": "application/json;charset=utf-8"}
|
headers = {"Content-Type": "application/json;charset=utf-8"}
|
||||||
data = {"msgtype": "text", "text": {"content": f"{title}\n\n{content}"}}
|
data = {"msgtype": "text", "text": {"content": f"{title}\n\n{content}"}}
|
||||||
response = requests.post(
|
response = requests.post(
|
||||||
@@ -201,16 +211,16 @@ def dingding_bot(title: str, content: str) -> None:
|
|||||||
print("钉钉机器人 推送失败!")
|
print("钉钉机器人 推送失败!")
|
||||||
|
|
||||||
|
|
||||||
def feishu_bot(title: str, content: str) -> None:
|
def feishu_bot(title: str, content: str, **kwargs) -> None:
|
||||||
"""
|
"""
|
||||||
使用 飞书机器人 推送消息。
|
使用 飞书机器人 推送消息。
|
||||||
"""
|
"""
|
||||||
if not push_config.get("FSKEY"):
|
if not (kwargs.get("DD_BOT_SECRET") or push_config.get("FSKEY")):
|
||||||
print("飞书 服务的 FSKEY 未设置!!\n取消推送")
|
print("飞书 服务的 FSKEY 未设置!!\n取消推送")
|
||||||
return
|
return
|
||||||
print("飞书 服务启动")
|
print("飞书 服务启动")
|
||||||
|
FSKEY = kwargs.get("DD_BOT_SECRET", push_config.get("FSKEY"))
|
||||||
url = f'https://open.feishu.cn/open-apis/bot/v2/hook/{push_config.get("FSKEY")}'
|
url = f"https://open.feishu.cn/open-apis/bot/v2/hook/{FSKEY}"
|
||||||
data = {"msg_type": "text", "content": {"text": f"{title}\n\n{content}"}}
|
data = {"msg_type": "text", "content": {"text": f"{title}\n\n{content}"}}
|
||||||
response = requests.post(url, data=json.dumps(data)).json()
|
response = requests.post(url, data=json.dumps(data)).json()
|
||||||
|
|
||||||
@@ -220,16 +230,27 @@ def feishu_bot(title: str, content: str) -> None:
|
|||||||
print("飞书 推送失败!错误信息如下:\n", response)
|
print("飞书 推送失败!错误信息如下:\n", response)
|
||||||
|
|
||||||
|
|
||||||
def go_cqhttp(title: str, content: str) -> None:
|
def go_cqhttp(title: str, content: str, **kwargs) -> None:
|
||||||
"""
|
"""
|
||||||
使用 go_cqhttp 推送消息。
|
使用 go_cqhttp 推送消息。
|
||||||
"""
|
"""
|
||||||
if not push_config.get("GOBOT_URL") or not push_config.get("GOBOT_QQ"):
|
if not (
|
||||||
|
(kwargs.get("GOBOT_URL") and kwargs.get("GOBOT_QQ"))
|
||||||
|
or (push_config.get("GOBOT_URL") and push_config.get("GOBOT_QQ"))
|
||||||
|
):
|
||||||
print("go-cqhttp 服务的 GOBOT_URL 或 GOBOT_QQ 未设置!!\n取消推送")
|
print("go-cqhttp 服务的 GOBOT_URL 或 GOBOT_QQ 未设置!!\n取消推送")
|
||||||
return
|
return
|
||||||
print("go-cqhttp 服务启动")
|
print("go-cqhttp 服务启动")
|
||||||
|
if kwargs.get("GOBOT_URL") and kwargs.get("GOBOT_QQ"):
|
||||||
|
GOBOT_URL = kwargs.get("GOBOT_URL")
|
||||||
|
GOBOT_QQ = kwargs.get("GOBOT_QQ")
|
||||||
|
GOBOT_TOKEN = kwargs.get("GOBOT_TOKEN")
|
||||||
|
else:
|
||||||
|
GOBOT_URL = push_config.get("GOBOT_URL")
|
||||||
|
GOBOT_QQ = push_config.get("GOBOT_QQ")
|
||||||
|
GOBOT_TOKEN = push_config.get("GOBOT_TOKEN")
|
||||||
|
|
||||||
url = f'{push_config.get("GOBOT_URL")}?access_token={push_config.get("GOBOT_TOKEN")}&{push_config.get("GOBOT_QQ")}&message=标题:{title}\n内容:{content}'
|
url = f"{GOBOT_URL}?access_token={GOBOT_TOKEN}&{GOBOT_QQ}&message=标题:{title}\n内容:{content}"
|
||||||
response = requests.get(url).json()
|
response = requests.get(url).json()
|
||||||
|
|
||||||
if response["status"] == "ok":
|
if response["status"] == "ok":
|
||||||
@@ -238,20 +259,31 @@ def go_cqhttp(title: str, content: str) -> None:
|
|||||||
print("go-cqhttp 推送失败!")
|
print("go-cqhttp 推送失败!")
|
||||||
|
|
||||||
|
|
||||||
def gotify(title: str, content: str) -> None:
|
def gotify(title: str, content: str, **kwargs) -> None:
|
||||||
"""
|
"""
|
||||||
使用 gotify 推送消息。
|
使用 gotify 推送消息。
|
||||||
"""
|
"""
|
||||||
if not push_config.get("GOTIFY_URL") or not push_config.get("GOTIFY_TOKEN"):
|
if not (
|
||||||
|
(kwargs.get("GOTIFY_URL") and kwargs.get("GOTIFY_TOKEN"))
|
||||||
|
or (push_config.get("GOTIFY_URL") and push_config.get("GOTIFY_TOKEN"))
|
||||||
|
):
|
||||||
print("gotify 服务的 GOTIFY_URL 或 GOTIFY_TOKEN 未设置!!\n取消推送")
|
print("gotify 服务的 GOTIFY_URL 或 GOTIFY_TOKEN 未设置!!\n取消推送")
|
||||||
return
|
return
|
||||||
print("gotify 服务启动")
|
print("gotify 服务启动")
|
||||||
|
if kwargs.get("GOTIFY_URL") and kwargs.get("GOTIFY_TOKEN"):
|
||||||
|
GOTIFY_URL = kwargs.get("GOTIFY_URL")
|
||||||
|
GOTIFY_TOKEN = kwargs.get("GOBOTGOTIFY_TOKEN_QQ")
|
||||||
|
GOTIFY_PRIORITY = kwargs.get("GOTIFY_PRIORITY")
|
||||||
|
else:
|
||||||
|
GOTIFY_URL = push_config.get("GOTIFY_URL")
|
||||||
|
GOTIFY_TOKEN = push_config.get("GOTIFY_TOKEN")
|
||||||
|
GOTIFY_PRIORITY = kwargs.get("GOTIFY_PRIORITY")
|
||||||
|
|
||||||
url = f'{push_config.get("GOTIFY_URL")}/message?token={push_config.get("GOTIFY_TOKEN")}'
|
url = f"{GOTIFY_URL}/message?token={GOTIFY_TOKEN}"
|
||||||
data = {
|
data = {
|
||||||
"title": title,
|
"title": title,
|
||||||
"message": content,
|
"message": content,
|
||||||
"priority": push_config.get("GOTIFY_PRIORITY"),
|
"priority": GOTIFY_PRIORITY,
|
||||||
}
|
}
|
||||||
response = requests.post(url, data=data).json()
|
response = requests.post(url, data=data).json()
|
||||||
|
|
||||||
@@ -261,16 +293,16 @@ def gotify(title: str, content: str) -> None:
|
|||||||
print("gotify 推送失败!")
|
print("gotify 推送失败!")
|
||||||
|
|
||||||
|
|
||||||
def iGot(title: str, content: str) -> None:
|
def iGot(title: str, content: str, **kwargs) -> None:
|
||||||
"""
|
"""
|
||||||
使用 iGot 推送消息。
|
使用 iGot 推送消息。
|
||||||
"""
|
"""
|
||||||
if not push_config.get("IGOT_PUSH_KEY"):
|
if not (kwargs.get("IGOT_PUSH_KEY") or push_config.get("IGOT_PUSH_KEY")):
|
||||||
print("iGot 服务的 IGOT_PUSH_KEY 未设置!!\n取消推送")
|
print("iGot 服务的 IGOT_PUSH_KEY 未设置!!\n取消推送")
|
||||||
return
|
return
|
||||||
print("iGot 服务启动")
|
print("iGot 服务启动")
|
||||||
|
IGOT_PUSH_KEY = kwargs.get("IGOT_PUSH_KEY", push_config.get("IGOT_PUSH_KEY"))
|
||||||
url = f'https://push.hellyw.com/{push_config.get("IGOT_PUSH_KEY")}'
|
url = f"https://push.hellyw.com/{IGOT_PUSH_KEY}"
|
||||||
data = {"title": title, "content": content}
|
data = {"title": title, "content": content}
|
||||||
headers = {"Content-Type": "application/x-www-form-urlencoded"}
|
headers = {"Content-Type": "application/x-www-form-urlencoded"}
|
||||||
response = requests.post(url, data=data, headers=headers).json()
|
response = requests.post(url, data=data, headers=headers).json()
|
||||||
@@ -281,20 +313,21 @@ def iGot(title: str, content: str) -> None:
|
|||||||
print(f'iGot 推送失败!{response["errMsg"]}')
|
print(f'iGot 推送失败!{response["errMsg"]}')
|
||||||
|
|
||||||
|
|
||||||
def serverJ(title: str, content: str) -> None:
|
def serverJ(title: str, content: str, **kwargs) -> None:
|
||||||
"""
|
"""
|
||||||
通过 serverJ 推送消息。
|
通过 serverJ 推送消息。
|
||||||
"""
|
"""
|
||||||
if not push_config.get("PUSH_KEY"):
|
if not (kwargs.get("PUSH_KEY") or push_config.get("PUSH_KEY")):
|
||||||
print("serverJ 服务的 PUSH_KEY 未设置!!\n取消推送")
|
print("serverJ 服务的 PUSH_KEY 未设置!!\n取消推送")
|
||||||
return
|
return
|
||||||
print("serverJ 服务启动")
|
print("serverJ 服务启动")
|
||||||
|
PUSH_KEY = kwargs.get("PUSH_KEY", push_config.get("PUSH_KEY"))
|
||||||
|
|
||||||
data = {"text": title, "desp": content.replace("\n", "\n\n")}
|
data = {"text": title, "desp": content.replace("\n", "\n\n")}
|
||||||
if push_config.get("PUSH_KEY").find("SCT") != -1:
|
if PUSH_KEY.find("SCT") != -1:
|
||||||
url = f'https://sctapi.ftqq.com/{push_config.get("PUSH_KEY")}.send'
|
url = f"https://sctapi.ftqq.com/{PUSH_KEY}.send"
|
||||||
else:
|
else:
|
||||||
url = f'https://sc.ftqq.com/{push_config.get("PUSH_KEY")}.send'
|
url = f"https://sc.ftqq.com/{PUSH_KEY}.send"
|
||||||
response = requests.post(url, data=data).json()
|
response = requests.post(url, data=data).json()
|
||||||
|
|
||||||
if response.get("errno") == 0 or response.get("code") == 0:
|
if response.get("errno") == 0 or response.get("code") == 0:
|
||||||
@@ -303,23 +336,27 @@ def serverJ(title: str, content: str) -> None:
|
|||||||
print(f'serverJ 推送失败!错误码:{response["message"]}')
|
print(f'serverJ 推送失败!错误码:{response["message"]}')
|
||||||
|
|
||||||
|
|
||||||
def pushdeer(title: str, content: str) -> None:
|
def pushdeer(title: str, content: str, **kwargs) -> None:
|
||||||
"""
|
"""
|
||||||
通过PushDeer 推送消息
|
通过PushDeer 推送消息
|
||||||
"""
|
"""
|
||||||
if not push_config.get("DEER_KEY"):
|
if not (kwargs.get("DEER_KEY") or push_config.get("DEER_KEY")):
|
||||||
print("PushDeer 服务的 DEER_KEY 未设置!!\n取消推送")
|
print("PushDeer 服务的 DEER_KEY 未设置!!\n取消推送")
|
||||||
return
|
return
|
||||||
print("PushDeer 服务启动")
|
print("PushDeer 服务启动")
|
||||||
|
DEER_KEY = kwargs.get("DEER_KEY", push_config.get("DEER_KEY"))
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
"text": title,
|
"text": title,
|
||||||
"desp": content,
|
"desp": content,
|
||||||
"type": "markdown",
|
"type": "markdown",
|
||||||
"pushkey": push_config.get("DEER_KEY"),
|
"pushkey": DEER_KEY,
|
||||||
}
|
}
|
||||||
url = "https://api2.pushdeer.com/message/push"
|
url = "https://api2.pushdeer.com/message/push"
|
||||||
if push_config.get("DEER_URL"):
|
if push_config.get("DEER_URL"):
|
||||||
url = push_config.get("DEER_URL")
|
url = push_config.get("DEER_URL")
|
||||||
|
if kwargs.get("DEER_URL"):
|
||||||
|
url = kwargs.get("DEER_URL")
|
||||||
|
|
||||||
response = requests.post(url, data=data).json()
|
response = requests.post(url, data=data).json()
|
||||||
|
|
||||||
@@ -329,16 +366,26 @@ def pushdeer(title: str, content: str) -> None:
|
|||||||
print("PushDeer 推送失败!错误信息:", response)
|
print("PushDeer 推送失败!错误信息:", response)
|
||||||
|
|
||||||
|
|
||||||
def chat(title: str, content: str) -> None:
|
def chat(title: str, content: str, **kwargs) -> None:
|
||||||
"""
|
"""
|
||||||
通过Chat 推送消息
|
通过Chat 推送消息
|
||||||
"""
|
"""
|
||||||
if not push_config.get("CHAT_URL") or not push_config.get("CHAT_TOKEN"):
|
if not (
|
||||||
|
(kwargs.get("CHAT_URL") and kwargs.get("CHAT_TOKEN"))
|
||||||
|
or (push_config.get("CHAT_URL") and push_config.get("CHAT_TOKEN"))
|
||||||
|
):
|
||||||
print("chat 服务的 CHAT_URL或CHAT_TOKEN 未设置!!\n取消推送")
|
print("chat 服务的 CHAT_URL或CHAT_TOKEN 未设置!!\n取消推送")
|
||||||
return
|
return
|
||||||
print("chat 服务启动")
|
print("chat 服务启动")
|
||||||
|
if kwargs.get("CHAT_URL") and kwargs.get("CHAT_TOKEN"):
|
||||||
|
CHAT_URL = kwargs.get("CHAT_URL")
|
||||||
|
CHAT_TOKEN = kwargs.get("CHAT_TOKEN")
|
||||||
|
else:
|
||||||
|
CHAT_URL = push_config.get("CHAT_URL")
|
||||||
|
CHAT_TOKEN = push_config.get("CHAT_TOKEN")
|
||||||
|
|
||||||
data = "payload=" + json.dumps({"text": title + "\n" + content})
|
data = "payload=" + json.dumps({"text": title + "\n" + content})
|
||||||
url = push_config.get("CHAT_URL") + push_config.get("CHAT_TOKEN")
|
url = CHAT_URL + CHAT_TOKEN
|
||||||
response = requests.post(url, data=data)
|
response = requests.post(url, data=data)
|
||||||
|
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
@@ -347,21 +394,23 @@ def chat(title: str, content: str) -> None:
|
|||||||
print("Chat 推送失败!错误信息:", response)
|
print("Chat 推送失败!错误信息:", response)
|
||||||
|
|
||||||
|
|
||||||
def pushplus_bot(title: str, content: str) -> None:
|
def pushplus_bot(title: str, content: str, **kwargs) -> None:
|
||||||
"""
|
"""
|
||||||
通过 push+ 推送消息。
|
通过 push+ 推送消息。
|
||||||
"""
|
"""
|
||||||
if not push_config.get("PUSH_PLUS_TOKEN"):
|
if not (kwargs.get("PUSH_PLUS_TOKEN") or push_config.get("PUSH_PLUS_TOKEN")):
|
||||||
print("PUSHPLUS 服务的 PUSH_PLUS_TOKEN 未设置!!\n取消推送")
|
print("PUSHPLUS 服务的 PUSH_PLUS_TOKEN 未设置!!\n取消推送")
|
||||||
return
|
return
|
||||||
print("PUSHPLUS 服务启动")
|
print("PUSHPLUS 服务启动")
|
||||||
|
PUSH_PLUS_TOKEN = kwargs.get("PUSH_PLUS_TOKEN", push_config.get("PUSH_PLUS_TOKEN"))
|
||||||
|
PUSH_PLUS_USER = kwargs.get("PUSH_PLUS_USER", push_config.get("PUSH_PLUS_USER"))
|
||||||
|
|
||||||
url = "http://www.pushplus.plus/send"
|
url = "http://www.pushplus.plus/send"
|
||||||
data = {
|
data = {
|
||||||
"token": push_config.get("PUSH_PLUS_TOKEN"),
|
"token": PUSH_PLUS_TOKEN,
|
||||||
"title": title,
|
"title": title,
|
||||||
"content": content,
|
"content": content,
|
||||||
"topic": push_config.get("PUSH_PLUS_USER"),
|
"topic": PUSH_PLUS_USER,
|
||||||
}
|
}
|
||||||
body = json.dumps(data).encode(encoding="utf-8")
|
body = json.dumps(data).encode(encoding="utf-8")
|
||||||
headers = {"Content-Type": "application/json"}
|
headers = {"Content-Type": "application/json"}
|
||||||
@@ -382,16 +431,25 @@ def pushplus_bot(title: str, content: str) -> None:
|
|||||||
print("PUSHPLUS 推送失败!")
|
print("PUSHPLUS 推送失败!")
|
||||||
|
|
||||||
|
|
||||||
def qmsg_bot(title: str, content: str) -> None:
|
def qmsg_bot(title: str, content: str, **kwargs) -> None:
|
||||||
"""
|
"""
|
||||||
使用 qmsg 推送消息。
|
使用 qmsg 推送消息。
|
||||||
"""
|
"""
|
||||||
if not push_config.get("QMSG_KEY") or not push_config.get("QMSG_TYPE"):
|
if not (
|
||||||
|
(kwargs.get("QMSG_KEY") and kwargs.get("QMSG_TYPE"))
|
||||||
|
or (push_config.get("QMSG_KEY") and push_config.get("QMSG_TYPE"))
|
||||||
|
):
|
||||||
print("qmsg 的 QMSG_KEY 或者 QMSG_TYPE 未设置!!\n取消推送")
|
print("qmsg 的 QMSG_KEY 或者 QMSG_TYPE 未设置!!\n取消推送")
|
||||||
return
|
return
|
||||||
print("qmsg 服务启动")
|
print("qmsg 服务启动")
|
||||||
|
if kwargs.get("QMSG_KEY") and kwargs.get("QMSG_TYPE"):
|
||||||
|
QMSG_KEY = kwargs.get("QMSG_KEY")
|
||||||
|
QMSG_TYPE = kwargs.get("QMSG_TYPE")
|
||||||
|
else:
|
||||||
|
QMSG_KEY = push_config.get("QMSG_KEY")
|
||||||
|
QMSG_TYPE = push_config.get("QMSG_TYPE")
|
||||||
|
|
||||||
url = f'https://qmsg.zendee.cn/{push_config.get("QMSG_TYPE")}/{push_config.get("QMSG_KEY")}'
|
url = f"https://qmsg.zendee.cn/{QMSG_TYPE}/{QMSG_KEY}"
|
||||||
payload = {"msg": f'{title}\n\n{content.replace("----", "-")}'.encode("utf-8")}
|
payload = {"msg": f'{title}\n\n{content.replace("----", "-")}'.encode("utf-8")}
|
||||||
response = requests.post(url=url, params=payload).json()
|
response = requests.post(url=url, params=payload).json()
|
||||||
|
|
||||||
@@ -401,14 +459,15 @@ def qmsg_bot(title: str, content: str) -> None:
|
|||||||
print(f'qmsg 推送失败!{response["reason"]}')
|
print(f'qmsg 推送失败!{response["reason"]}')
|
||||||
|
|
||||||
|
|
||||||
def wecom_app(title: str, content: str) -> None:
|
def wecom_app(title: str, content: str, **kwargs) -> None:
|
||||||
"""
|
"""
|
||||||
通过 企业微信 APP 推送消息。
|
通过 企业微信 APP 推送消息。
|
||||||
"""
|
"""
|
||||||
if not push_config.get("QYWX_AM"):
|
if not (kwargs.get("QYWX_AM") or push_config.get("QYWX_AM")):
|
||||||
print("QYWX_AM 未设置!!\n取消推送")
|
print("QYWX_AM 未设置!!\n取消推送")
|
||||||
return
|
return
|
||||||
QYWX_AM_AY = re.split(",", push_config.get("QYWX_AM"))
|
QYWX_AM = kwargs.get("QYWX_AM", push_config.get("QYWX_AM"))
|
||||||
|
QYWX_AM_AY = re.split(",", QYWX_AM)
|
||||||
if 4 < len(QYWX_AM_AY) > 5:
|
if 4 < len(QYWX_AM_AY) > 5:
|
||||||
print("QYWX_AM 设置错误!!\n取消推送")
|
print("QYWX_AM 设置错误!!\n取消推送")
|
||||||
return
|
return
|
||||||
@@ -498,20 +557,23 @@ class WeCom:
|
|||||||
return respone["errmsg"]
|
return respone["errmsg"]
|
||||||
|
|
||||||
|
|
||||||
def wecom_bot(title: str, content: str) -> None:
|
def wecom_bot(title: str, content: str, **kwargs) -> None:
|
||||||
"""
|
"""
|
||||||
通过 企业微信机器人 推送消息。
|
通过 企业微信机器人 推送消息。
|
||||||
"""
|
"""
|
||||||
if not push_config.get("QYWX_KEY"):
|
if not (kwargs.get("QYWX_KEY") or push_config.get("QYWX_KEY")):
|
||||||
print("企业微信机器人 服务的 QYWX_KEY 未设置!!\n取消推送")
|
print("企业微信机器人 服务的 QYWX_KEY 未设置!!\n取消推送")
|
||||||
return
|
return
|
||||||
print("企业微信机器人服务启动")
|
print("企业微信机器人服务启动")
|
||||||
|
QYWX_KEY = kwargs.get("QYWX_KEY", push_config.get("QYWX_KEY"))
|
||||||
|
|
||||||
origin = "https://qyapi.weixin.qq.com"
|
origin = "https://qyapi.weixin.qq.com"
|
||||||
if push_config.get("QYWX_ORIGIN"):
|
if push_config.get("QYWX_ORIGIN"):
|
||||||
origin = push_config.get("QYWX_ORIGIN")
|
origin = push_config.get("QYWX_ORIGIN")
|
||||||
|
if kwargs.get("QYWX_ORIGIN"):
|
||||||
|
origin = kwargs.get("QYWX_ORIGIN")
|
||||||
|
|
||||||
url = f"{origin}/cgi-bin/webhook/send?key={push_config.get('QYWX_KEY')}"
|
url = f"{origin}/cgi-bin/webhook/send?key={QYWX_KEY}"
|
||||||
headers = {"Content-Type": "application/json;charset=utf-8"}
|
headers = {"Content-Type": "application/json;charset=utf-8"}
|
||||||
data = {"msgtype": "text", "text": {"content": f"{title}\n\n{content}"}}
|
data = {"msgtype": "text", "text": {"content": f"{title}\n\n{content}"}}
|
||||||
response = requests.post(
|
response = requests.post(
|
||||||
@@ -524,40 +586,53 @@ def wecom_bot(title: str, content: str) -> None:
|
|||||||
print("企业微信机器人推送失败!")
|
print("企业微信机器人推送失败!")
|
||||||
|
|
||||||
|
|
||||||
def telegram_bot(title: str, content: str) -> None:
|
def telegram_bot(title: str, content: str, **kwargs) -> None:
|
||||||
"""
|
"""
|
||||||
使用 telegram 机器人 推送消息。
|
使用 telegram 机器人 推送消息。
|
||||||
"""
|
"""
|
||||||
if not push_config.get("TG_BOT_TOKEN") or not push_config.get("TG_USER_ID"):
|
if not (
|
||||||
print("tg 服务的 bot_token 或者 user_id 未设置!!\n取消推送")
|
(kwargs.get("TG_BOT_TOKEN") and kwargs.get("TG_USER_ID"))
|
||||||
|
or (push_config.get("TG_BOT_TOKEN") and push_config.get("TG_USER_ID"))
|
||||||
|
):
|
||||||
|
print("tg 服务的 TG_BOT_TOKEN 或者 TG_USER_ID 未设置!!\n取消推送")
|
||||||
return
|
return
|
||||||
print("tg 服务启动")
|
print("tg 服务启动")
|
||||||
|
if kwargs.get("TG_BOT_TOKEN") and kwargs.get("TG_USER_ID"):
|
||||||
if push_config.get("TG_API_HOST"):
|
TG_BOT_TOKEN = kwargs.get("TG_BOT_TOKEN")
|
||||||
url = f"{push_config.get('TG_API_HOST')}/bot{push_config.get('TG_BOT_TOKEN')}/sendMessage"
|
TG_USER_ID = kwargs.get("TG_USER_ID")
|
||||||
else:
|
else:
|
||||||
url = (
|
TG_BOT_TOKEN = push_config.get("TG_BOT_TOKEN")
|
||||||
f"https://api.telegram.org/bot{push_config.get('TG_BOT_TOKEN')}/sendMessage"
|
TG_USER_ID = push_config.get("TG_USER_ID")
|
||||||
)
|
|
||||||
|
if kwargs.get("TG_API_HOST") or push_config.get("TG_API_HOST"):
|
||||||
|
TG_API_HOST = kwargs.get("TG_API_HOST", push_config.get("TG_API_HOST"))
|
||||||
|
url = f"{TG_API_HOST}/bot{TG_BOT_TOKEN}/sendMessage"
|
||||||
|
else:
|
||||||
|
url = f"https://api.telegram.org/bot{TG_BOT_TOKEN}/sendMessage"
|
||||||
headers = {"Content-Type": "application/x-www-form-urlencoded"}
|
headers = {"Content-Type": "application/x-www-form-urlencoded"}
|
||||||
payload = {
|
payload = {
|
||||||
"chat_id": str(push_config.get("TG_USER_ID")),
|
"chat_id": str(TG_USER_ID),
|
||||||
"text": f"{title}\n\n{content}",
|
"text": f"{title}\n\n{content}",
|
||||||
"disable_web_page_preview": "true",
|
"disable_web_page_preview": "true",
|
||||||
}
|
}
|
||||||
proxies = None
|
proxies = None
|
||||||
if push_config.get("TG_PROXY_HOST") and push_config.get("TG_PROXY_PORT"):
|
if not (
|
||||||
if push_config.get("TG_PROXY_AUTH") is not None and "@" not in push_config.get(
|
(kwargs.get("TG_PROXY_HOST") and kwargs.get("TG_PROXY_PORT"))
|
||||||
"TG_PROXY_HOST"
|
or (push_config.get("TG_PROXY_HOST") and push_config.get("TG_PROXY_PORT"))
|
||||||
):
|
):
|
||||||
push_config["TG_PROXY_HOST"] = (
|
if kwargs.get("TG_PROXY_HOST") and kwargs.get("TG_PROXY_PORT"):
|
||||||
push_config.get("TG_PROXY_AUTH")
|
TG_PROXY_HOST = kwargs.get("TG_PROXY_HOST")
|
||||||
+ "@"
|
TG_PROXY_PORT = kwargs.get("TG_PROXY_PORT")
|
||||||
+ push_config.get("TG_PROXY_HOST")
|
else:
|
||||||
|
TG_PROXY_HOST = kwargs.get("TG_PROXY_HOST")
|
||||||
|
TG_PROXY_PORT = kwargs.get("TG_PROXY_PORT")
|
||||||
|
if kwargs.get("TG_PROXY_AUTH") or push_config.get("TG_PROXY_AUTH"):
|
||||||
|
TG_PROXY_AUTH = kwargs.get(
|
||||||
|
"TG_PROXY_AUTH", push_config.get("TG_PROXY_AUTH")
|
||||||
)
|
)
|
||||||
proxyStr = "http://{}:{}".format(
|
if TG_PROXY_AUTH is not None and "@" not in TG_PROXY_HOST:
|
||||||
push_config.get("TG_PROXY_HOST"), push_config.get("TG_PROXY_PORT")
|
TG_PROXY_HOST = TG_PROXY_AUTH + "@" + TG_PROXY_HOST
|
||||||
)
|
proxyStr = "http://{}:{}".format(TG_PROXY_HOST, TG_PROXY_PORT)
|
||||||
proxies = {"http": proxyStr, "https": proxyStr}
|
proxies = {"http": proxyStr, "https": proxyStr}
|
||||||
response = requests.post(
|
response = requests.post(
|
||||||
url=url, headers=headers, params=payload, proxies=proxies
|
url=url, headers=headers, params=payload, proxies=proxies
|
||||||
@@ -569,31 +644,51 @@ def telegram_bot(title: str, content: str) -> None:
|
|||||||
print("tg 推送失败!")
|
print("tg 推送失败!")
|
||||||
|
|
||||||
|
|
||||||
def aibotk(title: str, content: str) -> None:
|
def aibotk(title: str, content: str, **kwargs) -> None:
|
||||||
"""
|
"""
|
||||||
使用 智能微秘书 推送消息。
|
使用 智能微秘书 推送消息。
|
||||||
"""
|
"""
|
||||||
if (
|
if not (
|
||||||
not push_config.get("AIBOTK_KEY")
|
(
|
||||||
or not push_config.get("AIBOTK_TYPE")
|
kwargs.get("AIBOTK_KEY")
|
||||||
or not push_config.get("AIBOTK_NAME")
|
and kwargs.get("AIBOTK_TYPE")
|
||||||
|
and kwargs.get("AIBOTK_NAME")
|
||||||
|
)
|
||||||
|
or (
|
||||||
|
push_config.get("AIBOTK_KEY")
|
||||||
|
and push_config.get("AIBOTK_TYPE")
|
||||||
|
and push_config.get("AIBOTK_NAME")
|
||||||
|
)
|
||||||
):
|
):
|
||||||
print("智能微秘书 的 AIBOTK_KEY 或者 AIBOTK_TYPE 或者 AIBOTK_NAME 未设置!!\n取消推送")
|
print(
|
||||||
|
"智能微秘书 的 AIBOTK_KEY 或者 AIBOTK_TYPE 或者 AIBOTK_NAME 未设置!!\n取消推送"
|
||||||
|
)
|
||||||
return
|
return
|
||||||
print("智能微秘书 服务启动")
|
print("智能微秘书 服务启动")
|
||||||
|
if (
|
||||||
if push_config.get("AIBOTK_TYPE") == "room":
|
kwargs.get("AIBOTK_KEY")
|
||||||
|
and kwargs.get("AIBOTK_TYPE")
|
||||||
|
and kwargs.get("AIBOTK_NAME")
|
||||||
|
):
|
||||||
|
AIBOTK_KEY = kwargs.get("AIBOTK_KEY")
|
||||||
|
AIBOTK_TYPE = kwargs.get("AIBOTK_TYPE")
|
||||||
|
AIBOTK_NAME = kwargs.get("AIBOTK_NAME")
|
||||||
|
else:
|
||||||
|
AIBOTK_KEY = push_config.get("AIBOTK_KEY")
|
||||||
|
AIBOTK_TYPE = push_config.get("AIBOTK_TYPE")
|
||||||
|
AIBOTK_NAME = push_config.get("AIBOTK_NAME")
|
||||||
|
if AIBOTK_TYPE == "room":
|
||||||
url = "https://api-bot.aibotk.com/openapi/v1/chat/room"
|
url = "https://api-bot.aibotk.com/openapi/v1/chat/room"
|
||||||
data = {
|
data = {
|
||||||
"apiKey": push_config.get("AIBOTK_KEY"),
|
"apiKey": AIBOTK_KEY,
|
||||||
"roomName": push_config.get("AIBOTK_NAME"),
|
"roomName": AIBOTK_NAME,
|
||||||
"message": {"type": 1, "content": f"【青龙快讯】\n\n{title}\n{content}"},
|
"message": {"type": 1, "content": f"【青龙快讯】\n\n{title}\n{content}"},
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
url = "https://api-bot.aibotk.com/openapi/v1/chat/contact"
|
url = "https://api-bot.aibotk.com/openapi/v1/chat/contact"
|
||||||
data = {
|
data = {
|
||||||
"apiKey": push_config.get("AIBOTK_KEY"),
|
"apiKey": AIBOTK_KEY,
|
||||||
"name": push_config.get("AIBOTK_NAME"),
|
"name": AIBOTK_NAME,
|
||||||
"message": {"type": 1, "content": f"【青龙快讯】\n\n{title}\n{content}"},
|
"message": {"type": 1, "content": f"【青龙快讯】\n\n{title}\n{content}"},
|
||||||
}
|
}
|
||||||
body = json.dumps(data).encode(encoding="utf-8")
|
body = json.dumps(data).encode(encoding="utf-8")
|
||||||
@@ -606,50 +701,75 @@ def aibotk(title: str, content: str) -> None:
|
|||||||
print(f'智能微秘书 推送失败!{response["error"]}')
|
print(f'智能微秘书 推送失败!{response["error"]}')
|
||||||
|
|
||||||
|
|
||||||
def smtp(title: str, content: str) -> None:
|
def smtp(title: str, content: str, **kwargs) -> None:
|
||||||
"""
|
"""
|
||||||
使用 SMTP 邮件 推送消息。
|
使用 SMTP 邮件 推送消息。
|
||||||
"""
|
"""
|
||||||
if (
|
if not (
|
||||||
not push_config.get("SMTP_SERVER")
|
(
|
||||||
or not push_config.get("SMTP_SSL")
|
kwargs.get("SMTP_SERVER")
|
||||||
or not push_config.get("SMTP_EMAIL")
|
and kwargs.get("SMTP_SSL")
|
||||||
or not push_config.get("SMTP_PASSWORD")
|
and kwargs.get("SMTP_EMAIL")
|
||||||
or not push_config.get("SMTP_NAME")
|
and kwargs.get("SMTP_PASSWORD")
|
||||||
|
and kwargs.get("SMTP_NAME")
|
||||||
|
)
|
||||||
|
or (
|
||||||
|
push_config.get("SMTP_SERVER")
|
||||||
|
and push_config.get("SMTP_SSL")
|
||||||
|
and push_config.get("SMTP_EMAIL")
|
||||||
|
and push_config.get("SMTP_PASSWORD")
|
||||||
|
and push_config.get("SMTP_NAME")
|
||||||
|
)
|
||||||
):
|
):
|
||||||
print(
|
print(
|
||||||
"SMTP 邮件 的 SMTP_SERVER 或者 SMTP_SSL 或者 SMTP_EMAIL 或者 SMTP_PASSWORD 或者 SMTP_NAME 未设置!!\n取消推送"
|
"SMTP 邮件 的 SMTP_SERVER 或者 SMTP_SSL 或者 SMTP_EMAIL 或者 SMTP_PASSWORD 或者 SMTP_NAME 未设置!!\n取消推送"
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
print("SMTP 邮件 服务启动")
|
print("SMTP 邮件 服务启动")
|
||||||
|
if (
|
||||||
|
kwargs.get("SMTP_SERVER")
|
||||||
|
and kwargs.get("SMTP_SSL")
|
||||||
|
and kwargs.get("SMTP_EMAIL")
|
||||||
|
and kwargs.get("SMTP_PASSWORD")
|
||||||
|
and kwargs.get("SMTP_NAME")
|
||||||
|
):
|
||||||
|
SMTP_SERVER = kwargs.get("SMTP_SERVER")
|
||||||
|
SMTP_SSL = kwargs.get("SMTP_SSL")
|
||||||
|
SMTP_EMAIL = kwargs.get("SMTP_EMAIL")
|
||||||
|
SMTP_PASSWORD = kwargs.get("SMTP_PASSWORD")
|
||||||
|
SMTP_NAME = kwargs.get("SMTP_NAME")
|
||||||
|
else:
|
||||||
|
SMTP_SERVER = push_config.get("SMTP_SERVER")
|
||||||
|
SMTP_SSL = push_config.get("SMTP_SSL")
|
||||||
|
SMTP_EMAIL = push_config.get("SMTP_EMAIL")
|
||||||
|
SMTP_PASSWORD = push_config.get("SMTP_PASSWORD")
|
||||||
|
SMTP_NAME = push_config.get("SMTP_NAME")
|
||||||
|
|
||||||
message = MIMEText(content, "plain", "utf-8")
|
message = MIMEText(content, "plain", "utf-8")
|
||||||
message["From"] = formataddr(
|
message["From"] = formataddr(
|
||||||
(
|
(
|
||||||
Header(push_config.get("SMTP_NAME"), "utf-8").encode(),
|
Header(SMTP_NAME, "utf-8").encode(),
|
||||||
push_config.get("SMTP_EMAIL"),
|
SMTP_EMAIL,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
message["To"] = formataddr(
|
message["To"] = formataddr(
|
||||||
(
|
(
|
||||||
Header(push_config.get("SMTP_NAME"), "utf-8").encode(),
|
Header(SMTP_NAME, "utf-8").encode(),
|
||||||
push_config.get("SMTP_EMAIL"),
|
SMTP_EMAIL,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
message["Subject"] = Header(title, "utf-8")
|
message["Subject"] = Header(title, "utf-8")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
smtp_server = (
|
smtp_server = (
|
||||||
smtplib.SMTP_SSL(push_config.get("SMTP_SERVER"))
|
smtplib.SMTP_SSL(SMTP_SERVER)
|
||||||
if push_config.get("SMTP_SSL") == "true"
|
if SMTP_SSL == "true"
|
||||||
else smtplib.SMTP(push_config.get("SMTP_SERVER"))
|
else smtplib.SMTP(SMTP_SERVER)
|
||||||
)
|
|
||||||
smtp_server.login(
|
|
||||||
push_config.get("SMTP_EMAIL"), push_config.get("SMTP_PASSWORD")
|
|
||||||
)
|
)
|
||||||
|
smtp_server.login(SMTP_EMAIL, SMTP_PASSWORD)
|
||||||
smtp_server.sendmail(
|
smtp_server.sendmail(
|
||||||
push_config.get("SMTP_EMAIL"),
|
SMTP_EMAIL,
|
||||||
push_config.get("SMTP_EMAIL"),
|
SMTP_EMAIL,
|
||||||
message.as_bytes(),
|
message.as_bytes(),
|
||||||
)
|
)
|
||||||
smtp_server.close()
|
smtp_server.close()
|
||||||
@@ -658,16 +778,17 @@ def smtp(title: str, content: str) -> None:
|
|||||||
print(f"SMTP 邮件 推送失败!{e}")
|
print(f"SMTP 邮件 推送失败!{e}")
|
||||||
|
|
||||||
|
|
||||||
def pushme(title: str, content: str) -> None:
|
def pushme(title: str, content: str, **kwargs) -> None:
|
||||||
"""
|
"""
|
||||||
使用 PushMe 推送消息。
|
使用 PushMe 推送消息。
|
||||||
"""
|
"""
|
||||||
if not push_config.get("PUSHME_KEY"):
|
if not (kwargs.get("PUSHME_KEY") or push_config.get("PUSHME_KEY")):
|
||||||
print("PushMe 服务的 PUSHME_KEY 未设置!!\n取消推送")
|
print("PushMe 服务的 PUSHME_KEY 未设置!!\n取消推送")
|
||||||
return
|
return
|
||||||
print("PushMe 服务启动")
|
print("PushMe 服务启动")
|
||||||
|
PUSHME_KEY = kwargs.get("PUSHME_KEY", push_config.get("PUSHME_KEY"))
|
||||||
|
|
||||||
url = f'https://push.i-i.me/?push_key={push_config.get("PUSHME_KEY")}'
|
url = f"https://push.i-i.me/?push_key={PUSHME_KEY}"
|
||||||
data = {
|
data = {
|
||||||
"title": title,
|
"title": title,
|
||||||
"content": content,
|
"content": content,
|
||||||
@@ -680,27 +801,45 @@ def pushme(title: str, content: str) -> None:
|
|||||||
print(f"PushMe 推送失败!{response.status_code} {response.text}")
|
print(f"PushMe 推送失败!{response.status_code} {response.text}")
|
||||||
|
|
||||||
|
|
||||||
def chronocat(title: str, content: str) -> None:
|
def chronocat(title: str, content: str, **kwargs) -> None:
|
||||||
"""
|
"""
|
||||||
使用 CHRONOCAT 推送消息。
|
使用 CHRONOCAT 推送消息。
|
||||||
"""
|
"""
|
||||||
if (
|
if not (
|
||||||
not push_config.get("CHRONOCAT_URL")
|
(
|
||||||
or not push_config.get("CHRONOCAT_QQ")
|
push_config.get("CHRONOCAT_URL")
|
||||||
or not push_config.get("CHRONOCAT_TOKEN")
|
and push_config.get("CHRONOCAT_QQ")
|
||||||
|
and push_config.get("CHRONOCAT_TOKEN")
|
||||||
|
)
|
||||||
|
or (
|
||||||
|
push_config.get("CHRONOCAT_URL")
|
||||||
|
and push_config.get("CHRONOCAT_QQ")
|
||||||
|
and push_config.get("CHRONOCAT_TOKEN")
|
||||||
|
)
|
||||||
):
|
):
|
||||||
print("CHRONOCAT 服务的 CHRONOCAT_URL 或 CHRONOCAT_QQ 未设置!!\n取消推送")
|
print("CHRONOCAT 服务的 CHRONOCAT_URL 或 CHRONOCAT_QQ 未设置!!\n取消推送")
|
||||||
return
|
return
|
||||||
|
|
||||||
print("CHRONOCAT 服务启动")
|
print("CHRONOCAT 服务启动")
|
||||||
|
if (
|
||||||
|
kwargs.get("CHRONOCAT_URL")
|
||||||
|
and kwargs.get("CHRONOCAT_QQ")
|
||||||
|
and kwargs.get("CHRONOCAT_TOKEN")
|
||||||
|
):
|
||||||
|
CHRONOCAT_URL = kwargs.get("CHRONOCAT_URL")
|
||||||
|
CHRONOCAT_QQ = kwargs.get("CHRONOCAT_QQ")
|
||||||
|
CHRONOCAT_TOKEN = kwargs.get("CHRONOCAT_TOKEN")
|
||||||
|
else:
|
||||||
|
CHRONOCAT_URL = push_config.get("CHRONOCAT_URL")
|
||||||
|
CHRONOCAT_QQ = push_config.get("CHRONOCAT_QQ")
|
||||||
|
CHRONOCAT_TOKEN = push_config.get("CHRONOCAT_TOKEN")
|
||||||
|
|
||||||
user_ids = re.findall(r"user_id=(\d+)", push_config.get("CHRONOCAT_QQ"))
|
user_ids = re.findall(r"user_id=(\d+)", CHRONOCAT_QQ)
|
||||||
group_ids = re.findall(r"group_id=(\d+)", push_config.get("CHRONOCAT_QQ"))
|
group_ids = re.findall(r"group_id=(\d+)", CHRONOCAT_QQ)
|
||||||
|
|
||||||
url = f'{push_config.get("CHRONOCAT_URL")}/api/message/send'
|
url = f"{CHRONOCAT_URL}/api/message/send"
|
||||||
headers = {
|
headers = {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"Authorization": f'Bearer {push_config.get("CHRONOCAT_TOKEN")}',
|
"Authorization": f"Bearer {CHRONOCAT_TOKEN}",
|
||||||
}
|
}
|
||||||
|
|
||||||
for chat_type, ids in [(1, user_ids), (2, group_ids)]:
|
for chat_type, ids in [(1, user_ids), (2, group_ids)]:
|
||||||
@@ -748,29 +887,26 @@ def parse_headers(headers):
|
|||||||
return parsed
|
return parsed
|
||||||
|
|
||||||
|
|
||||||
def parse_body(body, content_type):
|
def parse_string(input_string, value_format_fn=None):
|
||||||
|
matches = {}
|
||||||
|
pattern = r"(\w+):\s*((?:(?!\n\w+:).)*)"
|
||||||
|
regex = re.compile(pattern)
|
||||||
|
for match in regex.finditer(input_string):
|
||||||
|
key, value = match.group(1).strip(), match.group(2).strip()
|
||||||
|
try:
|
||||||
|
value = value_format_fn(value) if value_format_fn else value
|
||||||
|
json_value = json.loads(value)
|
||||||
|
matches[key] = json_value
|
||||||
|
except:
|
||||||
|
matches[key] = value
|
||||||
|
return matches
|
||||||
|
|
||||||
|
|
||||||
|
def parse_body(body, content_type, value_format_fn=None):
|
||||||
if not body or content_type == "text/plain":
|
if not body or content_type == "text/plain":
|
||||||
return body
|
return body
|
||||||
|
|
||||||
parsed = {}
|
parsed = parse_string(input_string, value_format_fn)
|
||||||
lines = body.split("\n")
|
|
||||||
|
|
||||||
for line in lines:
|
|
||||||
i = line.find(":")
|
|
||||||
if i == -1:
|
|
||||||
continue
|
|
||||||
|
|
||||||
key = line[:i].strip()
|
|
||||||
val = line[i + 1 :].strip()
|
|
||||||
|
|
||||||
if not key or key in parsed:
|
|
||||||
continue
|
|
||||||
|
|
||||||
try:
|
|
||||||
json_value = json.loads(val)
|
|
||||||
parsed[key] = json_value
|
|
||||||
except:
|
|
||||||
parsed[key] = val
|
|
||||||
|
|
||||||
if content_type == "application/x-www-form-urlencoded":
|
if content_type == "application/x-www-form-urlencoded":
|
||||||
data = urlencode(parsed, doseq=True)
|
data = urlencode(parsed, doseq=True)
|
||||||
@@ -811,16 +947,19 @@ def custom_notify(title: str, content: str) -> None:
|
|||||||
WEBHOOK_BODY = push_config.get("WEBHOOK_BODY")
|
WEBHOOK_BODY = push_config.get("WEBHOOK_BODY")
|
||||||
WEBHOOK_HEADERS = push_config.get("WEBHOOK_HEADERS")
|
WEBHOOK_HEADERS = push_config.get("WEBHOOK_HEADERS")
|
||||||
|
|
||||||
formatUrl, formatBody = format_notify_content(
|
if "$title" not in WEBHOOK_URL and "$title" not in WEBHOOK_BODY:
|
||||||
WEBHOOK_URL, WEBHOOK_BODY, title, content
|
|
||||||
)
|
|
||||||
|
|
||||||
if not formatUrl and not formatBody:
|
|
||||||
print("请求头或者请求体中必须包含 $title 和 $content")
|
print("请求头或者请求体中必须包含 $title 和 $content")
|
||||||
return
|
return
|
||||||
|
|
||||||
headers = parse_headers(WEBHOOK_HEADERS)
|
headers = parse_headers(WEBHOOK_HEADERS)
|
||||||
body = parse_body(formatBody, WEBHOOK_CONTENT_TYPE)
|
body = parse_body(
|
||||||
|
WEBHOOK_BODY,
|
||||||
|
WEBHOOK_CONTENT_TYPE,
|
||||||
|
lambda v: v.replace("$title", title).replace("$content", content),
|
||||||
|
)
|
||||||
|
formatted_url = WEBHOOK_URL.replace(
|
||||||
|
"$title", urllib.parse.quote_plus(title)
|
||||||
|
).replace("$content", urllib.parse.quote_plus(content))
|
||||||
response = requests.request(
|
response = requests.request(
|
||||||
method=WEBHOOK_METHOD, url=formatUrl, headers=headers, timeout=15, data=body
|
method=WEBHOOK_METHOD, url=formatUrl, headers=headers, timeout=15, data=body
|
||||||
)
|
)
|
||||||
@@ -898,7 +1037,7 @@ def add_notify_function():
|
|||||||
notify_function.append(custom_notify)
|
notify_function.append(custom_notify)
|
||||||
|
|
||||||
|
|
||||||
def send(title: str, content: str) -> None:
|
def send(title: str, content: str, **kwargs) -> None:
|
||||||
if not content:
|
if not content:
|
||||||
print(f"{title} 推送内容为空!")
|
print(f"{title} 推送内容为空!")
|
||||||
return
|
return
|
||||||
@@ -915,7 +1054,9 @@ def send(title: str, content: str) -> None:
|
|||||||
|
|
||||||
add_notify_function()
|
add_notify_function()
|
||||||
ts = [
|
ts = [
|
||||||
threading.Thread(target=mode, args=(title, content), name=mode.__name__)
|
threading.Thread(
|
||||||
|
target=mode, args=(title, content), kwargs=kwargs, name=mode.__name__
|
||||||
|
)
|
||||||
for mode in notify_function
|
for mode in notify_function
|
||||||
]
|
]
|
||||||
[t.start() for t in ts]
|
[t.start() for t in ts]
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ main() {
|
|||||||
check_ql
|
check_ql
|
||||||
check_nginx
|
check_nginx
|
||||||
check_pm2
|
check_pm2
|
||||||
|
reload_update
|
||||||
reload_pm2
|
reload_pm2
|
||||||
echo -e "\n=====> 检测结束\n"
|
echo -e "\n=====> 检测结束\n"
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-1
@@ -293,7 +293,7 @@ git_clone_scripts() {
|
|||||||
|
|
||||||
set_proxy "$proxy"
|
set_proxy "$proxy"
|
||||||
|
|
||||||
git clone --depth=1 $part_cmd $url $dir
|
git clone -q --depth=1 $part_cmd $url $dir
|
||||||
exit_status=$?
|
exit_status=$?
|
||||||
|
|
||||||
unset_proxy
|
unset_proxy
|
||||||
@@ -305,6 +305,11 @@ random_range() {
|
|||||||
echo $((RANDOM % ($end - $beg) + $beg))
|
echo $((RANDOM % ($end - $beg) + $beg))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delete_pm2() {
|
||||||
|
cd $dir_root
|
||||||
|
pm2 delete ecosystem.config.js
|
||||||
|
}
|
||||||
|
|
||||||
reload_pm2() {
|
reload_pm2() {
|
||||||
cd $dir_root
|
cd $dir_root
|
||||||
restore_env_vars
|
restore_env_vars
|
||||||
@@ -312,6 +317,13 @@ reload_pm2() {
|
|||||||
pm2 startOrGracefulReload ecosystem.config.js
|
pm2 startOrGracefulReload ecosystem.config.js
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reload_update() {
|
||||||
|
cd $dir_root
|
||||||
|
restore_env_vars
|
||||||
|
pm2 flush &>/dev/null
|
||||||
|
pm2 startOrGracefulReload other.config.js
|
||||||
|
}
|
||||||
|
|
||||||
diff_time() {
|
diff_time() {
|
||||||
local format="$1"
|
local format="$1"
|
||||||
local begin_time="$2"
|
local begin_time="$2"
|
||||||
|
|||||||
+34
-22
@@ -34,7 +34,6 @@ output_list_add_drop() {
|
|||||||
if [[ -s $list ]]; then
|
if [[ -s $list ]]; then
|
||||||
echo -e "检测到有${type}的定时任务:"
|
echo -e "检测到有${type}的定时任务:"
|
||||||
cat $list
|
cat $list
|
||||||
echo
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,7 +44,7 @@ del_cron() {
|
|||||||
local path=$2
|
local path=$2
|
||||||
local detail=""
|
local detail=""
|
||||||
local ids=""
|
local ids=""
|
||||||
echo -e "开始尝试自动删除失效的定时任务..."
|
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 | 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 | awk -F " " '{print $1}')
|
||||||
if [[ $ids ]]; then
|
if [[ $ids ]]; then
|
||||||
@@ -76,7 +75,7 @@ del_cron() {
|
|||||||
add_cron() {
|
add_cron() {
|
||||||
local list_add=$1
|
local list_add=$1
|
||||||
local path=$2
|
local path=$2
|
||||||
echo -e "开始尝试自动添加定时任务..."
|
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
|
||||||
@@ -86,19 +85,20 @@ add_cron() {
|
|||||||
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 2>/dev/null |
|
||||||
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
|
}" 2>/dev/null | sort -u | head -1
|
||||||
)
|
)
|
||||||
cron_name=$(grep "new Env" $file | awk -F "\(" '{print $2}' | awk -F "\)" '{print $1}' | sed 's:.*\('\''\|"\)\([^"'\'']*\)\('\''\|"\).*:\2:' | sed 's:"::g' | sed "s:'::g" | head -1)
|
|
||||||
[[ -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:$SUB_ID")
|
cron_name=$(grep "new Env" $file | awk -F "\(" '{print $2}' | awk -F "\)" '{print $1}' | sed 's:.*\('\''\|"\)\([^"'\'']*\)\('\''\|"\).*:\2:' | sed 's:"::g' | sed "s:'::g" | head -1)
|
||||||
|
[[ -z $cron_name ]] && cron_name=$(grep "name:" $file | awk -F ":" '{print $2}' | head -1 | xargs)
|
||||||
|
[[ -z $cron_name ]] && cron_name=$(basename "$file_name")
|
||||||
|
result=$(add_cron_api "${cron_line}:${cmd_task} ${file}:${cron_name}:${SUB_ID}")
|
||||||
echo -e "$result"
|
echo -e "$result"
|
||||||
if [[ $detail ]]; then
|
if [[ $detail ]]; then
|
||||||
detail="${detail}${result}\n"
|
detail="${detail}${result}\n"
|
||||||
@@ -135,10 +135,10 @@ update_repo() {
|
|||||||
git_clone_scripts "${formatUrl}" ${repo_path} "${branch}" "${proxy}"
|
git_clone_scripts "${formatUrl}" ${repo_path} "${branch}" "${proxy}"
|
||||||
|
|
||||||
if [[ $exit_status -eq 0 ]]; then
|
if [[ $exit_status -eq 0 ]]; then
|
||||||
echo -e "\n拉取 ${uniq_path} 成功...\n"
|
echo -e "拉取 ${uniq_path} 成功...\n"
|
||||||
diff_scripts "$repo_path" "$author" "$path" "$blackword" "$dependence" "$extensions" "$autoAddCron" "$autoDelCron"
|
diff_scripts "$repo_path" "$author" "$path" "$blackword" "$dependence" "$extensions" "$autoAddCron" "$autoDelCron"
|
||||||
else
|
else
|
||||||
echo -e "\n拉取 ${uniq_path} 失败,请检查日志...\n"
|
echo -e "拉取 ${uniq_path} 失败,请检查日志...\n"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,7 +195,7 @@ update_raw() {
|
|||||||
[[ -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"
|
||||||
result=$(add_cron_api "$cron_line:$cmd_task $filename:$cron_name:$SUB_ID")
|
result=$(add_cron_api "${cron_line}:${cmd_task} ${filename}:${cron_name}:${SUB_ID}")
|
||||||
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"
|
||||||
@@ -231,22 +231,25 @@ usage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
reload_qinglong() {
|
reload_qinglong() {
|
||||||
|
delete_pm2
|
||||||
|
|
||||||
local reload_target="${1}"
|
local reload_target="${1}"
|
||||||
local primary_branch="master"
|
local primary_branch="master"
|
||||||
if [[ "${QL_BRANCH}" == "develop" ]]; then
|
if [[ "${QL_BRANCH}" == "develop" ]] || [[ "${QL_BRANCH}" == "debian" ]] || [[ "${QL_BRANCH}" == "debian-dev" ]]; then
|
||||||
primary_branch="develop"
|
primary_branch="${QL_BRANCH}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$reload_target" == 'system' ]]; then
|
if [[ "$reload_target" == 'system' ]]; then
|
||||||
cp -rf ${dir_tmp}/qinglong-${primary_branch}/* ${dir_root}/
|
rm -rf ${dir_root}/back ${dir_root}/cli ${dir_root}/docker ${dir_root}/sample ${dir_root}/shell ${dir_root}/src
|
||||||
|
mv -f ${dir_tmp}/qinglong-${primary_branch}/* ${dir_root}/
|
||||||
rm -rf $dir_static/*
|
rm -rf $dir_static/*
|
||||||
cp -rf ${dir_tmp}/qinglong-static-${primary_branch}/* ${dir_static}/
|
mv -f ${dir_tmp}/qinglong-static-${primary_branch}/* ${dir_static}/
|
||||||
cp -f $file_config_sample $dir_config/config.sample.sh
|
cp -f $file_config_sample $dir_config/config.sample.sh
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$reload_target" == 'data' ]]; then
|
if [[ "$reload_target" == 'data' ]]; then
|
||||||
rm -rf ${dir_root}/data
|
rm -rf ${dir_root}/data/*
|
||||||
cp -rf ${dir_tmp}/data ${dir_root}/
|
mv -f ${dir_tmp}/data/* ${dir_root}/data/
|
||||||
fi
|
fi
|
||||||
|
|
||||||
reload_pm2
|
reload_pm2
|
||||||
@@ -258,7 +261,7 @@ update_qinglong() {
|
|||||||
local mirror="gitee"
|
local mirror="gitee"
|
||||||
local downloadQLUrl="https://gitee.com/whyour/qinglong/repository/archive"
|
local downloadQLUrl="https://gitee.com/whyour/qinglong/repository/archive"
|
||||||
local downloadStaticUrl="https://gitee.com/whyour/qinglong-static/repository/archive"
|
local downloadStaticUrl="https://gitee.com/whyour/qinglong-static/repository/archive"
|
||||||
local githubStatus=$(curl -s -m 2 -IL "https://google.com" | grep 200)
|
local githubStatus=$(curl -s --noproxy "*" -m 2 -IL "https://google.com" | grep 200)
|
||||||
if [[ ! -z $githubStatus ]]; then
|
if [[ ! -z $githubStatus ]]; then
|
||||||
mirror="github"
|
mirror="github"
|
||||||
downloadQLUrl="https://github.com/whyour/qinglong/archive/refs/heads"
|
downloadQLUrl="https://github.com/whyour/qinglong/archive/refs/heads"
|
||||||
@@ -310,9 +313,12 @@ check_update_dep() {
|
|||||||
echo -e "更新包下载成功..."
|
echo -e "更新包下载成功..."
|
||||||
|
|
||||||
if [[ "$needRestart" == 'true' ]]; then
|
if [[ "$needRestart" == 'true' ]]; then
|
||||||
cp -rf ${dir_tmp}/qinglong-${primary_branch}/* ${dir_root}/
|
delete_pm2
|
||||||
|
|
||||||
|
rm -rf ${dir_root}/back ${dir_root}/cli ${dir_root}/docker ${dir_root}/sample ${dir_root}/shell ${dir_root}/src
|
||||||
|
mv -f ${dir_tmp}/qinglong-${primary_branch}/* ${dir_root}/
|
||||||
rm -rf $dir_static/*
|
rm -rf $dir_static/*
|
||||||
cp -rf ${dir_tmp}/qinglong-static-${primary_branch}/* ${dir_static}/
|
mv -f ${dir_tmp}/qinglong-static-${primary_branch}/* ${dir_static}/
|
||||||
cp -f $file_config_sample $dir_config/config.sample.sh
|
cp -f $file_config_sample $dir_config/config.sample.sh
|
||||||
|
|
||||||
reload_pm2
|
reload_pm2
|
||||||
@@ -417,9 +423,15 @@ gen_list_repo() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
for file in ${files}; do
|
for file in ${files}; do
|
||||||
|
dirPath=$(dirname "$file")
|
||||||
filename=$(basename "$file")
|
filename=$(basename "$file")
|
||||||
cp -f $file "$dir_scripts/${uniq_path}/${filename}"
|
filePath="${uniq_path}/${filename}"
|
||||||
echo "${uniq_path}/${filename}" >>"$dir_list_tmp/${uniq_path}_scripts.list"
|
if [[ $dirPath ]] && [[ $dirPath != '.' ]]; then
|
||||||
|
mkdir -p "${dir_scripts}/${uniq_path}/${dirPath}"
|
||||||
|
filePath="${uniq_path}/${dirPath}/${filename}"
|
||||||
|
fi
|
||||||
|
cp -f $file "${dir_scripts}/$filePath"
|
||||||
|
echo "$filePath" >>"$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}')
|
# 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
|
# if [[ $cron_id ]]; then
|
||||||
# result=$(update_cron_command_api "$cmd_task ${uniq_path}/${filename}:$cron_id")
|
# result=$(update_cron_command_api "$cmd_task ${uniq_path}/${filename}:$cron_id")
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { createFromIconfontCN } from '@ant-design/icons';
|
import { createFromIconfontCN } from '@ant-design/icons';
|
||||||
|
|
||||||
const IconFont = createFromIconfontCN({
|
const IconFont = createFromIconfontCN({
|
||||||
scriptUrl: ['//at.alicdn.com/t/c/font_3354854_ob5y15ewlyq.js'],
|
scriptUrl: ['//at.alicdn.com/t/c/font_3354854_lc939gab1iq.js'],
|
||||||
});
|
});
|
||||||
|
|
||||||
export default IconFont;
|
export default IconFont;
|
||||||
|
|||||||
@@ -100,12 +100,14 @@
|
|||||||
"删除中": "Deleting",
|
"删除中": "Deleting",
|
||||||
"已删除": "Deleted",
|
"已删除": "Deleted",
|
||||||
"删除失败": "Deletion Failed",
|
"删除失败": "Deletion Failed",
|
||||||
|
"已取消": "Cancelled",
|
||||||
"序号": "Number",
|
"序号": "Number",
|
||||||
"备注": "Remarks",
|
"备注": "Remarks",
|
||||||
"更新时间": "Update Time",
|
"更新时间": "Update Time",
|
||||||
"创建时间": "Creation Time",
|
"创建时间": "Creation Time",
|
||||||
"确认删除依赖": "Confirm to delete the dependency",
|
"确认删除依赖": "Confirm to delete the dependency",
|
||||||
"确认重新安装": "Confirm to reinstall",
|
"确认重新安装": "Confirm to reinstall",
|
||||||
|
"确认取消安装": "Confirm to cancel install",
|
||||||
"确认删除选中的依赖吗": "Confirm to delete the selected dependencies?",
|
"确认删除选中的依赖吗": "Confirm to delete the selected dependencies?",
|
||||||
"确认重新安装选中的依赖吗": "Confirm to reinstall the selected dependencies?",
|
"确认重新安装选中的依赖吗": "Confirm to reinstall the selected dependencies?",
|
||||||
"请输入名称": "Please enter a name",
|
"请输入名称": "Please enter a name",
|
||||||
@@ -394,6 +396,7 @@
|
|||||||
"系统": "System",
|
"系统": "System",
|
||||||
"个人": "Personal",
|
"个人": "Personal",
|
||||||
"重新安装": "Reinstall",
|
"重新安装": "Reinstall",
|
||||||
|
"取消安装": "Cancel Install",
|
||||||
"强制删除": "Force Delete",
|
"强制删除": "Force Delete",
|
||||||
"全部任务": "All Tasks",
|
"全部任务": "All Tasks",
|
||||||
"关联订阅": "Associate Subscription",
|
"关联订阅": "Associate Subscription",
|
||||||
|
|||||||
@@ -100,12 +100,14 @@
|
|||||||
"删除中": "删除中",
|
"删除中": "删除中",
|
||||||
"已删除": "已删除",
|
"已删除": "已删除",
|
||||||
"删除失败": "删除失败",
|
"删除失败": "删除失败",
|
||||||
|
"已取消": "已取消",
|
||||||
"序号": "序号",
|
"序号": "序号",
|
||||||
"备注": "备注",
|
"备注": "备注",
|
||||||
"更新时间": "更新时间",
|
"更新时间": "更新时间",
|
||||||
"创建时间": "创建时间",
|
"创建时间": "创建时间",
|
||||||
"确认删除依赖": "确认删除依赖",
|
"确认删除依赖": "确认删除依赖",
|
||||||
"确认重新安装": "确认重新安装",
|
"确认重新安装": "确认重新安装",
|
||||||
|
"确认取消安装": "确认取消安装",
|
||||||
"确认删除选中的依赖吗": "确认删除选中的依赖吗",
|
"确认删除选中的依赖吗": "确认删除选中的依赖吗",
|
||||||
"确认重新安装选中的依赖吗": "确认重新安装选中的依赖吗",
|
"确认重新安装选中的依赖吗": "确认重新安装选中的依赖吗",
|
||||||
"请输入名称": "请输入名称",
|
"请输入名称": "请输入名称",
|
||||||
@@ -394,6 +396,7 @@
|
|||||||
"系统": "系统",
|
"系统": "系统",
|
||||||
"个人": "个人",
|
"个人": "个人",
|
||||||
"重新安装": "重新安装",
|
"重新安装": "重新安装",
|
||||||
|
"取消安装": "取消安装",
|
||||||
"强制删除": "强制删除",
|
"强制删除": "强制删除",
|
||||||
"全部任务": "全部任务",
|
"全部任务": "全部任务",
|
||||||
"关联订阅": "关联订阅",
|
"关联订阅": "关联订阅",
|
||||||
|
|||||||
+111
-37
@@ -22,6 +22,7 @@ import {
|
|||||||
FileTextOutlined,
|
FileTextOutlined,
|
||||||
CloseCircleOutlined,
|
CloseCircleOutlined,
|
||||||
ClockCircleOutlined,
|
ClockCircleOutlined,
|
||||||
|
MinusCircleOutlined,
|
||||||
} from '@ant-design/icons';
|
} from '@ant-design/icons';
|
||||||
import config from '@/utils/config';
|
import config from '@/utils/config';
|
||||||
import { PageContainer } from '@ant-design/pro-layout';
|
import { PageContainer } from '@ant-design/pro-layout';
|
||||||
@@ -36,20 +37,12 @@ import { SharedContext } from '@/layouts';
|
|||||||
import useTableScrollHeight from '@/hooks/useTableScrollHeight';
|
import useTableScrollHeight from '@/hooks/useTableScrollHeight';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
import WebSocketManager from '@/utils/websocket';
|
import WebSocketManager from '@/utils/websocket';
|
||||||
|
import { DependenceStatus, Status } from './type';
|
||||||
|
import IconFont from '@/components/iconfont';
|
||||||
|
|
||||||
const { Text } = Typography;
|
const { Text } = Typography;
|
||||||
const { Search } = Input;
|
const { Search } = Input;
|
||||||
|
|
||||||
enum Status {
|
|
||||||
'安装中',
|
|
||||||
'已安装',
|
|
||||||
'安装失败',
|
|
||||||
'删除中',
|
|
||||||
'已删除',
|
|
||||||
'删除失败',
|
|
||||||
'队列中',
|
|
||||||
}
|
|
||||||
|
|
||||||
enum StatusColor {
|
enum StatusColor {
|
||||||
'processing',
|
'processing',
|
||||||
'success',
|
'success',
|
||||||
@@ -85,6 +78,10 @@ const StatusMap: Record<number, { icon: React.ReactNode; color: string }> = {
|
|||||||
icon: <ClockCircleOutlined />,
|
icon: <ClockCircleOutlined />,
|
||||||
color: 'default',
|
color: 'default',
|
||||||
},
|
},
|
||||||
|
7: {
|
||||||
|
icon: <MinusCircleOutlined />,
|
||||||
|
color: 'default',
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const Dependence = () => {
|
const Dependence = () => {
|
||||||
@@ -108,6 +105,40 @@ const Dependence = () => {
|
|||||||
key: 'status',
|
key: 'status',
|
||||||
width: 120,
|
width: 120,
|
||||||
dataIndex: 'status',
|
dataIndex: 'status',
|
||||||
|
filters: [
|
||||||
|
{
|
||||||
|
text: intl.get('队列中'),
|
||||||
|
value: DependenceStatus.queued,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: intl.get('安装中'),
|
||||||
|
value: DependenceStatus.installing,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: intl.get('已安装'),
|
||||||
|
value: DependenceStatus.installed,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: intl.get('安装失败'),
|
||||||
|
value: DependenceStatus.installFailed,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: intl.get('删除中'),
|
||||||
|
value: DependenceStatus.removing,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: intl.get('已删除'),
|
||||||
|
value: DependenceStatus.removed,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: intl.get('删除失败'),
|
||||||
|
value: DependenceStatus.removeFailed,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: intl.get('已取消'),
|
||||||
|
value: DependenceStatus.cancelled,
|
||||||
|
},
|
||||||
|
],
|
||||||
render: (text: string, record: any, index: number) => {
|
render: (text: string, record: any, index: number) => {
|
||||||
return (
|
return (
|
||||||
<Space size="middle" style={{ cursor: 'text' }}>
|
<Space size="middle" style={{ cursor: 'text' }}>
|
||||||
@@ -154,35 +185,46 @@ const Dependence = () => {
|
|||||||
const isPc = !isPhone;
|
const isPc = !isPhone;
|
||||||
return (
|
return (
|
||||||
<Space size="middle">
|
<Space size="middle">
|
||||||
<Tooltip title={isPc ? intl.get('日志') : ''}>
|
{![Status.队列中, Status.已取消].includes(record.status) && (
|
||||||
<a
|
<Tooltip title={isPc ? intl.get('日志') : ''}>
|
||||||
onClick={() => {
|
<a
|
||||||
setLogDependence({ ...record, timestamp: Date.now() });
|
onClick={() => {
|
||||||
}}
|
setLogDependence({ ...record, timestamp: Date.now() });
|
||||||
>
|
}}
|
||||||
<FileTextOutlined />
|
>
|
||||||
</a>
|
<FileTextOutlined />
|
||||||
</Tooltip>
|
</a>
|
||||||
{record.status !== Status.安装中 &&
|
</Tooltip>
|
||||||
record.status !== Status.删除中 && (
|
)}
|
||||||
<>
|
{[Status.队列中, Status.安装中, Status.删除中].includes(
|
||||||
<Tooltip title={isPc ? intl.get('重新安装') : ''}>
|
record.status,
|
||||||
<a onClick={() => reInstallDependence(record, index)}>
|
) ? (
|
||||||
<BugOutlined />
|
<Tooltip title={isPc ? intl.get('取消安装') : ''}>
|
||||||
</a>
|
<a onClick={() => cancelDependence(record)}>
|
||||||
</Tooltip>
|
<IconFont type="ql-icon-quxiaoanzhuang" />
|
||||||
|
</a>
|
||||||
|
</Tooltip>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<Tooltip title={isPc ? intl.get('重新安装') : ''}>
|
||||||
|
<a onClick={() => reInstallDependence(record, index)}>
|
||||||
|
<BugOutlined />
|
||||||
|
</a>
|
||||||
|
</Tooltip>
|
||||||
|
{Status.已安装 === record.status && (
|
||||||
<Tooltip title={isPc ? intl.get('删除') : ''}>
|
<Tooltip title={isPc ? intl.get('删除') : ''}>
|
||||||
<a onClick={() => deleteDependence(record, index)}>
|
<a onClick={() => deleteDependence(record, index)}>
|
||||||
<DeleteOutlined />
|
<DeleteOutlined />
|
||||||
</a>
|
</a>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
<Tooltip title={isPc ? intl.get('强制删除') : ''}>
|
)}
|
||||||
<a onClick={() => deleteDependence(record, index, true)}>
|
<Tooltip title={isPc ? intl.get('强制删除') : ''}>
|
||||||
<DeleteFilled />
|
<a onClick={() => deleteDependence(record, index, true)}>
|
||||||
</a>
|
<DeleteFilled />
|
||||||
</Tooltip>
|
</a>
|
||||||
</>
|
</Tooltip>
|
||||||
)}
|
</>
|
||||||
|
)}
|
||||||
</Space>
|
</Space>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@@ -200,11 +242,15 @@ const Dependence = () => {
|
|||||||
const tableRef = useRef<HTMLDivElement>(null);
|
const tableRef = useRef<HTMLDivElement>(null);
|
||||||
const tableScrollHeight = useTableScrollHeight(tableRef, 59);
|
const tableScrollHeight = useTableScrollHeight(tableRef, 59);
|
||||||
|
|
||||||
const getDependencies = () => {
|
const getDependencies = (status?: number[]) => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
request
|
request
|
||||||
.get(
|
.get(
|
||||||
`${config.apiPrefix}dependencies?searchValue=${searchText}&type=${type}`,
|
`${
|
||||||
|
config.apiPrefix
|
||||||
|
}dependencies?searchValue=${searchText}&type=${type}&status=${
|
||||||
|
status || ''
|
||||||
|
}`,
|
||||||
)
|
)
|
||||||
.then(({ code, data }) => {
|
.then(({ code, data }) => {
|
||||||
if (code === 200) {
|
if (code === 200) {
|
||||||
@@ -289,6 +335,31 @@ const Dependence = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const cancelDependence = (record: any) => {
|
||||||
|
Modal.confirm({
|
||||||
|
title: intl.get('确认取消安装'),
|
||||||
|
content: (
|
||||||
|
<>
|
||||||
|
{intl.get('确认取消安装')}{' '}
|
||||||
|
<Text style={{ wordBreak: 'break-all' }} type="warning">
|
||||||
|
{record.name}
|
||||||
|
</Text>{' '}
|
||||||
|
{intl.get('吗')}
|
||||||
|
</>
|
||||||
|
),
|
||||||
|
onOk() {
|
||||||
|
request
|
||||||
|
.put(`${config.apiPrefix}dependencies/cancel`, [record.id])
|
||||||
|
.then(() => {
|
||||||
|
getDependencies();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onCancel() {
|
||||||
|
console.log('Cancel');
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const handleCancel = (dependence?: any[]) => {
|
const handleCancel = (dependence?: any[]) => {
|
||||||
setIsModalVisible(false);
|
setIsModalVisible(false);
|
||||||
dependence && handleDependence(dependence);
|
dependence && handleDependence(dependence);
|
||||||
@@ -420,7 +491,7 @@ const Dependence = () => {
|
|||||||
}
|
}
|
||||||
return _result;
|
return _result;
|
||||||
});
|
});
|
||||||
}, 5000);
|
}, 300);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -538,6 +609,9 @@ const Dependence = () => {
|
|||||||
size="middle"
|
size="middle"
|
||||||
scroll={{ x: 768, y: tableScrollHeight }}
|
scroll={{ x: 768, y: tableScrollHeight }}
|
||||||
loading={loading}
|
loading={loading}
|
||||||
|
onChange={(pagination, filters) => {
|
||||||
|
getDependencies(filters?.status as number[]);
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</DndProvider>
|
</DndProvider>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import {
|
|||||||
import { PageLoading } from '@ant-design/pro-layout';
|
import { PageLoading } from '@ant-design/pro-layout';
|
||||||
import Ansi from 'ansi-to-react';
|
import Ansi from 'ansi-to-react';
|
||||||
import WebSocketManager from '@/utils/websocket';
|
import WebSocketManager from '@/utils/websocket';
|
||||||
|
import { Status } from './type';
|
||||||
|
|
||||||
const DependenceLogModal = ({
|
const DependenceLogModal = ({
|
||||||
dependence,
|
dependence,
|
||||||
@@ -96,7 +97,11 @@ const DependenceLogModal = ({
|
|||||||
|
|
||||||
const handleMessage = (payload: any) => {
|
const handleMessage = (payload: any) => {
|
||||||
const { message, references } = payload;
|
const { message, references } = payload;
|
||||||
if (references.length > 0 && references.includes(dependence.id)) {
|
if (
|
||||||
|
references.length > 0 &&
|
||||||
|
references.includes(dependence.id) &&
|
||||||
|
[Status.删除中, Status.安装中].includes(dependence.status)
|
||||||
|
) {
|
||||||
if (message.includes('结束时间')) {
|
if (message.includes('结束时间')) {
|
||||||
setExecuting(false);
|
setExecuting(false);
|
||||||
setIsRemoveFailed(message.includes('删除失败'));
|
setIsRemoveFailed(message.includes('删除失败'));
|
||||||
@@ -108,11 +113,13 @@ const DependenceLogModal = ({
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const ws = WebSocketManager.getInstance();
|
const ws = WebSocketManager.getInstance();
|
||||||
ws.subscribe('installDependence', handleMessage);
|
ws.subscribe('installDependence', handleMessage);
|
||||||
|
ws.subscribe('uninstallDependence', handleMessage);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
ws.unsubscribe('installDependence', handleMessage);
|
ws.unsubscribe('installDependence', handleMessage);
|
||||||
|
ws.unsubscribe('uninstallDependence', handleMessage);
|
||||||
};
|
};
|
||||||
}, []);
|
}, [dependence]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setIsPhone(document.body.clientWidth < 768);
|
setIsPhone(document.body.clientWidth < 768);
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
export enum DependenceStatus {
|
||||||
|
'installing',
|
||||||
|
'installed',
|
||||||
|
'installFailed',
|
||||||
|
'removing',
|
||||||
|
'removed',
|
||||||
|
'removeFailed',
|
||||||
|
'queued',
|
||||||
|
'cancelled',
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum Status {
|
||||||
|
'安装中',
|
||||||
|
'已安装',
|
||||||
|
'安装失败',
|
||||||
|
'删除中',
|
||||||
|
'已删除',
|
||||||
|
'删除失败',
|
||||||
|
'队列中',
|
||||||
|
'已取消',
|
||||||
|
}
|
||||||
@@ -68,13 +68,13 @@ const Log = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setCurrentNode(node);
|
||||||
|
setSelect(value);
|
||||||
|
|
||||||
if (node.type === 'directory') {
|
if (node.type === 'directory') {
|
||||||
setValue(intl.get('请选择日志文件'));
|
setValue(intl.get('请选择日志文件'));
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -115,13 +115,13 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setSelect(node.key);
|
||||||
|
setCurrentNode(node);
|
||||||
|
|
||||||
if (node.type === 'directory') {
|
if (node.type === 'directory') {
|
||||||
setValue(intl.get('请选择脚本文件'));
|
setValue(intl.get('请选择脚本文件'));
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import intl from 'react-intl-universal';
|
import { disableBody } from '@/utils';
|
||||||
import React, { useEffect, useState, useRef, useCallback } from 'react';
|
|
||||||
import { Statistic, Modal, Tag, Button, Spin, message } from 'antd';
|
|
||||||
import { request } from '@/utils/http';
|
|
||||||
import config from '@/utils/config';
|
import config from '@/utils/config';
|
||||||
|
import { request } from '@/utils/http';
|
||||||
import WebSocketManager from '@/utils/websocket';
|
import WebSocketManager from '@/utils/websocket';
|
||||||
import Ansi from 'ansi-to-react';
|
import Ansi from 'ansi-to-react';
|
||||||
|
import { Button, Modal, Statistic, message } from 'antd';
|
||||||
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||||
|
import intl from 'react-intl-universal';
|
||||||
|
|
||||||
const { Countdown } = Statistic;
|
const { Countdown } = Statistic;
|
||||||
|
|
||||||
@@ -116,7 +117,7 @@ const CheckUpdate = ({ systemInfo }: any) => {
|
|||||||
|
|
||||||
const reloadSystem = (type?: string) => {
|
const reloadSystem = (type?: string) => {
|
||||||
request
|
request
|
||||||
.put(`${config.apiPrefix}system/reload`, { type })
|
.put(`${config.apiPrefix}update/${type}`)
|
||||||
.then((_data: any) => {
|
.then((_data: any) => {
|
||||||
message.success({
|
message.success({
|
||||||
content: (
|
content: (
|
||||||
@@ -132,6 +133,7 @@ const CheckUpdate = ({ systemInfo }: any) => {
|
|||||||
),
|
),
|
||||||
duration: 30,
|
duration: 30,
|
||||||
});
|
});
|
||||||
|
disableBody();
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
}, 30000);
|
}, 30000);
|
||||||
@@ -220,7 +222,7 @@ const CheckUpdate = ({ systemInfo }: any) => {
|
|||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
type="primary"
|
type="primary"
|
||||||
onClick={() => reloadSystem()}
|
onClick={() => reloadSystem('reload')}
|
||||||
style={{ marginLeft: 8 }}
|
style={{ marginLeft: 8 }}
|
||||||
>
|
>
|
||||||
{intl.get('重新启动')}
|
{intl.get('重新启动')}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import { UploadOutlined } from '@ant-design/icons';
|
|||||||
import Countdown from 'antd/lib/statistic/Countdown';
|
import Countdown from 'antd/lib/statistic/Countdown';
|
||||||
import useProgress from './progress';
|
import useProgress from './progress';
|
||||||
import pick from 'lodash/pick';
|
import pick from 'lodash/pick';
|
||||||
|
import { disableBody } from '@/utils';
|
||||||
|
|
||||||
const dataMap = {
|
const dataMap = {
|
||||||
'log-remove-frequency': 'logRemoveFrequency',
|
'log-remove-frequency': 'logRemoveFrequency',
|
||||||
@@ -141,7 +142,7 @@ const Other = ({
|
|||||||
okText: intl.get('重启'),
|
okText: intl.get('重启'),
|
||||||
onOk() {
|
onOk() {
|
||||||
request
|
request
|
||||||
.put(`${config.apiPrefix}system/reload`, { type: 'data' })
|
.put(`${config.apiPrefix}update/data`)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
message.success({
|
message.success({
|
||||||
content: (
|
content: (
|
||||||
@@ -157,6 +158,7 @@ const Other = ({
|
|||||||
),
|
),
|
||||||
duration: 30,
|
duration: 30,
|
||||||
});
|
});
|
||||||
|
disableBody();
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
}, 30000);
|
}, 30000);
|
||||||
@@ -271,12 +273,18 @@ const Other = ({
|
|||||||
showUploadList={false}
|
showUploadList={false}
|
||||||
maxCount={1}
|
maxCount={1}
|
||||||
action={`${config.apiPrefix}system/data/import`}
|
action={`${config.apiPrefix}system/data/import`}
|
||||||
onChange={(e) => {
|
onChange={({ file, event }) => {
|
||||||
if (e.event?.percent) {
|
if (event?.percent) {
|
||||||
showUploadProgress(parseFloat(e.event?.percent.toFixed(1)));
|
showUploadProgress(
|
||||||
if (e.event?.percent === 100) {
|
Math.min(parseFloat(event?.percent.toFixed(1)), 99),
|
||||||
showReloadModal();
|
);
|
||||||
}
|
}
|
||||||
|
if (file.status === 'done') {
|
||||||
|
showUploadProgress(100);
|
||||||
|
showReloadModal();
|
||||||
|
}
|
||||||
|
if (file.status === 'error') {
|
||||||
|
message.error('上传失败');
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
name="data"
|
name="data"
|
||||||
|
|||||||
@@ -2,30 +2,42 @@ import intl from 'react-intl-universal';
|
|||||||
import { Modal, Progress } from 'antd';
|
import { Modal, Progress } from 'antd';
|
||||||
import { useRef } from 'react';
|
import { useRef } from 'react';
|
||||||
|
|
||||||
export default function useProgress(title: string) {
|
const ProgressElement = ({ percent }: { percent: number }) => (
|
||||||
const modalRef = useRef<ReturnType<typeof Modal.info>>();
|
<Progress
|
||||||
|
style={{ display: 'flex', justifyContent: 'center' }}
|
||||||
|
type="circle"
|
||||||
|
percent={percent}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
|
||||||
const ProgressElement = ({ percent }: { percent: number }) => (
|
export default function useProgress(title: string) {
|
||||||
<Progress
|
const modalRef = useRef<ReturnType<typeof Modal.info> | null>();
|
||||||
style={{ display: 'flex', justifyContent: 'center' }}
|
|
||||||
type="circle"
|
|
||||||
percent={percent}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
|
|
||||||
const showProgress = (percent: number) => {
|
const showProgress = (percent: number) => {
|
||||||
if (modalRef.current) {
|
if (modalRef.current) {
|
||||||
modalRef.current.update({
|
modalRef.current.update({
|
||||||
title: `${title}${percent >= 100 ? intl.get('成功') : intl.get('中...')}`,
|
title: `${title}${
|
||||||
|
percent >= 100 ? intl.get('成功') : intl.get('中...')
|
||||||
|
}`,
|
||||||
content: <ProgressElement percent={percent} />,
|
content: <ProgressElement percent={percent} />,
|
||||||
|
okButtonProps: { disabled: percent !== 100 },
|
||||||
});
|
});
|
||||||
|
if (percent === 100) {
|
||||||
|
setTimeout(() => {
|
||||||
|
modalRef.current?.destroy();
|
||||||
|
modalRef.current = null;
|
||||||
|
});
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
modalRef.current = Modal.info({
|
modalRef.current = Modal.info({
|
||||||
width: 600,
|
width: 600,
|
||||||
maskClosable: false,
|
maskClosable: false,
|
||||||
title: `${title}${percent >= 100 ? intl.get('成功') : intl.get('中...')}`,
|
title: `${title}${
|
||||||
|
percent >= 100 ? intl.get('成功') : intl.get('中...')
|
||||||
|
}`,
|
||||||
centered: true,
|
centered: true,
|
||||||
content: <ProgressElement percent={percent} />,
|
content: <ProgressElement percent={percent} />,
|
||||||
|
okButtonProps: { disabled: true },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
+32
-10
@@ -154,9 +154,9 @@ export default function browserType() {
|
|||||||
shell === 'none'
|
shell === 'none'
|
||||||
? {}
|
? {}
|
||||||
: {
|
: {
|
||||||
shell, // wechat qq uc 360 2345 sougou liebao maxthon
|
shell, // wechat qq uc 360 2345 sougou liebao maxthon
|
||||||
shellVs,
|
shellVs,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
@@ -335,20 +335,23 @@ export function parseCrontab(schedule: string): Date | null {
|
|||||||
if (time) {
|
if (time) {
|
||||||
return time.next().toDate();
|
return time.next().toDate();
|
||||||
}
|
}
|
||||||
} catch (error) { }
|
} catch (error) {}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getCrontabsNextDate(schedule: string, extra_schedules: string[]): Date | null {
|
export function getCrontabsNextDate(
|
||||||
let date = parseCrontab(schedule)
|
schedule: string,
|
||||||
|
extra_schedules: string[],
|
||||||
|
): Date | null {
|
||||||
|
let date = parseCrontab(schedule);
|
||||||
if (extra_schedules?.length) {
|
if (extra_schedules?.length) {
|
||||||
extra_schedules.forEach(x => {
|
extra_schedules.forEach((x) => {
|
||||||
const _date = parseCrontab(x)
|
const _date = parseCrontab(x);
|
||||||
if (_date && (!date || _date < date)) {
|
if (_date && (!date || _date < date)) {
|
||||||
date = _date;
|
date = _date;
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
return date;
|
return date;
|
||||||
}
|
}
|
||||||
@@ -362,4 +365,23 @@ export function getExtension(filename: string) {
|
|||||||
export function getEditorMode(filename: string) {
|
export function getEditorMode(filename: string) {
|
||||||
const extension = getExtension(filename) as keyof typeof LANG_MAP;
|
const extension = getExtension(filename) as keyof typeof LANG_MAP;
|
||||||
return LANG_MAP[extension];
|
return LANG_MAP[extension];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function disableBody() {
|
||||||
|
const overlay = document.createElement('div');
|
||||||
|
overlay.style.position = 'fixed';
|
||||||
|
overlay.style.top = '0px';
|
||||||
|
overlay.style.left = '0px';
|
||||||
|
overlay.style.width = '100%';
|
||||||
|
overlay.style.height = '100%';
|
||||||
|
overlay.style.backgroundColor = 'transparent';
|
||||||
|
overlay.style.zIndex = '9999';
|
||||||
|
document.body.appendChild(overlay);
|
||||||
|
|
||||||
|
overlay.addEventListener('click', function (event) {
|
||||||
|
event.stopPropagation();
|
||||||
|
event.preventDefault();
|
||||||
|
});
|
||||||
|
|
||||||
|
document.body.style.overflow = 'hidden';
|
||||||
|
}
|
||||||
|
|||||||
+8
-12
@@ -1,13 +1,9 @@
|
|||||||
version: 2.17.1
|
version: 2.17.3
|
||||||
changeLogLink: https://t.me/jiao_long/402
|
changeLogLink: https://t.me/jiao_long/404
|
||||||
publishTime: 2024-02-07 23:00
|
publishTime: 2024-03-29 23:30
|
||||||
changeLog: |
|
changeLog: |
|
||||||
1. 系统设置增加重启
|
1. python 通知文件支持自定义参数,可由每个脚本控制通知参数配置
|
||||||
2. 修复 debian 系统内更新源代码分支错误
|
2. ql repo 命令复制仓库任务时,保留仓库脚本原始目录层级
|
||||||
3. 修复启动时依赖配置未初始化
|
3. 修改自定义通知 body 解析逻辑
|
||||||
4. 修复未开启一言时多余空行, 通知渠道改发送前检查,感谢 https://github.com/Cp0204
|
4. 修改系统重启逻辑
|
||||||
5. Dockerfile 添加发布端口和数据卷 https://github.com/Akimio521
|
5. 修改 latest 基础镜像 node 版本为 v20
|
||||||
6. 修复有反向代理时脚本管理获取文件可能失败
|
|
||||||
7. 脚本管理重命名增加默认值,增加新建(mod+o)、删除快捷键(mod+d)
|
|
||||||
8. 修复对比工具保存文件
|
|
||||||
9. 其他 bug 修复
|
|
||||||
|
|||||||
Reference in New Issue
Block a user