增加初始化订阅任务

This commit is contained in:
whyour 2022-05-18 23:30:59 +08:00
parent 8011b4b793
commit 03bc5bb882
6 changed files with 24 additions and 7 deletions

View File

@ -2,10 +2,12 @@ import { Container } from 'typedi';
import _ from 'lodash';
import SystemService from '../services/system';
import ScheduleService from '../services/schedule';
import SubscriptionService from '../services/subscription';
export default async () => {
const systemService = Container.get(SystemService);
const scheduleService = Container.get(ScheduleService);
const subscriptionService = Container.get(SubscriptionService);
// 运行删除日志任务
const data = await systemService.getLogRemoveFrequency();
@ -20,4 +22,10 @@ export default async () => {
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 {
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[]) {

View File

@ -124,7 +124,7 @@ export default class SubscriptionService {
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);
if (doc.type === 'private-repo' && doc.pull_type === 'ssh-key') {
if (needAddKey) {

View File

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

View File

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

View File

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