订阅支持添加代理

This commit is contained in:
whyour
2022-11-12 22:45:46 +08:00
parent 8fdd8db51b
commit ff2b4e0b2f
5 changed files with 56 additions and 24 deletions
+15 -6
View File
@@ -38,8 +38,12 @@ 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`;
private generateSingleSshConfig(
alias: string,
host: string,
proxy?: string,
): string {
return `\nHost ${alias}\n Hostname ${host}\n IdentityFile ${this.sshPath}/${alias}\n StrictHostKeyChecking no\n`;
}
private generateSshConfig(configs: string[]) {
@@ -69,16 +73,21 @@ export default class SshKeyService {
}
}
public addSSHKey(key: string, alias: string, host: string): void {
public addSSHKey(
key: string,
alias: string,
host: string,
proxy?: string,
): void {
this.generatePrivateKeyFile(alias, key);
const config = this.generateSingleSshConfig(alias, host);
const config = this.generateSingleSshConfig(alias, host, proxy);
this.removeSshConfig(alias);
this.generateSshConfig([config]);
}
public removeSSHKey(alias: string, host: string): void {
public removeSSHKey(alias: string, host: string, proxy?: string): void {
this.removePrivateKeyFile(alias);
const config = this.generateSingleSshConfig(alias, host);
const config = this.generateSingleSshConfig(alias, host, proxy);
this.removeSshConfig(config);
}
}
+15 -4
View File
@@ -77,13 +77,21 @@ export default class SubscriptionService {
private formatCommand(doc: Subscription, url?: string) {
let command = 'ql ';
let _url = url || this.formatUrl(doc).url;
const { type, whitelist, blacklist, dependences, branch, extensions } = doc;
const {
type,
whitelist,
blacklist,
dependences,
branch,
extensions,
proxy,
} = doc;
if (type === 'file') {
command += `raw "${_url}"`;
} else {
command += `repo "${_url}" "${whitelist || ''}" "${blacklist || ''}" "${
dependences || ''
}" "${branch || ''}" "${extensions || ''}"`;
}" "${branch || ''}" "${extensions || ''}" "${proxy || ''}"`;
}
return command;
}
@@ -117,9 +125,10 @@ export default class SubscriptionService {
(doc.pull_option as any).private_key,
doc.alias,
host,
doc.proxy,
);
} else {
this.sshKeyService.removeSSHKey(doc.alias, host);
this.sshKeyService.removeSSHKey(doc.alias, host, doc.proxy);
}
}
@@ -354,7 +363,9 @@ export default class SubscriptionService {
fs.appendFileSync(
`${absolutePath}`,
`${str}\n## 执行结束... ${dayjs().format('YYYY-MM-DD HH:mm:ss')}${LOG_END_SYMBOL}`,
`${str}\n## 执行结束... ${dayjs().format(
'YYYY-MM-DD HH:mm:ss',
)}${LOG_END_SYMBOL}`,
);
}