订阅支持添加代理

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

View File

@ -38,8 +38,12 @@ export default class SshKeyService {
} }
} }
private generateSingleSshConfig(alias: string, host: string): string { private generateSingleSshConfig(
return `\nHost ${alias}\n Hostname ${host}\n IdentityFile ${this.sshPath}/${alias}\n StrictHostKeyChecking no`; 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[]) { 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); this.generatePrivateKeyFile(alias, key);
const config = this.generateSingleSshConfig(alias, host); const config = this.generateSingleSshConfig(alias, host, proxy);
this.removeSshConfig(alias); this.removeSshConfig(alias);
this.generateSshConfig([config]); this.generateSshConfig([config]);
} }
public removeSSHKey(alias: string, host: string): void { public removeSSHKey(alias: string, host: string, proxy?: string): void {
this.removePrivateKeyFile(alias); this.removePrivateKeyFile(alias);
const config = this.generateSingleSshConfig(alias, host); const config = this.generateSingleSshConfig(alias, host, proxy);
this.removeSshConfig(config); this.removeSshConfig(config);
} }
} }

View File

@ -77,13 +77,21 @@ export default class SubscriptionService {
private formatCommand(doc: Subscription, url?: string) { private formatCommand(doc: Subscription, url?: string) {
let command = 'ql '; let command = 'ql ';
let _url = url || this.formatUrl(doc).url; 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') { if (type === 'file') {
command += `raw "${_url}"`; command += `raw "${_url}"`;
} else { } else {
command += `repo "${_url}" "${whitelist || ''}" "${blacklist || ''}" "${ command += `repo "${_url}" "${whitelist || ''}" "${blacklist || ''}" "${
dependences || '' dependences || ''
}" "${branch || ''}" "${extensions || ''}"`; }" "${branch || ''}" "${extensions || ''}" "${proxy || ''}"`;
} }
return command; return command;
} }
@ -117,9 +125,10 @@ export default class SubscriptionService {
(doc.pull_option as any).private_key, (doc.pull_option as any).private_key,
doc.alias, doc.alias,
host, host,
doc.proxy,
); );
} else { } 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( fs.appendFileSync(
`${absolutePath}`, `${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}`,
); );
} }

View File

@ -119,7 +119,7 @@
"codemirror": "^5.65.2", "codemirror": "^5.65.2",
"compression-webpack-plugin": "9.2.0", "compression-webpack-plugin": "9.2.0",
"concurrently": "^7.0.0", "concurrently": "^7.0.0",
"lint-staged": "^12.3.4", "lint-staged": "^13.0.3",
"nodemon": "^2.0.15", "nodemon": "^2.0.15",
"prettier": "^2.5.1", "prettier": "^2.5.1",
"qiniu": "^7.4.0", "qiniu": "^7.4.0",

View File

@ -85,6 +85,10 @@ import_config() {
} }
set_proxy() { set_proxy() {
local proxy="$1"
if [[ $proxy ]]; then
proxy_url="$proxy"
fi
if [[ $proxy_url ]]; then if [[ $proxy_url ]]; then
export http_proxy="${proxy_url}" export http_proxy="${proxy_url}"
export https_proxy="${proxy_url}" export https_proxy="${proxy_url}"
@ -303,13 +307,14 @@ update_depend() {
} }
git_clone_scripts() { git_clone_scripts() {
local url=$1 local url="$1"
local dir=$2 local dir="$2"
local branch=$3 local branch="$3"
local proxy="$4"
[[ $branch ]] && local part_cmd="-b $branch " [[ $branch ]] && local part_cmd="-b $branch "
echo -e "开始克隆仓库 $url$dir\n" echo -e "开始克隆仓库 $url$dir\n"
set_proxy set_proxy "$proxy"
git clone $part_cmd $url $dir git clone $part_cmd $url $dir
exit_status=$? exit_status=$?
unset_proxy unset_proxy
@ -319,10 +324,11 @@ git_pull_scripts() {
local dir_current=$(pwd) local dir_current=$(pwd)
local dir_work="$1" local dir_work="$1"
local branch="$2" local branch="$2"
local proxy="$3"
cd $dir_work cd $dir_work
echo -e "开始更新仓库:$dir_work\n" echo -e "开始更新仓库:$dir_work\n"
set_proxy set_proxy "$proxy"
git fetch --all git fetch --all
exit_status=$? exit_status=$?
git pull &>/dev/null git pull &>/dev/null

View File

@ -144,6 +144,7 @@ update_repo() {
local dependence="$4" local dependence="$4"
local branch="$5" local branch="$5"
local extensions="$6" local extensions="$6"
local proxy="$7"
local tmp="${url%/*}" local tmp="${url%/*}"
local authorTmp1="${tmp##*/}" local authorTmp1="${tmp##*/}"
local authorTmp2="${authorTmp1##*:}" local authorTmp2="${authorTmp1##*:}"
@ -156,9 +157,9 @@ update_repo() {
local formatUrl="$url" local formatUrl="$url"
if [[ -d ${repo_path}/.git ]]; then if [[ -d ${repo_path}/.git ]]; then
reset_romote_url ${repo_path} "${formatUrl}" "${branch}" reset_romote_url ${repo_path} "${formatUrl}" "${branch}"
git_pull_scripts ${repo_path} "${branch}" git_pull_scripts ${repo_path} "${branch}" "${proxy}"
else else
git_clone_scripts "${formatUrl}" ${repo_path} "${branch}" git_clone_scripts "${formatUrl}" ${repo_path} "${branch}" "${proxy}"
fi fi
if [[ $exit_status -eq 0 ]]; then if [[ $exit_status -eq 0 ]]; then
echo -e "\n更新${repo_path}成功...\n" echo -e "\n更新${repo_path}成功...\n"
@ -447,7 +448,10 @@ main() {
[[ $ID ]] && update_cron "\"$ID\"" "0" "$$" "$log_path" "$begin_timestamp" [[ $ID ]] && update_cron "\"$ID\"" "0" "$$" "$log_path" "$begin_timestamp"
local begin_time=$(format_time "$time_format" "$time") local begin_time=$(format_time "$time_format" "$time")
if [[ "$p1" != "repo" ]] && [[ "$p1" != "raw" ]]; then
eval echo -e "\#\# 开始执行... $begin_time\\\n" $cmd eval echo -e "\#\# 开始执行... $begin_time\\\n" $cmd
fi
if [[ -s $task_error_log_path ]]; then if [[ -s $task_error_log_path ]]; then
eval cat $task_error_log_path $cmd eval cat $task_error_log_path $cmd
@ -470,7 +474,7 @@ main() {
repo) repo)
get_uniq_path "$p2" "$p6" get_uniq_path "$p2" "$p6"
if [[ -n $p2 ]]; then if [[ -n $p2 ]]; then
update_repo "$p2" "$p3" "$p4" "$p5" "$p6" "$p7" update_repo "$p2" "$p3" "$p4" "$p5" "$p6" "$p7" "$p8"
else else
eval echo -e "命令输入错误...\\\n" $cmd eval echo -e "命令输入错误...\\\n" $cmd
eval usage $cmd eval usage $cmd
@ -497,7 +501,7 @@ main() {
resetlet) resetlet)
auth_value=$(cat $file_auth_user | jq '.retries =0' -c) auth_value=$(cat $file_auth_user | jq '.retries =0' -c)
echo "$auth_value" >$file_auth_user echo "$auth_value" >$file_auth_user
echo -e "重置登录错误次数成功" $cmd eval echo -e "重置登录错误次数成功" $cmd
;; ;;
resettfa) resettfa)
auth_value=$(cat $file_auth_user | jq '.twoFactorActivated =false' | jq '.twoFactorActived =false' -c) auth_value=$(cat $file_auth_user | jq '.twoFactorActivated =false' | jq '.twoFactorActived =false' -c)
@ -514,10 +518,12 @@ main() {
local end_time=$(format_time "$time_format" "$etime") local end_time=$(format_time "$time_format" "$etime")
local end_timestamp=$(format_timestamp "$time_format" "$etime") local end_timestamp=$(format_timestamp "$time_format" "$etime")
local diff_time=$(($end_timestamp - $begin_timestamp)) local diff_time=$(($end_timestamp - $begin_timestamp))
eval echo -e "\\\n\#\# 执行结束... $end_time 耗时 $diff_time" $cmd
[[ $ID ]] && update_cron "\"$ID\"" "1" "" "$log_path" "$begin_timestamp" "$diff_time" [[ $ID ]] && update_cron "\"$ID\"" "1" "" "$log_path" "$begin_timestamp" "$diff_time"
if [[ "$p1" != "repo" ]] && [[ "$p1" != "raw" ]]; then
eval echo -e "\\\n\#\# 执行结束... $end_time 耗时 $diff_time" $cmd
eval echo -e "\\\n          " $cmd eval echo -e "\\\n          " $cmd
fi
if [[ -f $file_path ]]; then if [[ -f $file_path ]]; then
cat $file_path cat $file_path