完善拉取公开仓库

This commit is contained in:
whyour 2022-05-17 00:42:18 +08:00
parent f1a51638a5
commit 4e7a5c637d
9 changed files with 75 additions and 47 deletions

View File

@ -15,4 +15,5 @@ export type SockMessageType =
| 'installDependence'
| 'uninstallDependence'
| 'updateSystemVersion'
| 'manuallyRunScript';
| 'manuallyRunScript'
| 'runSubscriptionEnd';

View File

@ -40,7 +40,6 @@ export class Subscription {
this.blacklist = options.blacklist;
this.dependences = options.dependences;
this.branch = options.branch;
this.status = options.status;
this.pull_type = options.pull_type;
this.pull_option = options.pull_option;
this.pid = options.pid;

View File

@ -26,12 +26,14 @@ import { Op } from 'sequelize';
import path from 'path';
import ScheduleService, { TaskCallbacks } from './schedule';
import { SimpleIntervalSchedule } from 'toad-scheduler';
import SockService from './sock';
@Service()
export default class SubscriptionService {
constructor(
@Inject('logger') private logger: winston.Logger,
private scheduleService: ScheduleService,
private sockService: SockService,
) {}
public async list(searchText?: string): Promise<Subscription[]> {
@ -94,11 +96,11 @@ export default class SubscriptionService {
let command = 'ql ';
const { type, url, whitelist, blacklist, dependences, branch } = doc;
if (type === 'file') {
command += `raw ${url}`;
command += `raw "${url}"`;
} else {
command += `repo ${url} ${whitelist || ''} ${blacklist || ''} ${
command += `repo "${url}" "${whitelist || ''}" "${blacklist || ''}" "${
dependences || ''
} ${branch || ''}`;
}" "${branch || ''}"`;
}
return command;
}
@ -168,6 +170,11 @@ export default class SubscriptionService {
'YYYY-MM-DD HH:mm:ss',
)} ${diff} `,
);
this.sockService.sendMessage({
type: 'runSubscriptionEnd',
message: '订阅执行完成',
references: [doc.id as number],
});
},
onError: async (message: string) => {
const sub = await this.getDb({ id: doc.id });
@ -179,6 +186,7 @@ export default class SubscriptionService {
public async create(payload: Subscription): Promise<Subscription> {
const tab = new Subscription(payload);
console.log(tab);
const doc = await this.insert(tab);
this.handleTask(doc);
return doc;
@ -231,6 +239,10 @@ export default class SubscriptionService {
}
public async remove(ids: number[]) {
const docs = await SubscriptionModel.findAll({ where: { id: ids } });
for (const doc of docs) {
this.handleTask(doc, false);
}
await SubscriptionModel.destroy({ where: { id: ids } });
}

View File

@ -200,18 +200,9 @@ const Crontab = ({ headerStyle, isPhone, theme }: any) => {
},
},
render: (text: string, record: any) => {
const language = navigator.language || navigator.languages[0];
return (
<span
style={{
display: 'block',
}}
>
{record.last_running_time
? diffTime(record.last_running_time)
: '-'}
</span>
);
return record.last_running_time
? diffTime(record.last_running_time)
: '-';
},
},
{
@ -225,19 +216,11 @@ const Crontab = ({ headerStyle, isPhone, theme }: any) => {
},
render: (text: string, record: any) => {
const language = navigator.language || navigator.languages[0];
return (
<span
style={{
display: 'block',
}}
>
{record.nextRunTime
.toLocaleString(language, {
hour12: false,
})
.replace(' 24:', ' 00:')}
</span>
);
return record.nextRunTime
.toLocaleString(language, {
hour12: false,
})
.replace(' 24:', ' 00:');
},
},

View File

@ -95,7 +95,7 @@ const CronLogModal = ({
<>
{(executing || loading) && <Loading3QuartersOutlined spin />}
{!executing && !loading && <CheckCircleOutlined />}
<span style={{ marginLeft: 5 }}>-{cron && cron.name}</span>{' '}
<span style={{ marginLeft: 5 }}>{cron && cron.name}</span>
</>
);
};

View File

@ -21,7 +21,7 @@ const columns = [
align: 'center' as const,
width: 50,
render: (text: string, record: any, index: number) => {
return <span style={{ cursor: 'text' }}>{index + 1} </span>;
return index + 1;
},
},
{
@ -30,7 +30,7 @@ const columns = [
key: 'timestamp',
align: 'center' as const,
render: (text: string, record: any) => {
return <span>{new Date(record.timestamp).toLocaleString()}</span>;
return new Date(record.timestamp).toLocaleString();
},
},
{

View File

@ -51,7 +51,7 @@ export enum IntervalSchedule {
'seconds' = '秒',
}
const Subscription = ({ headerStyle, isPhone, theme }: any) => {
const Subscription = ({ headerStyle, isPhone, socketMessage }: any) => {
const columns: any = [
{
title: '名称',
@ -73,6 +73,20 @@ const Subscription = ({ headerStyle, isPhone, theme }: any) => {
compare: (a: any, b: any) => a.name.localeCompare(b.name),
multiple: 2,
},
render: (text: string, record: any) => {
return (
<Paragraph
style={{
wordBreak: 'break-all',
marginBottom: 0,
textAlign: 'left',
}}
ellipsis={{ tooltip: text, rows: 2 }}
>
{text}
</Paragraph>
);
},
},
{
title: '分支',
@ -80,20 +94,20 @@ const Subscription = ({ headerStyle, isPhone, theme }: any) => {
key: 'branch',
width: 130,
align: 'center' as const,
render: (text: string, record: any) => {
return record.branch || '-';
},
},
{
title: '定时规则',
width: 180,
align: 'center' as const,
render: (text: string, record: any) => {
const { type, value } = record.interval_schedule;
return (
<span>
{record.schedule_type === 'interval'
? `${value}${(IntervalSchedule as any)[type]}`
: record.schedule}
</span>
);
if (record.schedule_type === 'interval') {
const { type, value } = record.interval_schedule;
return `${value}${(IntervalSchedule as any)[type]}`;
}
return record.schedule;
},
},
{
@ -472,6 +486,22 @@ const Subscription = ({ headerStyle, isPhone, theme }: any) => {
: 'subscription';
};
useEffect(() => {
if (!socketMessage) return;
const { type, message, references } = socketMessage;
if (type === 'runSubscriptionEnd' && references.length > 0) {
const result = [...value];
for (let i = 0; i < references.length; i++) {
const index = value.findIndex((x) => x.id === references[i]);
result.splice(index, 1, {
...result[index],
status: SubscriptionStatus.idle,
});
}
setValue(result);
}
}, [socketMessage]);
useEffect(() => {
if (logSubscription) {
localStorage.setItem('logSubscription', logSubscription.id);

View File

@ -68,8 +68,8 @@ const SubscriptionLogModal = ({
{(executing || loading) && <Loading3QuartersOutlined spin />}
{!executing && !loading && <CheckCircleOutlined />}
<span style={{ marginLeft: 5 }}>
-{subscription && subscription.name}
</span>{' '}
{subscription && subscription.name}
</span>
</>
);
};

View File

@ -174,6 +174,9 @@ const SubscriptionModal = ({
setType((subscription && subscription.type) || 'public-repo');
setScheduleType((subscription && subscription.schedule_type) || 'crontab');
setPullType((subscription && subscription.pull_type) || 'ssh-key');
if (!subscription) {
form.resetFields();
}
}, [subscription, visible]);
return (
@ -300,7 +303,7 @@ const SubscriptionModal = ({
{type !== 'file' && (
<>
<Form.Item
name="command"
name="whitelist"
label="白名单"
rules={[{ whitespace: true }]}
tooltip="多个关键词竖线分割,支持正则表达式"
@ -312,7 +315,7 @@ const SubscriptionModal = ({
/>
</Form.Item>
<Form.Item
name="command"
name="blacklist"
label="黑名单"
rules={[{ whitespace: true }]}
tooltip="多个关键词竖线分割,支持正则表达式"
@ -324,7 +327,7 @@ const SubscriptionModal = ({
/>
</Form.Item>
<Form.Item
name="command"
name="dependences"
label="依赖文件"
rules={[{ whitespace: true }]}
tooltip="多个关键词竖线分割,支持正则表达式"