增加初始化订阅任务

This commit is contained in:
whyour 2022-05-18 23:30:59 +08:00
parent d2c2ea8d3b
commit 460a1750f4
6 changed files with 24 additions and 7 deletions

View File

@ -2,10 +2,12 @@ import { Container } from 'typedi';
import _ from 'lodash'; import _ from 'lodash';
import SystemService from '../services/system'; import SystemService from '../services/system';
import ScheduleService from '../services/schedule'; import ScheduleService from '../services/schedule';
import SubscriptionService from '../services/subscription';
export default async () => { export default async () => {
const systemService = Container.get(SystemService); const systemService = Container.get(SystemService);
const scheduleService = Container.get(ScheduleService); const scheduleService = Container.get(ScheduleService);
const subscriptionService = Container.get(SubscriptionService);
// 运行删除日志任务 // 运行删除日志任务
const data = await systemService.getLogRemoveFrequency(); const data = await systemService.getLogRemoveFrequency();
@ -20,4 +22,10 @@ export default async () => {
runImmediately: true, runImmediately: true,
}); });
} }
// 运行所有订阅
const subs = await subscriptionService.list();
for (const sub of subs) {
await subscriptionService.handleTask(sub);
}
}; };

View File

@ -32,7 +32,7 @@ export default class SshKeyService {
} }
private generateSingleSshConfig(alias: string, host: string): string { private generateSingleSshConfig(alias: string, host: string): string {
return `\nHost ${alias}\n Hostname ${host}\n IdentityFile=${this.sshPath}/${alias}\n StrictHostKeyChecking no`; return `\nHost ${alias}\n Hostname ${host}\n IdentityFile ${this.sshPath}/${alias}\n StrictHostKeyChecking no`;
} }
private generateSshConfig(configs: string[]) { private generateSshConfig(configs: string[]) {

View File

@ -124,7 +124,7 @@ export default class SubscriptionService {
return { url, host }; return { url, host };
} }
private handleTask(doc: Subscription, needCreate = true, needAddKey = true) { public handleTask(doc: Subscription, needCreate = true, needAddKey = true) {
const { url, host } = this.formatUrl(doc); const { url, host } = this.formatUrl(doc);
if (doc.type === 'private-repo' && doc.pull_type === 'ssh-key') { if (doc.type === 'private-repo' && doc.pull_type === 'ssh-key') {
if (needAddKey) { if (needAddKey) {

View File

@ -75,6 +75,7 @@ const CronModal = ({
<Form.Item <Form.Item
name="command" name="command"
label="命令" label="命令"
normalize={(value) => value.trim()}
rules={[{ required: true, whitespace: true }]} rules={[{ required: true, whitespace: true }]}
> >
<Input.TextArea <Input.TextArea
@ -86,6 +87,7 @@ const CronModal = ({
<Form.Item <Form.Item
name="schedule" name="schedule"
label="定时规则" label="定时规则"
normalize={(value) => value.trim()}
rules={[ rules={[
{ required: true }, { required: true },
{ {

View File

@ -79,6 +79,7 @@ const EnvModal = ({
<Form.Item <Form.Item
name="name" name="name"
label="名称" label="名称"
normalize={(value) => value.trim()}
rules={[ rules={[
{ required: true, message: '请输入环境变量名称', whitespace: true }, { required: true, message: '请输入环境变量名称', whitespace: true },
{ {
@ -105,6 +106,7 @@ const EnvModal = ({
<Form.Item <Form.Item
name="value" name="value"
label="值" label="值"
normalize={(value) => value.trim()}
rules={[ rules={[
{ required: true, message: '请输入环境变量值', whitespace: true }, { required: true, message: '请输入环境变量值', whitespace: true },
]} ]}

View File

@ -225,12 +225,13 @@ const SubscriptionModal = ({
<Radio.Group onChange={typeChange}> <Radio.Group onChange={typeChange}>
<Radio value="public-repo"></Radio> <Radio value="public-repo"></Radio>
<Radio value="private-repo"></Radio> <Radio value="private-repo"></Radio>
<Radio value="file"></Radio> <Radio value="file"></Radio>
</Radio.Group> </Radio.Group>
</Form.Item> </Form.Item>
<Form.Item <Form.Item
name="url" name="url"
label="链接" label="链接"
normalize={(value) => value.trim()}
rules={[ rules={[
{ required: true }, { required: true },
{ pattern: type === 'file' ? fileUrlRegx : repoUrlRegx }, { pattern: type === 'file' ? fileUrlRegx : repoUrlRegx },
@ -245,7 +246,11 @@ const SubscriptionModal = ({
/> />
</Form.Item> </Form.Item>
{type !== 'file' && ( {type !== 'file' && (
<Form.Item name="branch" label="分支"> <Form.Item
name="branch"
label="分支"
normalize={(value) => value.trim()}
>
<Input <Input
placeholder="请输入分支" placeholder="请输入分支"
onPaste={onBranchChange} onPaste={onBranchChange}
@ -319,7 +324,7 @@ const SubscriptionModal = ({
<Form.Item <Form.Item
name="whitelist" name="whitelist"
label="白名单" label="白名单"
rules={[{ whitespace: true }]} normalize={(value) => value.trim()}
tooltip="多个关键词竖线分割,支持正则表达式" tooltip="多个关键词竖线分割,支持正则表达式"
> >
<Input.TextArea <Input.TextArea
@ -331,7 +336,7 @@ const SubscriptionModal = ({
<Form.Item <Form.Item
name="blacklist" name="blacklist"
label="黑名单" label="黑名单"
rules={[{ whitespace: true }]} normalize={(value) => value.trim()}
tooltip="多个关键词竖线分割,支持正则表达式" tooltip="多个关键词竖线分割,支持正则表达式"
> >
<Input.TextArea <Input.TextArea
@ -343,7 +348,7 @@ const SubscriptionModal = ({
<Form.Item <Form.Item
name="dependences" name="dependences"
label="依赖文件" label="依赖文件"
rules={[{ whitespace: true }]} normalize={(value) => value.trim()}
tooltip="多个关键词竖线分割,支持正则表达式" tooltip="多个关键词竖线分割,支持正则表达式"
> >
<Input.TextArea <Input.TextArea