mirror of
				https://github.com/whyour/qinglong.git
				synced 2025-11-04 11:16:07 +08:00 
			
		
		
		
	完善拉取公开仓库
This commit is contained in:
		
							parent
							
								
									f1a51638a5
								
							
						
					
					
						commit
						4e7a5c637d
					
				| 
						 | 
					@ -15,4 +15,5 @@ export type SockMessageType =
 | 
				
			||||||
  | 'installDependence'
 | 
					  | 'installDependence'
 | 
				
			||||||
  | 'uninstallDependence'
 | 
					  | 'uninstallDependence'
 | 
				
			||||||
  | 'updateSystemVersion'
 | 
					  | 'updateSystemVersion'
 | 
				
			||||||
  | 'manuallyRunScript';
 | 
					  | 'manuallyRunScript'
 | 
				
			||||||
 | 
					  | 'runSubscriptionEnd';
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -40,7 +40,6 @@ export class Subscription {
 | 
				
			||||||
    this.blacklist = options.blacklist;
 | 
					    this.blacklist = options.blacklist;
 | 
				
			||||||
    this.dependences = options.dependences;
 | 
					    this.dependences = options.dependences;
 | 
				
			||||||
    this.branch = options.branch;
 | 
					    this.branch = options.branch;
 | 
				
			||||||
    this.status = options.status;
 | 
					 | 
				
			||||||
    this.pull_type = options.pull_type;
 | 
					    this.pull_type = options.pull_type;
 | 
				
			||||||
    this.pull_option = options.pull_option;
 | 
					    this.pull_option = options.pull_option;
 | 
				
			||||||
    this.pid = options.pid;
 | 
					    this.pid = options.pid;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -26,12 +26,14 @@ import { Op } from 'sequelize';
 | 
				
			||||||
import path from 'path';
 | 
					import path from 'path';
 | 
				
			||||||
import ScheduleService, { TaskCallbacks } from './schedule';
 | 
					import ScheduleService, { TaskCallbacks } from './schedule';
 | 
				
			||||||
import { SimpleIntervalSchedule } from 'toad-scheduler';
 | 
					import { SimpleIntervalSchedule } from 'toad-scheduler';
 | 
				
			||||||
 | 
					import SockService from './sock';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@Service()
 | 
					@Service()
 | 
				
			||||||
export default class SubscriptionService {
 | 
					export default class SubscriptionService {
 | 
				
			||||||
  constructor(
 | 
					  constructor(
 | 
				
			||||||
    @Inject('logger') private logger: winston.Logger,
 | 
					    @Inject('logger') private logger: winston.Logger,
 | 
				
			||||||
    private scheduleService: ScheduleService,
 | 
					    private scheduleService: ScheduleService,
 | 
				
			||||||
 | 
					    private sockService: SockService,
 | 
				
			||||||
  ) {}
 | 
					  ) {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  public async list(searchText?: string): Promise<Subscription[]> {
 | 
					  public async list(searchText?: string): Promise<Subscription[]> {
 | 
				
			||||||
| 
						 | 
					@ -94,11 +96,11 @@ export default class SubscriptionService {
 | 
				
			||||||
    let command = 'ql ';
 | 
					    let command = 'ql ';
 | 
				
			||||||
    const { type, url, whitelist, blacklist, dependences, branch } = doc;
 | 
					    const { type, url, whitelist, blacklist, dependences, branch } = doc;
 | 
				
			||||||
    if (type === 'file') {
 | 
					    if (type === 'file') {
 | 
				
			||||||
      command += `raw ${url}`;
 | 
					      command += `raw "${url}"`;
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
      command += `repo ${url} ${whitelist || ''} ${blacklist || ''} ${
 | 
					      command += `repo "${url}" "${whitelist || ''}" "${blacklist || ''}" "${
 | 
				
			||||||
        dependences || ''
 | 
					        dependences || ''
 | 
				
			||||||
      } ${branch || ''}`;
 | 
					      }" "${branch || ''}"`;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    return command;
 | 
					    return command;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
| 
						 | 
					@ -168,6 +170,11 @@ export default class SubscriptionService {
 | 
				
			||||||
            'YYYY-MM-DD HH:mm:ss',
 | 
					            'YYYY-MM-DD HH:mm:ss',
 | 
				
			||||||
          )}  耗时 ${diff} 秒`,
 | 
					          )}  耗时 ${diff} 秒`,
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
 | 
					        this.sockService.sendMessage({
 | 
				
			||||||
 | 
					          type: 'runSubscriptionEnd',
 | 
				
			||||||
 | 
					          message: '订阅执行完成',
 | 
				
			||||||
 | 
					          references: [doc.id as number],
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
      onError: async (message: string) => {
 | 
					      onError: async (message: string) => {
 | 
				
			||||||
        const sub = await this.getDb({ id: doc.id });
 | 
					        const sub = await this.getDb({ id: doc.id });
 | 
				
			||||||
| 
						 | 
					@ -179,6 +186,7 @@ export default class SubscriptionService {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  public async create(payload: Subscription): Promise<Subscription> {
 | 
					  public async create(payload: Subscription): Promise<Subscription> {
 | 
				
			||||||
    const tab = new Subscription(payload);
 | 
					    const tab = new Subscription(payload);
 | 
				
			||||||
 | 
					    console.log(tab);
 | 
				
			||||||
    const doc = await this.insert(tab);
 | 
					    const doc = await this.insert(tab);
 | 
				
			||||||
    this.handleTask(doc);
 | 
					    this.handleTask(doc);
 | 
				
			||||||
    return doc;
 | 
					    return doc;
 | 
				
			||||||
| 
						 | 
					@ -231,6 +239,10 @@ export default class SubscriptionService {
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  public async remove(ids: number[]) {
 | 
					  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 } });
 | 
					    await SubscriptionModel.destroy({ where: { id: ids } });
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -200,18 +200,9 @@ const Crontab = ({ headerStyle, isPhone, theme }: any) => {
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
      render: (text: string, record: any) => {
 | 
					      render: (text: string, record: any) => {
 | 
				
			||||||
        const language = navigator.language || navigator.languages[0];
 | 
					        return record.last_running_time
 | 
				
			||||||
        return (
 | 
					 | 
				
			||||||
          <span
 | 
					 | 
				
			||||||
            style={{
 | 
					 | 
				
			||||||
              display: 'block',
 | 
					 | 
				
			||||||
            }}
 | 
					 | 
				
			||||||
          >
 | 
					 | 
				
			||||||
            {record.last_running_time
 | 
					 | 
				
			||||||
          ? diffTime(record.last_running_time)
 | 
					          ? diffTime(record.last_running_time)
 | 
				
			||||||
              : '-'}
 | 
					          : '-';
 | 
				
			||||||
          </span>
 | 
					 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
| 
						 | 
					@ -225,19 +216,11 @@ const Crontab = ({ headerStyle, isPhone, theme }: any) => {
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
      render: (text: string, record: any) => {
 | 
					      render: (text: string, record: any) => {
 | 
				
			||||||
        const language = navigator.language || navigator.languages[0];
 | 
					        const language = navigator.language || navigator.languages[0];
 | 
				
			||||||
        return (
 | 
					        return record.nextRunTime
 | 
				
			||||||
          <span
 | 
					 | 
				
			||||||
            style={{
 | 
					 | 
				
			||||||
              display: 'block',
 | 
					 | 
				
			||||||
            }}
 | 
					 | 
				
			||||||
          >
 | 
					 | 
				
			||||||
            {record.nextRunTime
 | 
					 | 
				
			||||||
          .toLocaleString(language, {
 | 
					          .toLocaleString(language, {
 | 
				
			||||||
            hour12: false,
 | 
					            hour12: false,
 | 
				
			||||||
          })
 | 
					          })
 | 
				
			||||||
              .replace(' 24:', ' 00:')}
 | 
					          .replace(' 24:', ' 00:');
 | 
				
			||||||
          </span>
 | 
					 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -95,7 +95,7 @@ const CronLogModal = ({
 | 
				
			||||||
      <>
 | 
					      <>
 | 
				
			||||||
        {(executing || loading) && <Loading3QuartersOutlined spin />}
 | 
					        {(executing || loading) && <Loading3QuartersOutlined spin />}
 | 
				
			||||||
        {!executing && !loading && <CheckCircleOutlined />}
 | 
					        {!executing && !loading && <CheckCircleOutlined />}
 | 
				
			||||||
        <span style={{ marginLeft: 5 }}>日志-{cron && cron.name}</span>{' '}
 | 
					        <span style={{ marginLeft: 5 }}>{cron && cron.name}</span>
 | 
				
			||||||
      </>
 | 
					      </>
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -21,7 +21,7 @@ const columns = [
 | 
				
			||||||
    align: 'center' as const,
 | 
					    align: 'center' as const,
 | 
				
			||||||
    width: 50,
 | 
					    width: 50,
 | 
				
			||||||
    render: (text: string, record: any, index: number) => {
 | 
					    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',
 | 
					    key: 'timestamp',
 | 
				
			||||||
    align: 'center' as const,
 | 
					    align: 'center' as const,
 | 
				
			||||||
    render: (text: string, record: any) => {
 | 
					    render: (text: string, record: any) => {
 | 
				
			||||||
      return <span>{new Date(record.timestamp).toLocaleString()}</span>;
 | 
					      return new Date(record.timestamp).toLocaleString();
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  {
 | 
					  {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -51,7 +51,7 @@ export enum IntervalSchedule {
 | 
				
			||||||
  'seconds' = '秒',
 | 
					  'seconds' = '秒',
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const Subscription = ({ headerStyle, isPhone, theme }: any) => {
 | 
					const Subscription = ({ headerStyle, isPhone, socketMessage }: any) => {
 | 
				
			||||||
  const columns: any = [
 | 
					  const columns: any = [
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
      title: '名称',
 | 
					      title: '名称',
 | 
				
			||||||
| 
						 | 
					@ -73,6 +73,20 @@ const Subscription = ({ headerStyle, isPhone, theme }: any) => {
 | 
				
			||||||
        compare: (a: any, b: any) => a.name.localeCompare(b.name),
 | 
					        compare: (a: any, b: any) => a.name.localeCompare(b.name),
 | 
				
			||||||
        multiple: 2,
 | 
					        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: '分支',
 | 
					      title: '分支',
 | 
				
			||||||
| 
						 | 
					@ -80,20 +94,20 @@ const Subscription = ({ headerStyle, isPhone, theme }: any) => {
 | 
				
			||||||
      key: 'branch',
 | 
					      key: 'branch',
 | 
				
			||||||
      width: 130,
 | 
					      width: 130,
 | 
				
			||||||
      align: 'center' as const,
 | 
					      align: 'center' as const,
 | 
				
			||||||
 | 
					      render: (text: string, record: any) => {
 | 
				
			||||||
 | 
					        return record.branch || '-';
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
      title: '定时规则',
 | 
					      title: '定时规则',
 | 
				
			||||||
      width: 180,
 | 
					      width: 180,
 | 
				
			||||||
      align: 'center' as const,
 | 
					      align: 'center' as const,
 | 
				
			||||||
      render: (text: string, record: any) => {
 | 
					      render: (text: string, record: any) => {
 | 
				
			||||||
 | 
					        if (record.schedule_type === 'interval') {
 | 
				
			||||||
          const { type, value } = record.interval_schedule;
 | 
					          const { type, value } = record.interval_schedule;
 | 
				
			||||||
        return (
 | 
					          return `每${value}${(IntervalSchedule as any)[type]}`;
 | 
				
			||||||
          <span>
 | 
					        }
 | 
				
			||||||
            {record.schedule_type === 'interval'
 | 
					        return record.schedule;
 | 
				
			||||||
              ? `每${value}${(IntervalSchedule as any)[type]}`
 | 
					 | 
				
			||||||
              : record.schedule}
 | 
					 | 
				
			||||||
          </span>
 | 
					 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
| 
						 | 
					@ -472,6 +486,22 @@ const Subscription = ({ headerStyle, isPhone, theme }: any) => {
 | 
				
			||||||
      : 'subscription';
 | 
					      : '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(() => {
 | 
					  useEffect(() => {
 | 
				
			||||||
    if (logSubscription) {
 | 
					    if (logSubscription) {
 | 
				
			||||||
      localStorage.setItem('logSubscription', logSubscription.id);
 | 
					      localStorage.setItem('logSubscription', logSubscription.id);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -68,8 +68,8 @@ const SubscriptionLogModal = ({
 | 
				
			||||||
        {(executing || loading) && <Loading3QuartersOutlined spin />}
 | 
					        {(executing || loading) && <Loading3QuartersOutlined spin />}
 | 
				
			||||||
        {!executing && !loading && <CheckCircleOutlined />}
 | 
					        {!executing && !loading && <CheckCircleOutlined />}
 | 
				
			||||||
        <span style={{ marginLeft: 5 }}>
 | 
					        <span style={{ marginLeft: 5 }}>
 | 
				
			||||||
          日志-{subscription && subscription.name}
 | 
					          {subscription && subscription.name}
 | 
				
			||||||
        </span>{' '}
 | 
					        </span>
 | 
				
			||||||
      </>
 | 
					      </>
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -174,6 +174,9 @@ const SubscriptionModal = ({
 | 
				
			||||||
    setType((subscription && subscription.type) || 'public-repo');
 | 
					    setType((subscription && subscription.type) || 'public-repo');
 | 
				
			||||||
    setScheduleType((subscription && subscription.schedule_type) || 'crontab');
 | 
					    setScheduleType((subscription && subscription.schedule_type) || 'crontab');
 | 
				
			||||||
    setPullType((subscription && subscription.pull_type) || 'ssh-key');
 | 
					    setPullType((subscription && subscription.pull_type) || 'ssh-key');
 | 
				
			||||||
 | 
					    if (!subscription) {
 | 
				
			||||||
 | 
					      form.resetFields();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
  }, [subscription, visible]);
 | 
					  }, [subscription, visible]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return (
 | 
					  return (
 | 
				
			||||||
| 
						 | 
					@ -300,7 +303,7 @@ const SubscriptionModal = ({
 | 
				
			||||||
        {type !== 'file' && (
 | 
					        {type !== 'file' && (
 | 
				
			||||||
          <>
 | 
					          <>
 | 
				
			||||||
            <Form.Item
 | 
					            <Form.Item
 | 
				
			||||||
              name="command"
 | 
					              name="whitelist"
 | 
				
			||||||
              label="白名单"
 | 
					              label="白名单"
 | 
				
			||||||
              rules={[{ whitespace: true }]}
 | 
					              rules={[{ whitespace: true }]}
 | 
				
			||||||
              tooltip="多个关键词竖线分割,支持正则表达式"
 | 
					              tooltip="多个关键词竖线分割,支持正则表达式"
 | 
				
			||||||
| 
						 | 
					@ -312,7 +315,7 @@ const SubscriptionModal = ({
 | 
				
			||||||
              />
 | 
					              />
 | 
				
			||||||
            </Form.Item>
 | 
					            </Form.Item>
 | 
				
			||||||
            <Form.Item
 | 
					            <Form.Item
 | 
				
			||||||
              name="command"
 | 
					              name="blacklist"
 | 
				
			||||||
              label="黑名单"
 | 
					              label="黑名单"
 | 
				
			||||||
              rules={[{ whitespace: true }]}
 | 
					              rules={[{ whitespace: true }]}
 | 
				
			||||||
              tooltip="多个关键词竖线分割,支持正则表达式"
 | 
					              tooltip="多个关键词竖线分割,支持正则表达式"
 | 
				
			||||||
| 
						 | 
					@ -324,7 +327,7 @@ const SubscriptionModal = ({
 | 
				
			||||||
              />
 | 
					              />
 | 
				
			||||||
            </Form.Item>
 | 
					            </Form.Item>
 | 
				
			||||||
            <Form.Item
 | 
					            <Form.Item
 | 
				
			||||||
              name="command"
 | 
					              name="dependences"
 | 
				
			||||||
              label="依赖文件"
 | 
					              label="依赖文件"
 | 
				
			||||||
              rules={[{ whitespace: true }]}
 | 
					              rules={[{ whitespace: true }]}
 | 
				
			||||||
              tooltip="多个关键词竖线分割,支持正则表达式"
 | 
					              tooltip="多个关键词竖线分割,支持正则表达式"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user