mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-23 06:46:09 +08:00
47 lines
1.4 KiB
TypeScript
47 lines
1.4 KiB
TypeScript
import { Subscription } from '../data/subscription';
|
|
import isNil from 'lodash/isNil';
|
|
|
|
export function formatUrl(doc: Subscription) {
|
|
let url = doc.url;
|
|
let host = '';
|
|
if (doc.type === 'private-repo') {
|
|
if (doc.pull_type === 'ssh-key') {
|
|
host = doc.url!.replace(/.*\@([^\:]+)\:.*/, '$1');
|
|
url = doc.url!.replace(host, doc.alias);
|
|
} else {
|
|
host = doc.url!.replace(/.*\:\/\/([^\/]+)\/.*/, '$1');
|
|
const { username, password } = doc.pull_option as any;
|
|
url = doc.url!.replace(host, `${username}:${password}@${host}`);
|
|
}
|
|
}
|
|
return { url, host };
|
|
}
|
|
|
|
export function formatCommand(doc: Subscription, url?: string) {
|
|
let command = `SUB_ID=${doc.id} ql `;
|
|
let _url = url || formatUrl(doc).url;
|
|
const {
|
|
type,
|
|
whitelist,
|
|
blacklist,
|
|
dependences,
|
|
branch,
|
|
extensions,
|
|
proxy,
|
|
autoAddCron,
|
|
autoDelCron,
|
|
} = doc;
|
|
if (type === 'file') {
|
|
command += `raw "${_url}" "${proxy || ''}" "${
|
|
isNil(autoAddCron) ? true : Boolean(autoAddCron)
|
|
}" "${isNil(autoDelCron) ? true : Boolean(autoDelCron)}"`;
|
|
} else {
|
|
command += `repo "${_url}" "${whitelist || ''}" "${blacklist || ''}" "${
|
|
dependences || ''
|
|
}" "${branch || ''}" "${extensions || ''}" "${proxy || ''}" "${
|
|
isNil(autoAddCron) ? true : Boolean(autoAddCron)
|
|
}" "${isNil(autoDelCron) ? true : Boolean(autoDelCron)}"`;
|
|
}
|
|
return command;
|
|
}
|