更新新建文件订阅

This commit is contained in:
whyour
2022-05-15 15:25:23 +08:00
parent 5523d537dc
commit f6a122e5ea
7 changed files with 344 additions and 84 deletions
+2 -2
View File
@@ -29,7 +29,7 @@ export default (app: Router) => {
body: Joi.object({
type: Joi.string().required(),
schedule: Joi.string().optional(),
intervalSchedule: Joi.object().optional(),
interval_schedule: Joi.object().optional(),
name: Joi.string().optional(),
url: Joi.string().required(),
whitelist: Joi.string().optional(),
@@ -158,7 +158,7 @@ export default (app: Router) => {
body: Joi.object({
type: Joi.string().required(),
schedule: Joi.string().optional(),
intervalSchedule: Joi.object().optional(),
interval_schedule: Joi.object().optional(),
name: Joi.string().optional(),
url: Joi.string().required(),
whitelist: Joi.string().optional(),
+11 -6
View File
@@ -2,13 +2,14 @@ import { sequelize } from '.';
import { DataTypes, Model, ModelDefined } from 'sequelize';
import { SimpleIntervalSchedule } from 'toad-scheduler';
type SimpleIntervalScheduleUnit = keyof SimpleIntervalSchedule;
export class Subscription {
id?: number;
name?: string;
type?: 'public-repo' | 'private-repo' | 'file';
schedule_type?: 'crontab' | 'interval';
schedule?: string;
intervalSchedule?: SimpleIntervalSchedule;
interval_schedule?: { type: SimpleIntervalScheduleUnit; value: number };
url?: string;
whitelist?: string;
blacklist?: string;
@@ -20,7 +21,7 @@ export class Subscription {
| { private_key: string }
| { username: string; password: string };
pid?: number;
isDisabled?: 1 | 0;
is_disabled?: 1 | 0;
log_path?: string;
alias: string;
command?: string;
@@ -30,6 +31,10 @@ export class Subscription {
this.name = options.name;
this.type = options.type;
this.schedule = options.schedule;
this.status =
options.status && SubscriptionStatus[options.status]
? options.status
: SubscriptionStatus.idle;
this.url = options.url;
this.whitelist = options.whitelist;
this.blacklist = options.blacklist;
@@ -39,11 +44,11 @@ export class Subscription {
this.pull_type = options.pull_type;
this.pull_option = options.pull_option;
this.pid = options.pid;
this.isDisabled = options.isDisabled;
this.is_disabled = options.is_disabled;
this.log_path = options.log_path;
this.schedule_type = options.schedule_type;
this.alias = options.alias;
this.intervalSchedule = options.intervalSchedule;
this.interval_schedule = options.interval_schedule;
}
}
@@ -72,7 +77,7 @@ export const SubscriptionModel = sequelize.define<SubscriptionInstance>(
unique: 'compositeIndex',
type: DataTypes.STRING,
},
intervalSchedule: {
interval_schedule: {
unique: 'compositeIndex',
type: DataTypes.JSON,
},
@@ -85,7 +90,7 @@ export const SubscriptionModel = sequelize.define<SubscriptionInstance>(
pull_type: DataTypes.STRING,
pull_option: DataTypes.JSON,
pid: DataTypes.NUMBER,
isDisabled: DataTypes.NUMBER,
is_disabled: DataTypes.NUMBER,
log_path: DataTypes.STRING,
schedule_type: DataTypes.STRING,
alias: { type: DataTypes.STRING, unique: 'alias' },
+2 -1
View File
@@ -100,10 +100,11 @@ export default class SubscriptionService {
needCreate && this.scheduleService.createCronTask(doc as any);
} else {
this.scheduleService.cancelIntervalTask(doc as any);
const { type, value } = doc.interval_schedule as any;
needCreate &&
this.scheduleService.createIntervalTask(
doc as any,
doc.intervalSchedule as SimpleIntervalSchedule,
{ [type]: value } as SimpleIntervalSchedule,
);
}
}