mirror of
https://github.com/whyour/qinglong.git
synced 2026-08-05 16:25:04 +08:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b60cda66bb | |||
| 7efe81df9e | |||
| 0d492e94f4 | |||
| a45efbd69b | |||
| 035f0eb9e3 | |||
| 7d0cae7839 | |||
| 46e71d8213 | |||
| 372afb92c6 | |||
| 69d9307be9 | |||
| c3908e956f |
+62
-62
@@ -54,62 +54,6 @@ The npm version supports `debian/ubuntu/centos/alpine` systems and requires `nod
|
||||
npm i @whyour/qinglong
|
||||
```
|
||||
|
||||
## Built-in commands
|
||||
|
||||
- task
|
||||
|
||||
```bash
|
||||
# Execute in sequence, if a random delay is set, it will be randomly delayed by a certain number of seconds
|
||||
task <file_path>
|
||||
# Execute in sequence, regardless of whether a random delay is set, all run immediately,
|
||||
# and the foreground will output the day, while recorded in the log file
|
||||
task <file_path> now
|
||||
# Concurrent execution, regardless of whether a random delay is set, are run immediately,
|
||||
# the foreground does not generate the day, directly recorded in the log file, and can be specified account execution
|
||||
task <file_path> conc <env_name> <account_number>(Optional)
|
||||
# Specify the account to execute and run immediately regardless of whether a random delay is set
|
||||
task <file_path> desi <env_name> <account_number>
|
||||
# Set task timeout
|
||||
task -m <max_time> <file_path>
|
||||
# Use -- to split, -- followed by a parameter that is passed to the script, as in the following example, the script receives the parameter -u whyour -p password
|
||||
task <file_path> -- -u whyour -p password
|
||||
```
|
||||
|
||||
- ql
|
||||
|
||||
```bash
|
||||
# Update and restart Green Dragon
|
||||
ql update
|
||||
# Run custom scripts extra.sh
|
||||
ql extra
|
||||
# Adding a single script file
|
||||
ql raw <file_url>
|
||||
# Add a specific script for a single repository
|
||||
ql repo <repo_url> <whitelist> <blacklist> <dependence> <branch>
|
||||
# Delete old logs
|
||||
ql rmlog <days>
|
||||
# Start bot
|
||||
ql bot
|
||||
# Detecting the Green Dragon environment and repairing it
|
||||
ql check
|
||||
# Reset the number of login errors
|
||||
ql resetlet
|
||||
# Disable two-step login
|
||||
ql resettfa
|
||||
```
|
||||
|
||||
| **Parameter** | **Description** |
|
||||
|---|---|
|
||||
| file_url | Script address |
|
||||
| repo_url | Repository address |
|
||||
| whitelist | The whitelist when pulling the repository, i.e., the string contained in the path of the script to be pulled |
|
||||
| blacklist | Blacklisting when pulling repositories, i.e. strings that are not included in the path of the script to be pulled |
|
||||
| dependence | Pulling the dependencies needed for the repository will be copied directly from the repository to the repository directory under scripts, regardless of the blacklist |
|
||||
| extensions | Pull the branch of the repository |
|
||||
| branch | Number of days of logs to be kept |
|
||||
| days | File path for task execution |
|
||||
| file_path | The name of the environment variable that needs to be concurrent or specified at the time of task execution |
|
||||
|
||||
## Deployment
|
||||
|
||||
### Docker (Recommended)
|
||||
@@ -183,16 +127,72 @@ export QL_DATA_DIR=""
|
||||
qinglong
|
||||
```
|
||||
|
||||
## Built-in commands
|
||||
|
||||
- task
|
||||
|
||||
```bash
|
||||
# Execute in sequence, if a random delay is set, it will be randomly delayed by a certain number of seconds
|
||||
task <file_path>
|
||||
# Execute in sequence, regardless of whether a random delay is set, all run immediately,
|
||||
# and the foreground will output the day, while recorded in the log file
|
||||
task <file_path> now
|
||||
# Concurrent execution, regardless of whether a random delay is set, are run immediately,
|
||||
# the foreground does not generate the day, directly recorded in the log file, and can be specified account execution
|
||||
task <file_path> conc <env_name> <account_number>(Optional)
|
||||
# Specify the account to execute and run immediately regardless of whether a random delay is set
|
||||
task <file_path> desi <env_name> <account_number>
|
||||
# Set task timeout
|
||||
task -m <max_time> <file_path>
|
||||
# Use -- to split, -- followed by a parameter that is passed to the script, as in the following example, the script receives the parameter -u whyour -p password
|
||||
task <file_path> -- -u whyour -p password
|
||||
```
|
||||
|
||||
- ql
|
||||
|
||||
```bash
|
||||
# Update and restart Green Dragon
|
||||
ql update
|
||||
# Run custom scripts extra.sh
|
||||
ql extra
|
||||
# Adding a single script file
|
||||
ql raw <file_url>
|
||||
# Add a specific script for a single repository
|
||||
ql repo <repo_url> <whitelist> <blacklist> <dependence> <branch>
|
||||
# Delete old logs
|
||||
ql rmlog <days>
|
||||
# Start bot
|
||||
ql bot
|
||||
# Detecting the Green Dragon environment and repairing it
|
||||
ql check
|
||||
# Reset the number of login errors
|
||||
ql resetlet
|
||||
# Disable two-step login
|
||||
ql resettfa
|
||||
```
|
||||
|
||||
| **Parameter** | **Description** |
|
||||
|---|---|
|
||||
| file_url | Script address |
|
||||
| repo_url | Repository address |
|
||||
| whitelist | The whitelist when pulling the repository, i.e., the string contained in the path of the script to be pulled |
|
||||
| blacklist | Blacklisting when pulling repositories, i.e. strings that are not included in the path of the script to be pulled |
|
||||
| dependence | Pulling the dependencies needed for the repository will be copied directly from the repository to the repository directory under scripts, regardless of the blacklist |
|
||||
| extensions | Pull the branch of the repository |
|
||||
| branch | Number of days of logs to be kept |
|
||||
| days | File path for task execution |
|
||||
| file_path | The name of the environment variable that needs to be concurrent or specified at the time of task execution |
|
||||
|
||||
## Development
|
||||
|
||||
```bash
|
||||
$ git clone https://github.com/whyour/qinglong.git
|
||||
$ cd qinglong
|
||||
$ cp .env.example .env
|
||||
git clone https://github.com/whyour/qinglong.git
|
||||
cd qinglong
|
||||
cp .env.example .env
|
||||
# Recommended use pnpm https://pnpm.io/zh/installation
|
||||
$ npm install -g pnpm@8.3.1
|
||||
$ pnpm install
|
||||
$ pnpm start
|
||||
npm install -g pnpm@8.3.1
|
||||
pnpm install
|
||||
pnpm start
|
||||
```
|
||||
|
||||
Open your browser and visit <http://127.0.0.1:5700>
|
||||
|
||||
@@ -56,60 +56,6 @@ npm 版本支持 `debian/ubuntu/centos/alpine` 系统,需要自行安装 `node
|
||||
npm i @whyour/qinglong
|
||||
```
|
||||
|
||||
## 内置命令
|
||||
|
||||
- task
|
||||
|
||||
```bash
|
||||
# 依次执行,如果设置了随机延迟,将随机延迟一定秒数
|
||||
task <file_path>
|
||||
# 依次执行,无论是否设置了随机延迟,均立即运行,前台会输出日,同时记录在日志文件中
|
||||
task <file_path> now
|
||||
# 并发执行,无论是否设置了随机延迟,均立即运行,前台不产生日,直接记录在日志文件中,且可指定账号执行
|
||||
task <file_path> conc <env_name> <account_number>(可选的)
|
||||
# 指定账号执行,无论是否设置了随机延迟,均立即运行
|
||||
task <file_path> desi <env_name> <account_number>
|
||||
# 设置任务超时时间
|
||||
task -m <max_time> <file_path>
|
||||
# 使用 -- 分割,-- 后面的参数会传给脚本,下面的例子,脚本就可接收到参数 -u whyour -p password
|
||||
task <file_path> -- -u whyour -p password
|
||||
```
|
||||
|
||||
- ql
|
||||
|
||||
```bash
|
||||
# 更新并重启青龙
|
||||
ql update
|
||||
# 运行自定义脚本extra.sh
|
||||
ql extra
|
||||
# 添加单个脚本文件
|
||||
ql raw <file_url>
|
||||
# 添加单个仓库的指定脚本
|
||||
ql repo <repo_url> <whitelist> <blacklist> <dependence> <branch> <extensions>
|
||||
# 删除旧日志
|
||||
ql rmlog <days>
|
||||
# 启动tg-bot
|
||||
ql bot
|
||||
# 检测青龙环境并修复
|
||||
ql check
|
||||
# 重置登录错误次数
|
||||
ql resetlet
|
||||
# 禁用两步登录
|
||||
ql resettfa
|
||||
```
|
||||
|
||||
| **参数** | **说明** |
|
||||
|------------|---------------------------------------------------------------------------------------------|
|
||||
| file_url | 脚本地址 |
|
||||
| repo_url | 仓库地址 |
|
||||
| whitelist | 拉取仓库时的白名单,即就是需要拉取的脚本的路径包含的字符串,多个竖线分割 |
|
||||
| blacklist | 拉取仓库时的黑名单,即就是需要拉取的脚本的路径不包含的字符串,多个竖线分割 |
|
||||
| dependence | 拉取仓库需要的依赖文件,会直接从仓库拷贝到scripts下的仓库目录,不受黑名单影响,多个竖线分割 |
|
||||
| extensions | 拉取仓库的文件后缀,多个竖线分割 |
|
||||
| branch | 拉取仓库的分支 |
|
||||
| days | 需要保留的日志的天数 |
|
||||
| file_path | 任务执行时的文件路径 |
|
||||
|
||||
## 部署
|
||||
|
||||
### docker (推荐)
|
||||
@@ -183,16 +129,70 @@ export QL_DATA_DIR=""
|
||||
qinglong
|
||||
```
|
||||
|
||||
## 内置命令
|
||||
|
||||
- task
|
||||
|
||||
```bash
|
||||
# 依次执行,如果设置了随机延迟,将随机延迟一定秒数
|
||||
task <file_path>
|
||||
# 依次执行,无论是否设置了随机延迟,均立即运行,前台会输出日,同时记录在日志文件中
|
||||
task <file_path> now
|
||||
# 并发执行,无论是否设置了随机延迟,均立即运行,前台不产生日,直接记录在日志文件中,且可指定账号执行
|
||||
task <file_path> conc <env_name> <account_number>(可选的)
|
||||
# 指定账号执行,无论是否设置了随机延迟,均立即运行
|
||||
task <file_path> desi <env_name> <account_number>
|
||||
# 设置任务超时时间
|
||||
task -m <max_time> <file_path>
|
||||
# 使用 -- 分割,-- 后面的参数会传给脚本,下面的例子,脚本就可接收到参数 -u whyour -p password
|
||||
task <file_path> -- -u whyour -p password
|
||||
```
|
||||
|
||||
- ql
|
||||
|
||||
```bash
|
||||
# 更新并重启青龙
|
||||
ql update
|
||||
# 运行自定义脚本extra.sh
|
||||
ql extra
|
||||
# 添加单个脚本文件
|
||||
ql raw <file_url>
|
||||
# 添加单个仓库的指定脚本
|
||||
ql repo <repo_url> <whitelist> <blacklist> <dependence> <branch> <extensions>
|
||||
# 删除旧日志
|
||||
ql rmlog <days>
|
||||
# 启动tg-bot
|
||||
ql bot
|
||||
# 检测青龙环境并修复
|
||||
ql check
|
||||
# 重置登录错误次数
|
||||
ql resetlet
|
||||
# 禁用两步登录
|
||||
ql resettfa
|
||||
```
|
||||
|
||||
| **参数** | **说明** |
|
||||
|------------|---------------------------------------------------------------------------------------------|
|
||||
| file_url | 脚本地址 |
|
||||
| repo_url | 仓库地址 |
|
||||
| whitelist | 拉取仓库时的白名单,即就是需要拉取的脚本的路径包含的字符串,多个竖线分割 |
|
||||
| blacklist | 拉取仓库时的黑名单,即就是需要拉取的脚本的路径不包含的字符串,多个竖线分割 |
|
||||
| dependence | 拉取仓库需要的依赖文件,会直接从仓库拷贝到scripts下的仓库目录,不受黑名单影响,多个竖线分割 |
|
||||
| extensions | 拉取仓库的文件后缀,多个竖线分割 |
|
||||
| branch | 拉取仓库的分支 |
|
||||
| days | 需要保留的日志的天数 |
|
||||
| file_path | 任务执行时的文件路径 |
|
||||
|
||||
## 开发
|
||||
|
||||
```bash
|
||||
$ git clone https://github.com/whyour/qinglong.git
|
||||
$ cd qinglong
|
||||
$ cp .env.example .env
|
||||
git clone https://github.com/whyour/qinglong.git
|
||||
cd qinglong
|
||||
cp .env.example .env
|
||||
# 推荐使用 pnpm https://pnpm.io/zh/installation
|
||||
$ npm install -g pnpm@8.3.1
|
||||
$ pnpm install
|
||||
$ pnpm start
|
||||
npm install -g pnpm@8.3.1
|
||||
pnpm install
|
||||
pnpm start
|
||||
```
|
||||
|
||||
打开你的浏览器,访问 <http://127.0.0.1:5700>
|
||||
|
||||
+1
-1
@@ -217,7 +217,7 @@ export default (app: Router) => {
|
||||
} else {
|
||||
return res.send({
|
||||
code: 400,
|
||||
message: '文件缺少name或者value字段,参考导出文件格式',
|
||||
message: '每条数据 name 或者 value 字段不能为空,参考导出文件格式',
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
|
||||
@@ -19,7 +19,12 @@ const lastVersionFile = `https://qn.whyour.cn/version.yaml`;
|
||||
const rootPath = process.env.QL_DIR as string;
|
||||
const envFound = dotenv.config({ path: path.join(rootPath, '.env') });
|
||||
|
||||
const dataPath = path.join(rootPath, 'data/');
|
||||
let dataPath = path.join(rootPath, 'data/');
|
||||
|
||||
if (process.env.QL_DATA_DIR) {
|
||||
dataPath = process.env.QL_DATA_DIR.replace(/\/$/g, '');
|
||||
}
|
||||
|
||||
const shellPath = path.join(rootPath, 'shell/');
|
||||
const tmpPath = path.join(rootPath, '.tmp/');
|
||||
const samplePath = path.join(rootPath, 'sample/');
|
||||
|
||||
@@ -32,7 +32,9 @@ export function formatCommand(doc: Subscription, url?: string) {
|
||||
autoDelCron,
|
||||
} = doc;
|
||||
if (type === 'file') {
|
||||
command += `raw "${_url}"`;
|
||||
command += `raw "${_url}" "${proxy || ''}" "${
|
||||
isNil(autoAddCron) ? true : Boolean(autoAddCron)
|
||||
}" "${isNil(autoDelCron) ? true : Boolean(autoDelCron)}"`;
|
||||
} else {
|
||||
command += `repo "${_url}" "${whitelist || ''}" "${blacklist || ''}" "${
|
||||
dependences || ''
|
||||
|
||||
+3
-3
@@ -2,13 +2,13 @@ import { sequelize } from '.';
|
||||
import { DataTypes, Model, ModelDefined } from 'sequelize';
|
||||
import { NotificationInfo } from './notify';
|
||||
|
||||
export class AuthInfo {
|
||||
export class SystemInfo {
|
||||
ip?: string;
|
||||
type: AuthDataType;
|
||||
info?: SystemModelInfo;
|
||||
id?: number;
|
||||
|
||||
constructor(options: AuthInfo) {
|
||||
constructor(options: SystemInfo) {
|
||||
this.ip = options.ip;
|
||||
this.info = options.info;
|
||||
this.type = options.type;
|
||||
@@ -50,7 +50,7 @@ export type SystemModelInfo = SystemConfigInfo &
|
||||
Partial<NotificationInfo> &
|
||||
LoginLogInfo;
|
||||
|
||||
export interface SystemInstance extends Model<AuthInfo, AuthInfo>, AuthInfo { }
|
||||
export interface SystemInstance extends Model<SystemInfo, SystemInfo>, SystemInfo { }
|
||||
export const SystemModel = sequelize.define<SystemInstance>('Auth', {
|
||||
ip: DataTypes.STRING,
|
||||
type: DataTypes.STRING,
|
||||
|
||||
+19
-24
@@ -7,28 +7,23 @@ import linkDeps from './deps';
|
||||
import initTask from './initTask';
|
||||
|
||||
export default async ({ expressApp }: { expressApp: Application }) => {
|
||||
try {
|
||||
depInjectorLoader();
|
||||
Logger.info('✌️ Dependency Injector loaded');
|
||||
console.log('✌️ Dependency Injector loaded');
|
||||
|
||||
expressLoader({ app: expressApp });
|
||||
Logger.info('✌️ Express loaded');
|
||||
console.log('✌️ Express loaded');
|
||||
|
||||
await initData();
|
||||
Logger.info('✌️ init data loaded');
|
||||
console.log('✌️ init data loaded');
|
||||
|
||||
await linkDeps();
|
||||
Logger.info('✌️ link deps loaded');
|
||||
console.log('✌️ link deps loaded');
|
||||
|
||||
initTask();
|
||||
Logger.info('✌️ init task loaded');
|
||||
console.log('✌️ init task loaded');
|
||||
} catch (error) {
|
||||
Logger.error(`✌️ depInjectorLoader expressLoader initData linkDeps failed, ${error}`);
|
||||
console.error(`✌️ depInjectorLoader expressLoader initData linkDeps failed ${error}`);
|
||||
}
|
||||
depInjectorLoader();
|
||||
Logger.info('✌️ Dependency loaded');
|
||||
console.log('✌️ Dependency loaded');
|
||||
|
||||
await initData();
|
||||
Logger.info('✌️ Init data loaded');
|
||||
console.log('✌️ Init data loaded');
|
||||
|
||||
await linkDeps();
|
||||
Logger.info('✌️ Link deps loaded');
|
||||
console.log('✌️ Link deps loaded');
|
||||
|
||||
initTask();
|
||||
Logger.info('✌️ Init task loaded');
|
||||
console.log('✌️ Init task loaded');
|
||||
|
||||
expressLoader({ app: expressApp });
|
||||
Logger.info('✌️ Express loaded');
|
||||
console.log('✌️ Express loaded');
|
||||
};
|
||||
|
||||
@@ -18,6 +18,10 @@ export default async () => {
|
||||
const dependenceService = Container.get(DependenceService);
|
||||
const systemService = Container.get(SystemService);
|
||||
|
||||
// 初始化增加系统配置
|
||||
await SystemModel.upsert({ type: AuthDataType.systemConfig });
|
||||
await SystemModel.upsert({ type: AuthDataType.notification });
|
||||
|
||||
const installDependencies = () => {
|
||||
// 初始化时安装所有处于安装中,安装成功,安装失败的依赖
|
||||
DependenceModel.findAll({
|
||||
@@ -121,7 +125,7 @@ export default async () => {
|
||||
if (doc.command.includes(`${config.rootPath}/log/`)) {
|
||||
await CrontabModel.update(
|
||||
{
|
||||
command: `${config.rootPath}/data/log/${doc.command.replace(
|
||||
command: `${config.dataPath}/log/${doc.command.replace(
|
||||
`${config.rootPath}/log/`,
|
||||
'',
|
||||
)}`,
|
||||
@@ -132,7 +136,7 @@ export default async () => {
|
||||
if (doc.command.includes(`${config.rootPath}/config/`)) {
|
||||
await CrontabModel.update(
|
||||
{
|
||||
command: `${config.rootPath}/data/config/${doc.command.replace(
|
||||
command: `${config.dataPath}/config/${doc.command.replace(
|
||||
`${config.rootPath}/config/`,
|
||||
'',
|
||||
)}`,
|
||||
@@ -143,7 +147,7 @@ export default async () => {
|
||||
if (doc.command.includes(`${config.rootPath}/db/`)) {
|
||||
await CrontabModel.update(
|
||||
{
|
||||
command: `${config.rootPath}/data/db/${doc.command.replace(
|
||||
command: `${config.dataPath}/db/${doc.command.replace(
|
||||
`${config.rootPath}/db/`,
|
||||
'',
|
||||
)}`,
|
||||
@@ -158,7 +162,4 @@ export default async () => {
|
||||
// 初始化保存一次ck和定时任务数据
|
||||
await cronService.autosave_crontab();
|
||||
await envService.set_envs();
|
||||
|
||||
// 初始化增加系统配置
|
||||
await SystemModel.upsert({ type: AuthDataType.systemConfig });
|
||||
};
|
||||
|
||||
@@ -5,7 +5,12 @@ import Logger from './logger';
|
||||
import { fileExist } from '../config/util';
|
||||
|
||||
const rootPath = process.env.QL_DIR as string;
|
||||
const dataPath = path.join(rootPath, 'data/');
|
||||
let dataPath = path.join(rootPath, 'data/');
|
||||
|
||||
if (process.env.QL_DATA_DIR) {
|
||||
dataPath = process.env.QL_DATA_DIR.replace(/\/$/g, '');
|
||||
}
|
||||
|
||||
const configPath = path.join(dataPath, 'config/');
|
||||
const scriptPath = path.join(dataPath, 'scripts/');
|
||||
const logPath = path.join(dataPath, 'log/');
|
||||
|
||||
@@ -375,7 +375,10 @@ export default class CronService {
|
||||
|
||||
public async getDb(query: FindOptions<Crontab>['where']): Promise<Crontab> {
|
||||
const doc: any = await CrontabModel.findOne({ where: { ...query } });
|
||||
return doc && (doc.get({ plain: true }) as Crontab);
|
||||
if (!doc) {
|
||||
throw new Error(`Cron ${JSON.stringify(query)} not found`);
|
||||
}
|
||||
return doc.get({ plain: true });
|
||||
}
|
||||
|
||||
public async run(ids: number[]) {
|
||||
@@ -437,7 +440,7 @@ export default class CronService {
|
||||
const cp = spawn(
|
||||
`real_log_path=${logPath} no_delay=true ${this.makeCommand(
|
||||
cron,
|
||||
true
|
||||
true,
|
||||
)}`,
|
||||
{ shell: '/bin/bash' },
|
||||
);
|
||||
|
||||
@@ -63,7 +63,10 @@ export default class CronViewService {
|
||||
query: FindOptions<CrontabView>['where'],
|
||||
): Promise<CrontabView> {
|
||||
const doc: any = await CrontabViewModel.findOne({ where: { ...query } });
|
||||
return doc && (doc.get({ plain: true }) as CrontabView);
|
||||
if (!doc) {
|
||||
throw new Error(`CronView ${JSON.stringify(query)} not found`);
|
||||
}
|
||||
return doc.get({ plain: true });
|
||||
}
|
||||
|
||||
public async disabled(ids: number[]) {
|
||||
|
||||
@@ -183,7 +183,10 @@ export default class DependenceService {
|
||||
query: FindOptions<Dependence>['where'],
|
||||
): Promise<Dependence> {
|
||||
const doc: any = await DependenceModel.findOne({ where: { ...query } });
|
||||
return doc && (doc.get({ plain: true }) as Dependence);
|
||||
if (!doc) {
|
||||
throw new Error(`Dependency ${JSON.stringify(query)} not found`);
|
||||
}
|
||||
return doc.get({ plain: true });
|
||||
}
|
||||
|
||||
private async updateLog(ids: number[], log: string): Promise<void> {
|
||||
|
||||
@@ -165,7 +165,10 @@ export default class EnvService {
|
||||
|
||||
public async getDb(query: FindOptions<Env>['where']): Promise<Env> {
|
||||
const doc: any = await EnvModel.findOne({ where: { ...query } });
|
||||
return doc && (doc.get({ plain: true }) as Env);
|
||||
if (!doc) {
|
||||
throw new Error(`Env ${JSON.stringify(query)} not found`);
|
||||
}
|
||||
return doc.get({ plain: true });
|
||||
}
|
||||
|
||||
public async disabled(ids: string[]) {
|
||||
|
||||
+24
-20
@@ -27,7 +27,7 @@ export default class NotificationService {
|
||||
['aibotk', this.aibotk],
|
||||
['iGot', this.iGot],
|
||||
['pushPlus', this.pushPlus],
|
||||
['wePlusBot',this.wePlusBot],
|
||||
['wePlusBot', this.wePlusBot],
|
||||
['email', this.email],
|
||||
['pushMe', this.pushMe],
|
||||
['webhook', this.webhook],
|
||||
@@ -209,16 +209,23 @@ export default class NotificationService {
|
||||
if (!barkPush.startsWith('http')) {
|
||||
barkPush = `https://api.day.app/${barkPush}`;
|
||||
}
|
||||
const url = `${barkPush}/${encodeURIComponent(
|
||||
this.title,
|
||||
)}/${encodeURIComponent(
|
||||
this.content,
|
||||
)}?icon=${barkIcon}&sound=${barkSound}&group=${barkGroup}&level=${barkLevel}&url=${barkUrl}&isArchive=${barkArchive}`;
|
||||
const url = `${barkPush}`;
|
||||
const body = {
|
||||
title: this.title,
|
||||
body: this.content,
|
||||
icon: barkIcon,
|
||||
sound: barkSound,
|
||||
group: barkGroup,
|
||||
isArchive: barkArchive,
|
||||
level: barkLevel,
|
||||
url: barkUrl,
|
||||
};
|
||||
try {
|
||||
const res: any = await got
|
||||
.get(url, {
|
||||
.post(url, {
|
||||
...this.gotOption,
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||
json: body,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
})
|
||||
.json();
|
||||
if (res.code === 200) {
|
||||
@@ -519,7 +526,7 @@ export default class NotificationService {
|
||||
|
||||
let content = this.content;
|
||||
let template = 'txt';
|
||||
if(this.content.length>800){
|
||||
if (this.content.length > 800) {
|
||||
template = 'html';
|
||||
content = content.replace(/[\n\r]/g, '<br>');
|
||||
}
|
||||
@@ -612,18 +619,15 @@ export default class NotificationService {
|
||||
private async pushMe() {
|
||||
const { pushMeKey, pushMeUrl } = this.params;
|
||||
try {
|
||||
const res: any = await got.post(
|
||||
pushMeUrl || 'https://push.i-i.me/',
|
||||
{
|
||||
...this.gotOption,
|
||||
json: {
|
||||
push_key: pushMeKey,
|
||||
title: this.title,
|
||||
content: this.content,
|
||||
},
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
const res: any = await got.post(pushMeUrl || 'https://push.i-i.me/', {
|
||||
...this.gotOption,
|
||||
json: {
|
||||
push_key: pushMeKey,
|
||||
title: this.title,
|
||||
content: this.content,
|
||||
},
|
||||
);
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
if (res.body === 'success') {
|
||||
return true;
|
||||
} else {
|
||||
|
||||
@@ -26,7 +26,7 @@ export default class OpenService {
|
||||
|
||||
public async insert(payload: App): Promise<App> {
|
||||
const doc = await AppModel.create(payload, { returning: true });
|
||||
return doc.get({ plain: true }) as App;
|
||||
return doc.get({ plain: true });
|
||||
}
|
||||
|
||||
public async update(payload: App): Promise<App> {
|
||||
@@ -45,7 +45,10 @@ export default class OpenService {
|
||||
|
||||
public async getDb(query: any): Promise<App> {
|
||||
const doc: any = await AppModel.findOne({ where: query });
|
||||
return doc && (doc.get({ plain: true }) as App);
|
||||
if (!doc) {
|
||||
throw new Error(`App ${JSON.stringify(query)} not found`);
|
||||
}
|
||||
return doc.get({ plain: true });
|
||||
}
|
||||
|
||||
public async remove(ids: number[]) {
|
||||
|
||||
@@ -281,7 +281,7 @@ export default class SubscriptionService {
|
||||
): Promise<Subscription> {
|
||||
const doc = await SubscriptionModel.findOne({ where: { ...query } });
|
||||
if (!doc) {
|
||||
throw new Error(`${JSON.stringify(query)} not found`);
|
||||
throw new Error(`Subscription ${JSON.stringify(query)} not found`);
|
||||
}
|
||||
return doc.get({ plain: true });
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ import {
|
||||
import { NotificationInfo } from '../data/notify';
|
||||
import {
|
||||
AuthDataType,
|
||||
AuthInfo,
|
||||
SystemInfo,
|
||||
SystemInstance,
|
||||
SystemModel,
|
||||
SystemModelInfo,
|
||||
@@ -47,18 +47,21 @@ export default class SystemService {
|
||||
|
||||
public async getSystemConfig() {
|
||||
const doc = await this.getDb({ type: AuthDataType.systemConfig });
|
||||
return doc || ({} as SystemInstance);
|
||||
return doc;
|
||||
}
|
||||
|
||||
private async updateAuthDb(payload: AuthInfo): Promise<SystemInstance> {
|
||||
private async updateAuthDb(payload: SystemInfo): Promise<SystemInfo> {
|
||||
await SystemModel.upsert({ ...payload });
|
||||
const doc = await this.getDb({ type: payload.type });
|
||||
return doc;
|
||||
}
|
||||
|
||||
public async getDb(query: any): Promise<SystemInstance> {
|
||||
const doc: any = await SystemModel.findOne({ where: { ...query } });
|
||||
return doc && doc.get({ plain: true });
|
||||
public async getDb(query: any): Promise<SystemInfo> {
|
||||
const doc = await SystemModel.findOne({ where: { ...query } });
|
||||
if (!doc) {
|
||||
throw new Error(`System ${JSON.stringify(query)} not found`);
|
||||
}
|
||||
return doc.get({ plain: true });
|
||||
}
|
||||
|
||||
public async updateNotificationMode(notificationInfo: NotificationInfo) {
|
||||
|
||||
+10
-7
@@ -13,7 +13,7 @@ import jwt from 'jsonwebtoken';
|
||||
import { authenticator } from '@otplib/preset-default';
|
||||
import {
|
||||
AuthDataType,
|
||||
AuthInfo,
|
||||
SystemInfo,
|
||||
SystemModel,
|
||||
SystemModelInfo,
|
||||
LoginStatus,
|
||||
@@ -223,7 +223,7 @@ export default class UserService {
|
||||
return [];
|
||||
}
|
||||
|
||||
private async insertDb(payload: AuthInfo): Promise<AuthInfo> {
|
||||
private async insertDb(payload: SystemInfo): Promise<SystemInfo> {
|
||||
const doc = await SystemModel.create({ ...payload }, { returning: true });
|
||||
return doc;
|
||||
}
|
||||
@@ -351,10 +351,10 @@ export default class UserService {
|
||||
|
||||
public async getNotificationMode(): Promise<NotificationInfo> {
|
||||
const doc = await this.getDb({ type: AuthDataType.notification });
|
||||
return (doc && doc.info) || {};
|
||||
return (doc.info || {}) as NotificationInfo;
|
||||
}
|
||||
|
||||
private async updateAuthDb(payload: AuthInfo): Promise<any> {
|
||||
private async updateAuthDb(payload: SystemInfo): Promise<any> {
|
||||
let doc = await SystemModel.findOne({ type: payload.type });
|
||||
if (doc) {
|
||||
const updateResult = await SystemModel.update(payload, {
|
||||
@@ -368,9 +368,12 @@ export default class UserService {
|
||||
return doc;
|
||||
}
|
||||
|
||||
public async getDb(query: any): Promise<any> {
|
||||
const doc: any = await SystemModel.findOne({ where: { ...query } });
|
||||
return doc && (doc.get({ plain: true }) as any);
|
||||
public async getDb(query: any): Promise<SystemInfo> {
|
||||
const doc = await SystemModel.findOne({ where: { ...query } });
|
||||
if (!doc) {
|
||||
throw new Error(`${JSON.stringify(query)} not found`);
|
||||
}
|
||||
return doc.get({ plain: true });
|
||||
}
|
||||
|
||||
public async updateNotificationMode(notificationInfo: NotificationInfo) {
|
||||
|
||||
+15
-9
@@ -97,7 +97,6 @@ const push_config = {
|
||||
WEBHOOK_CONTENT_TYPE: '', // 自定义通知 content-type
|
||||
};
|
||||
|
||||
// 首先读取 面板变量 或者 github action 运行变量
|
||||
for (const key in push_config) {
|
||||
const v = process.env[key];
|
||||
if (v) {
|
||||
@@ -358,17 +357,24 @@ function barkNotify(text, desp, params = {}) {
|
||||
BARK_PUSH = `https://api.day.app/${BARK_PUSH}`;
|
||||
}
|
||||
const options = {
|
||||
url: `${BARK_PUSH}/${encodeURIComponent(text)}/${encodeURIComponent(
|
||||
desp,
|
||||
)}?icon=${BARK_ICON}&sound=${BARK_SOUND}&group=${BARK_GROUP}&isArchive=${BARK_ARCHIVE}&level=${BARK_LEVEL}&url=${BARK_URL}&${querystring.stringify(
|
||||
params,
|
||||
)}`,
|
||||
url: `${BARK_PUSH}`,
|
||||
json: {
|
||||
title: text,
|
||||
body: desp,
|
||||
icon: BARK_ICON,
|
||||
sound: BARK_SOUND,
|
||||
group: BARK_GROUP,
|
||||
isArchive: BARK_ARCHIVE,
|
||||
level: BARK_LEVEL,
|
||||
url: BARK_URL,
|
||||
...params,
|
||||
},
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
timeout,
|
||||
};
|
||||
$.get(options, (err, resp, data) => {
|
||||
$.post(options, (err, resp, data) => {
|
||||
try {
|
||||
if (err) {
|
||||
console.log('Bark APP 发送通知调用API失败😞\n', err);
|
||||
@@ -1283,7 +1289,7 @@ async function sendNotify(text, desp, params = {}) {
|
||||
}
|
||||
}
|
||||
|
||||
if (push_config.HITOKOTO) {
|
||||
if (push_config.HITOKOTO !== 'false') {
|
||||
desp += '\n\n' + (await one());
|
||||
}
|
||||
|
||||
|
||||
+19
-11
@@ -120,7 +120,6 @@ push_config = {
|
||||
}
|
||||
# fmt: on
|
||||
|
||||
# 首先读取 面板变量 或者 github action 运行变量
|
||||
for k in push_config:
|
||||
if os.getenv(k):
|
||||
v = os.getenv(k)
|
||||
@@ -137,9 +136,9 @@ def bark(title: str, content: str) -> None:
|
||||
print("bark 服务启动")
|
||||
|
||||
if push_config.get("BARK_PUSH").startswith("http"):
|
||||
url = f'{push_config.get("BARK_PUSH")}/{urllib.parse.quote_plus(title)}/{urllib.parse.quote_plus(content)}'
|
||||
url = f'{push_config.get("BARK_PUSH")}'
|
||||
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/{push_config.get("BARK_PUSH")}'
|
||||
|
||||
bark_params = {
|
||||
"BARK_ARCHIVE": "isArchive",
|
||||
@@ -149,7 +148,10 @@ def bark(title: str, content: str) -> None:
|
||||
"BARK_LEVEL": "level",
|
||||
"BARK_URL": "url",
|
||||
}
|
||||
params = ""
|
||||
data = {
|
||||
"title": title,
|
||||
"body": content,
|
||||
}
|
||||
for pair in filter(
|
||||
lambda pairs: pairs[0].startswith("BARK_")
|
||||
and pairs[0] != "BARK_PUSH"
|
||||
@@ -157,10 +159,11 @@ def bark(title: str, content: str) -> None:
|
||||
and bark_params.get(pairs[0]),
|
||||
push_config.items(),
|
||||
):
|
||||
params += f"{bark_params.get(pair[0])}={pair[1]}&"
|
||||
if params:
|
||||
url = url + "?" + params.rstrip("&")
|
||||
response = requests.get(url).json()
|
||||
data[bark_params.get(pair[0])] = pair[1]
|
||||
headers = {"Content-Type": "application/json;charset=utf-8"}
|
||||
response = requests.post(
|
||||
url=url, data=json.dumps(data), headers=headers, timeout=15
|
||||
).json()
|
||||
|
||||
if response["code"] == 200:
|
||||
print("bark 推送成功!")
|
||||
@@ -385,6 +388,7 @@ def pushplus_bot(title: str, content: str) -> None:
|
||||
else:
|
||||
print("PUSHPLUS 推送失败!")
|
||||
|
||||
|
||||
def weplus_bot(title: str, content: str) -> None:
|
||||
"""
|
||||
通过 微加机器人 推送消息。
|
||||
@@ -396,7 +400,7 @@ def weplus_bot(title: str, content: str) -> None:
|
||||
|
||||
template = "txt"
|
||||
if len(content) > 800:
|
||||
template = "html"
|
||||
template = "html"
|
||||
|
||||
url = "https://www.weplusbot.com/send"
|
||||
data = {
|
||||
@@ -704,7 +708,11 @@ def pushme(title: str, content: str) -> None:
|
||||
return
|
||||
print("PushMe 服务启动")
|
||||
|
||||
url = push_config.get("PUSHME_URL") if push_config.get("PUSHME_URL") else "https://push.i-i.me/"
|
||||
url = (
|
||||
push_config.get("PUSHME_URL")
|
||||
if push_config.get("PUSHME_URL")
|
||||
else "https://push.i-i.me/"
|
||||
)
|
||||
data = {
|
||||
"push_key": push_config.get("PUSHME_KEY"),
|
||||
"title": title,
|
||||
@@ -953,7 +961,7 @@ def send(title: str, content: str, ignore_default_config: bool = False, **kwargs
|
||||
return
|
||||
|
||||
hitokoto = push_config.get("HITOKOTO")
|
||||
content += "\n\n" + one() if hitokoto else ""
|
||||
content += "\n\n" + one() if hitokoto != "false" else ""
|
||||
|
||||
notify_function = add_notify_function()
|
||||
ts = [
|
||||
|
||||
+9
-4
@@ -4,6 +4,11 @@
|
||||
dir_root=$QL_DIR
|
||||
dir_tmp=$dir_root/.tmp
|
||||
dir_data=$dir_root/data
|
||||
|
||||
if [[ $QL_DATA_DIR ]]; then
|
||||
dir_data="${QL_DATA_DIR%/}"
|
||||
fi
|
||||
|
||||
dir_shell=$dir_root/shell
|
||||
dir_sample=$dir_root/sample
|
||||
dir_static=$dir_root/static
|
||||
@@ -371,25 +376,25 @@ patch_version() {
|
||||
|
||||
if [[ -d "$dir_root/db" ]]; then
|
||||
echo -e "检测到旧的db目录,拷贝到data目录...\n"
|
||||
cp -rf $dir_root/config $dir_root/data
|
||||
cp -rf $dir_root/config $dir_data
|
||||
echo
|
||||
fi
|
||||
|
||||
if [[ -d "$dir_root/scripts" ]]; then
|
||||
echo -e "检测到旧的scripts目录,拷贝到data目录...\n"
|
||||
cp -rf $dir_root/scripts $dir_root/data
|
||||
cp -rf $dir_root/scripts $dir_data
|
||||
echo
|
||||
fi
|
||||
|
||||
if [[ -d "$dir_root/log" ]]; then
|
||||
echo -e "检测到旧的log目录,拷贝到data目录...\n"
|
||||
cp -rf $dir_root/log $dir_root/data
|
||||
cp -rf $dir_root/log $dir_data
|
||||
echo
|
||||
fi
|
||||
|
||||
if [[ -d "$dir_root/config" ]]; then
|
||||
echo -e "检测到旧的config目录,拷贝到data目录...\n"
|
||||
cp -rf $dir_root/config $dir_root/data
|
||||
cp -rf $dir_root/config $dir_data
|
||||
echo
|
||||
fi
|
||||
}
|
||||
|
||||
+8
-14
@@ -156,21 +156,15 @@ update_raw() {
|
||||
autoDelCron=${AutoDelCron}
|
||||
fi
|
||||
|
||||
local proxyStr=""
|
||||
if [[ $proxy ]]; then
|
||||
if [[ $url == http:* ]]; then
|
||||
proxyStr="-e \"http_proxy=${proxy}\""
|
||||
elif [[ $url == https:* ]]; then
|
||||
proxyStr="-e \"http_proxy=${proxy};https_proxy=${proxy}\""
|
||||
fi
|
||||
fi
|
||||
|
||||
local raw_url="$url"
|
||||
local suffix="${raw_url##*.}"
|
||||
local raw_file_name="${uniq_path}.${suffix}"
|
||||
echo -e "开始下载:${raw_url} \n\n保存路径:$dir_raw/${raw_file_name}\n"
|
||||
|
||||
wget -q --no-check-certificate $proxyStr -O "$dir_raw/${raw_file_name}.new" ${raw_url}
|
||||
set_proxy "$proxy"
|
||||
wget -q --no-check-certificate -O "$dir_raw/${raw_file_name}.new" ${raw_url}
|
||||
exit_status=$?
|
||||
unset_proxy
|
||||
|
||||
if [[ $? -eq 0 ]]; then
|
||||
mv "$dir_raw/${raw_file_name}.new" "$dir_raw/${raw_file_name}"
|
||||
@@ -248,14 +242,14 @@ reload_qinglong() {
|
||||
fi
|
||||
|
||||
if [[ "$reload_target" == 'data' ]]; then
|
||||
rm -rf ${dir_root}/data/*
|
||||
mv -f ${dir_tmp}/data/* ${dir_root}/data/
|
||||
rm -rf ${dir_data}/*
|
||||
mv -f ${dir_tmp}/data/* ${dir_data}/
|
||||
fi
|
||||
|
||||
reload_pm2
|
||||
}
|
||||
|
||||
## 更新qinglong
|
||||
## 更新 qinglong
|
||||
update_qinglong() {
|
||||
rm -rf ${dir_tmp}/*
|
||||
local mirror="gitee"
|
||||
@@ -527,7 +521,7 @@ main() {
|
||||
raw)
|
||||
get_uniq_path "$p2"
|
||||
if [[ -n $p2 ]]; then
|
||||
update_raw "$p2" "$p3" "$p4"
|
||||
update_raw "$p2" "$p3" "$p4" "$p5"
|
||||
else
|
||||
eval echo -e "命令输入错误...\\\n" $cmd
|
||||
eval usage $cmd
|
||||
|
||||
@@ -57,6 +57,7 @@ import { useVT } from 'virtualizedtableforantd4';
|
||||
import { ICrontab, OperationName, OperationPath, CrontabStatus } from './type';
|
||||
import Name from '@/components/name';
|
||||
import dayjs from 'dayjs';
|
||||
import { noop } from 'lodash';
|
||||
|
||||
const { Text, Paragraph, Link } = Typography;
|
||||
const { Search } = Input;
|
||||
@@ -76,7 +77,7 @@ const Crontab = () => {
|
||||
wordBreak: 'break-all',
|
||||
marginBottom: 0,
|
||||
color: '#1890ff',
|
||||
cursor: 'pointer'
|
||||
cursor: 'pointer',
|
||||
}}
|
||||
ellipsis={{ tooltip: text, rows: 2 }}
|
||||
onClick={() => {
|
||||
@@ -270,9 +271,14 @@ const Crontab = () => {
|
||||
record.sub_id ? (
|
||||
<Name
|
||||
service={() =>
|
||||
request.get(`${config.apiPrefix}subscriptions/${record.sub_id}`)
|
||||
request.get(`${config.apiPrefix}subscriptions/${record.sub_id}`, {
|
||||
onError: noop,
|
||||
})
|
||||
}
|
||||
options={{ ready: record?.sub_id, cacheKey: record.sub_id }}
|
||||
options={{
|
||||
ready: record?.sub_id,
|
||||
cacheKey: record.sub_id,
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
'-'
|
||||
|
||||
+28
-9
@@ -1,29 +1,44 @@
|
||||
import intl from 'react-intl-universal'
|
||||
import intl from 'react-intl-universal';
|
||||
import { message } from 'antd';
|
||||
import config from './config';
|
||||
import { history } from '@umijs/max';
|
||||
import axios, { AxiosError, AxiosInstance, AxiosRequestConfig } from 'axios';
|
||||
import axios, {
|
||||
AxiosError,
|
||||
AxiosInstance,
|
||||
AxiosRequestConfig,
|
||||
AxiosResponse,
|
||||
InternalAxiosRequestConfig,
|
||||
} from 'axios';
|
||||
|
||||
interface IResponseData {
|
||||
export interface IResponseData {
|
||||
code?: number;
|
||||
data?: any;
|
||||
message?: string;
|
||||
error?: any;
|
||||
}
|
||||
|
||||
type Override<
|
||||
export type Override<
|
||||
T,
|
||||
K extends Partial<{ [P in keyof T]: any }> | string,
|
||||
> = K extends string
|
||||
? Omit<T, K> & { [P in keyof T]: T[P] | unknown }
|
||||
: Omit<T, keyof K> & K;
|
||||
|
||||
export interface ICustomConfig {
|
||||
onError?: (res: AxiosResponse<unknown, any>) => void;
|
||||
}
|
||||
|
||||
message.config({
|
||||
duration: 2,
|
||||
});
|
||||
|
||||
const time = Date.now();
|
||||
const errorHandler = function (error: AxiosError) {
|
||||
const errorHandler = function (
|
||||
error: Override<
|
||||
AxiosError<IResponseData>,
|
||||
{ config: InternalAxiosRequestConfig & ICustomConfig }
|
||||
>,
|
||||
) {
|
||||
if (error.response) {
|
||||
const msg = error.response.data
|
||||
? error.response.data.message || error.message || error.response.data
|
||||
@@ -38,6 +53,10 @@ const errorHandler = function (error: AxiosError) {
|
||||
history.push('/login');
|
||||
}
|
||||
} else {
|
||||
if (typeof error.config?.onError === 'function') {
|
||||
return error.config?.onError(error.response);
|
||||
}
|
||||
|
||||
message.error({
|
||||
content: msg,
|
||||
style: { maxWidth: 500, margin: '0 auto' },
|
||||
@@ -105,21 +124,21 @@ export const request = _request as Override<
|
||||
{
|
||||
get<T = IResponseData, D = any>(
|
||||
url: string,
|
||||
config?: AxiosRequestConfig<D>,
|
||||
config?: AxiosRequestConfig<D> & ICustomConfig,
|
||||
): Promise<T>;
|
||||
delete<T = IResponseData, D = any>(
|
||||
url: string,
|
||||
config?: AxiosRequestConfig<D>,
|
||||
config?: AxiosRequestConfig<D> & ICustomConfig,
|
||||
): Promise<T>;
|
||||
post<T = IResponseData, D = any>(
|
||||
url: string,
|
||||
data?: D,
|
||||
config?: AxiosRequestConfig<D>,
|
||||
config?: AxiosRequestConfig<D> & ICustomConfig,
|
||||
): Promise<T>;
|
||||
put<T = IResponseData, D = any>(
|
||||
url: string,
|
||||
data?: D,
|
||||
config?: AxiosRequestConfig<D>,
|
||||
config?: AxiosRequestConfig<D> & ICustomConfig,
|
||||
): Promise<T>;
|
||||
}
|
||||
>;
|
||||
|
||||
+6
-8
@@ -1,9 +1,7 @@
|
||||
version: 2.17.5
|
||||
changeLogLink: https://t.me/jiao_long/406
|
||||
publishTime: 2024-05-25 19:00
|
||||
version: 2.17.6
|
||||
changeLogLink: https://t.me/jiao_long/407
|
||||
publishTime: 2024-06-14 23:00
|
||||
changeLog: |
|
||||
1. 修复有可能手动运行任务无日志
|
||||
2. 重构 JavaScript 脚本通知文件
|
||||
3. PushMe 通知支持自建服务
|
||||
4. 增加微加机器人消息通道
|
||||
5. 修复任务详情查看脚本错误
|
||||
1. bark 推送改为 post 请求,防止请求头过大
|
||||
2. 修复单文件订阅代理无效
|
||||
3. 修复系统设置通知和依赖数据未初始化
|
||||
|
||||
Reference in New Issue
Block a user