mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-22 22:36:06 +08:00
订阅支持自动添加和删除任务设置
This commit is contained in:
parent
46c9774efa
commit
76fa82c3a7
|
@ -50,6 +50,8 @@ export default (app: Router) => {
|
|||
schedule_type: Joi.string().required(),
|
||||
alias: Joi.string().required(),
|
||||
proxy: Joi.string().optional().allow('').allow(null),
|
||||
autoAddCron: Joi.boolean().optional().allow('').allow(null),
|
||||
autoDelCron: Joi.boolean().optional().allow('').allow(null),
|
||||
}),
|
||||
}),
|
||||
async (req: Request, res: Response, next: NextFunction) => {
|
||||
|
@ -179,6 +181,8 @@ export default (app: Router) => {
|
|||
sub_after: Joi.string().optional().allow('').allow(null),
|
||||
alias: Joi.string().required(),
|
||||
proxy: Joi.string().optional().allow('').allow(null),
|
||||
autoAddCron: Joi.boolean().optional().allow('').allow(null),
|
||||
autoDelCron: Joi.boolean().optional().allow('').allow(null),
|
||||
id: Joi.number().required(),
|
||||
}),
|
||||
}),
|
||||
|
|
|
@ -29,6 +29,8 @@ export class Subscription {
|
|||
sub_before?: string;
|
||||
sub_after?: string;
|
||||
proxy?: string;
|
||||
autoAddCron?: 1 | 0;
|
||||
autoDelCron?: 1 | 0;
|
||||
|
||||
constructor(options: Subscription) {
|
||||
this.id = options.id;
|
||||
|
@ -56,6 +58,8 @@ export class Subscription {
|
|||
this.sub_before = options.sub_before;
|
||||
this.sub_after = options.sub_after;
|
||||
this.proxy = options.proxy;
|
||||
this.autoAddCron = options.autoAddCron ? 1 : 0;
|
||||
this.autoDelCron = options.autoDelCron ? 1 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -105,5 +109,7 @@ export const SubscriptionModel = sequelize.define<SubscriptionInstance>(
|
|||
schedule_type: DataTypes.STRING,
|
||||
alias: { type: DataTypes.STRING, unique: 'alias' },
|
||||
proxy: { type: DataTypes.STRING, allowNull: true },
|
||||
autoAddCron: { type: DataTypes.NUMBER, allowNull: true },
|
||||
autoDelCron: { type: DataTypes.NUMBER, allowNull: true },
|
||||
},
|
||||
);
|
||||
|
|
|
@ -36,6 +36,16 @@ export default async () => {
|
|||
try {
|
||||
await sequelize.query('alter table CrontabViews add column type NUMBER');
|
||||
} catch (error) {}
|
||||
try {
|
||||
await sequelize.query(
|
||||
'alter table Subscriptions add column autoAddCron NUMBER',
|
||||
);
|
||||
} catch (error) {}
|
||||
try {
|
||||
await sequelize.query(
|
||||
'alter table Subscriptions add column autoDelCron NUMBER',
|
||||
);
|
||||
} catch (error) {}
|
||||
|
||||
// 2.10-2.11 升级
|
||||
const cronDbFile = path.join(config.rootPath, 'db/crontab.db');
|
||||
|
|
|
@ -84,13 +84,17 @@ export default class SubscriptionService {
|
|||
branch,
|
||||
extensions,
|
||||
proxy,
|
||||
autoAddCron,
|
||||
autoDelCron,
|
||||
} = doc;
|
||||
if (type === 'file') {
|
||||
command += `raw "${_url}"`;
|
||||
} else {
|
||||
command += `repo "${_url}" "${whitelist || ''}" "${blacklist || ''}" "${
|
||||
dependences || ''
|
||||
}" "${branch || ''}" "${extensions || ''}" "${proxy || ''}"`;
|
||||
}" "${branch || ''}" "${extensions || ''}" "${proxy || ''}" "${
|
||||
Boolean(autoAddCron) || ''
|
||||
}" "${Boolean(autoDelCron) || ''}"`;
|
||||
}
|
||||
return command;
|
||||
}
|
||||
|
@ -280,7 +284,8 @@ export default class SubscriptionService {
|
|||
}
|
||||
|
||||
public async update(payload: Subscription): Promise<Subscription> {
|
||||
const newDoc = await this.updateDb(payload);
|
||||
const tab = new Subscription(payload);
|
||||
const newDoc = await this.updateDb(tab);
|
||||
await this.handleTask(newDoc, !newDoc.is_disabled);
|
||||
return newDoc;
|
||||
}
|
||||
|
|
|
@ -118,6 +118,8 @@ update_repo() {
|
|||
local branch="$5"
|
||||
local extensions="$6"
|
||||
local proxy="$7"
|
||||
local autoAddCron="$8"
|
||||
local autoDelCron="$9"
|
||||
local tmp="${url%/*}"
|
||||
local authorTmp1="${tmp##*/}"
|
||||
local authorTmp2="${authorTmp1##*:}"
|
||||
|
@ -137,7 +139,7 @@ update_repo() {
|
|||
fi
|
||||
if [[ $exit_status -eq 0 ]]; then
|
||||
echo -e "\n更新${repo_path}成功...\n"
|
||||
diff_scripts "$repo_path" "$author" "$path" "$blackword" "$dependence" "$extensions"
|
||||
diff_scripts "$repo_path" "$author" "$path" "$blackword" "$dependence" "$extensions" "$autoAddCron" "$autoDelCron"
|
||||
else
|
||||
echo -e "\n更新${repo_path}失败,请检查网络...\n"
|
||||
fi
|
||||
|
@ -288,6 +290,15 @@ diff_scripts() {
|
|||
local blackword="$4"
|
||||
local dependence="$5"
|
||||
local extensions="$6"
|
||||
local autoAddCron="$7"
|
||||
local autoDelCron="$8"
|
||||
|
||||
if [[ ! $autoAddCron ]];then
|
||||
autoAddCron=${AutoAddCron}
|
||||
fi
|
||||
if [[ ! $autoDelCron ]];then
|
||||
autoDelCron=${AutoDelCron}
|
||||
fi
|
||||
|
||||
gen_list_repo "$repo_path" "$author" "$path" "$blackword" "$dependence" "$extensions"
|
||||
|
||||
|
@ -297,13 +308,13 @@ diff_scripts() {
|
|||
|
||||
if [[ -s $list_drop ]]; then
|
||||
output_list_add_drop $list_drop "失效"
|
||||
if [[ ${AutoDelCron} == true ]]; then
|
||||
if [[ ${autoDelCron} == true ]]; then
|
||||
del_cron $list_drop $uniq_path
|
||||
fi
|
||||
fi
|
||||
if [[ -s $list_add ]]; then
|
||||
output_list_add_drop $list_add "新"
|
||||
if [[ ${AutoAddCron} == true ]]; then
|
||||
if [[ ${autoAddCron} == true ]]; then
|
||||
add_cron $list_add $uniq_path
|
||||
fi
|
||||
fi
|
||||
|
@ -404,13 +415,16 @@ main() {
|
|||
done
|
||||
[[ "$show_log" == "true" ]] && shift $(($OPTIND - 1))
|
||||
|
||||
local p1=$1
|
||||
local p2=$2
|
||||
local p3=$3
|
||||
local p4=$4
|
||||
local p5=$5
|
||||
local p6=$6
|
||||
local p7=$7
|
||||
local p1="${1}"
|
||||
local p2="${2}"
|
||||
local p3="${3}"
|
||||
local p4="${4}"
|
||||
local p5="${5}"
|
||||
local p6="${6}"
|
||||
local p7="${7}"
|
||||
local p8="${8}"
|
||||
local p9="${9}"
|
||||
local p10="${10}"
|
||||
local log_dir="${p1}"
|
||||
make_dir "$dir_log/$log_dir"
|
||||
local log_time=$(date "+%Y-%m-%d-%H-%M-%S")
|
||||
|
@ -452,7 +466,7 @@ main() {
|
|||
repo)
|
||||
get_uniq_path "$p2" "$p6"
|
||||
if [[ -n $p2 ]]; then
|
||||
update_repo "$p2" "$p3" "$p4" "$p5" "$p6" "$p7" "$p8"
|
||||
update_repo "$p2" "$p3" "$p4" "$p5" "$p6" "$p7" "$p8" "$p9" "$p10"
|
||||
else
|
||||
eval echo -e "命令输入错误...\\\n" $cmd
|
||||
eval usage $cmd
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
.inline-form-item {
|
||||
margin-bottom: 0;
|
||||
|
||||
.ant-form-item {
|
||||
display: inline-block;
|
||||
width: 50%;
|
||||
margin-bottom: 0px;
|
||||
}
|
||||
}
|
|
@ -1,5 +1,14 @@
|
|||
import React, { useCallback, useEffect, useState } from 'react';
|
||||
import { Modal, message, InputNumber, Form, Radio, Select, Input } from 'antd';
|
||||
import {
|
||||
Modal,
|
||||
message,
|
||||
InputNumber,
|
||||
Form,
|
||||
Radio,
|
||||
Select,
|
||||
Input,
|
||||
Switch,
|
||||
} from 'antd';
|
||||
import { request } from '@/utils/http';
|
||||
import config from '@/utils/config';
|
||||
import cron_parser from 'cron-parser';
|
||||
|
@ -26,7 +35,11 @@ const SubscriptionModal = ({
|
|||
const handleOk = async (values: any) => {
|
||||
setLoading(true);
|
||||
const method = subscription ? 'put' : 'post';
|
||||
const payload = { ...values };
|
||||
const payload = {
|
||||
...values,
|
||||
autoAddCron: Boolean(values.autoAddCron),
|
||||
autoDelCron: Boolean(values.autoDelCron),
|
||||
};
|
||||
if (subscription) {
|
||||
payload.id = subscription.id;
|
||||
}
|
||||
|
@ -110,8 +123,8 @@ const SubscriptionModal = ({
|
|||
}
|
||||
};
|
||||
|
||||
const numberChange = (value: number) => {
|
||||
setIntervalNumber(value);
|
||||
const numberChange = (value: number | null) => {
|
||||
setIntervalNumber(value || 1);
|
||||
if (!value) {
|
||||
onChange?.(null);
|
||||
} else {
|
||||
|
@ -452,6 +465,24 @@ const SubscriptionModal = ({
|
|||
}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item style={{ marginBottom: 0 }} className="inline-form-item">
|
||||
<Form.Item
|
||||
name="autoAddCron"
|
||||
label="自动添加任务"
|
||||
valuePropName="checked"
|
||||
initialValue={true}
|
||||
>
|
||||
<Switch />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
name="autoDelCron"
|
||||
label="自动删除任务"
|
||||
valuePropName="checked"
|
||||
initialValue={true}
|
||||
>
|
||||
<Switch />
|
||||
</Form.Item>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue
Block a user