mirror of
https://github.com/whyour/qinglong.git
synced 2026-10-17 07:20:51 +08:00
* fix: harden scoped API inputs and isolate login throttling * fix: close script path gaps and harden security boundaries * fix: preserve subscription aliases and avoid extension eval * fix: allow cancelling invalid historical subscriptions * fix: make script parent validation explicit for CodeQL * fix: limit command execution and clarify trusted path branches * fix: separate diff tool script access from config APIs * fix: clean up obsolete subscription SSH credentials
44 lines
1.4 KiB
TypeScript
44 lines
1.4 KiB
TypeScript
import { Subscription } from '../data/subscription';
|
|
import isNil from 'lodash/isNil';
|
|
import { shellQuote } from '../shared/shellQuote';
|
|
import { getSubscriptionSshAlias } from '../shared/subscriptionPath';
|
|
|
|
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, getSubscriptionSshAlias(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) {
|
|
const args =
|
|
doc.type === 'file'
|
|
? ['raw', url || formatUrl(doc).url, doc.proxy || '']
|
|
: [
|
|
'repo',
|
|
url || formatUrl(doc).url,
|
|
doc.whitelist || '',
|
|
doc.blacklist || '',
|
|
doc.dependences || '',
|
|
doc.branch || '',
|
|
doc.extensions || '',
|
|
doc.proxy || '',
|
|
];
|
|
args.push(
|
|
String(isNil(doc.autoAddCron) ? true : Boolean(doc.autoAddCron)),
|
|
String(isNil(doc.autoDelCron) ? true : Boolean(doc.autoDelCron)),
|
|
);
|
|
return `SUB_ID=${shellQuote(String(doc.id))} ql ${args
|
|
.map((arg) => shellQuote(arg!))
|
|
.join(' ')}`;
|
|
}
|