diff --git a/back/services/sshKey.ts b/back/services/sshKey.ts index 32a16d06..0550558f 100644 --- a/back/services/sshKey.ts +++ b/back/services/sshKey.ts @@ -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); } } diff --git a/back/services/subscription.ts b/back/services/subscription.ts index 6cb3cc3b..99d7c31d 100644 --- a/back/services/subscription.ts +++ b/back/services/subscription.ts @@ -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}`, ); } diff --git a/package.json b/package.json index e4413b4f..6ce3c485 100644 --- a/package.json +++ b/package.json @@ -119,7 +119,7 @@ "codemirror": "^5.65.2", "compression-webpack-plugin": "9.2.0", "concurrently": "^7.0.0", - "lint-staged": "^12.3.4", + "lint-staged": "^13.0.3", "nodemon": "^2.0.15", "prettier": "^2.5.1", "qiniu": "^7.4.0", diff --git a/shell/share.sh b/shell/share.sh index 95d8d5b3..c6b4252b 100755 --- a/shell/share.sh +++ b/shell/share.sh @@ -85,6 +85,10 @@ import_config() { } set_proxy() { + local proxy="$1" + if [[ $proxy ]]; then + proxy_url="$proxy" + fi if [[ $proxy_url ]]; then export http_proxy="${proxy_url}" export https_proxy="${proxy_url}" @@ -303,13 +307,14 @@ update_depend() { } git_clone_scripts() { - local url=$1 - local dir=$2 - local branch=$3 + local url="$1" + local dir="$2" + local branch="$3" + local proxy="$4" [[ $branch ]] && local part_cmd="-b $branch " echo -e "开始克隆仓库 $url 到 $dir\n" - set_proxy + set_proxy "$proxy" git clone $part_cmd $url $dir exit_status=$? unset_proxy @@ -319,10 +324,11 @@ git_pull_scripts() { local dir_current=$(pwd) local dir_work="$1" local branch="$2" + local proxy="$3" cd $dir_work echo -e "开始更新仓库:$dir_work\n" - set_proxy + set_proxy "$proxy" git fetch --all exit_status=$? git pull &>/dev/null diff --git a/shell/update.sh b/shell/update.sh index 600eab58..f2c5fed3 100755 --- a/shell/update.sh +++ b/shell/update.sh @@ -144,6 +144,7 @@ update_repo() { local dependence="$4" local branch="$5" local extensions="$6" + local proxy="$7" local tmp="${url%/*}" local authorTmp1="${tmp##*/}" local authorTmp2="${authorTmp1##*:}" @@ -156,9 +157,9 @@ update_repo() { local formatUrl="$url" if [[ -d ${repo_path}/.git ]]; then reset_romote_url ${repo_path} "${formatUrl}" "${branch}" - git_pull_scripts ${repo_path} "${branch}" + git_pull_scripts ${repo_path} "${branch}" "${proxy}" else - git_clone_scripts "${formatUrl}" ${repo_path} "${branch}" + git_clone_scripts "${formatUrl}" ${repo_path} "${branch}" "${proxy}" fi if [[ $exit_status -eq 0 ]]; then echo -e "\n更新${repo_path}成功...\n" @@ -447,7 +448,10 @@ main() { [[ $ID ]] && update_cron "\"$ID\"" "0" "$$" "$log_path" "$begin_timestamp" local begin_time=$(format_time "$time_format" "$time") - eval echo -e "\#\# 开始执行... $begin_time\\\n" $cmd + + if [[ "$p1" != "repo" ]] && [[ "$p1" != "raw" ]]; then + eval echo -e "\#\# 开始执行... $begin_time\\\n" $cmd + fi if [[ -s $task_error_log_path ]]; then eval cat $task_error_log_path $cmd @@ -470,7 +474,7 @@ main() { repo) get_uniq_path "$p2" "$p6" if [[ -n $p2 ]]; then - update_repo "$p2" "$p3" "$p4" "$p5" "$p6" "$p7" + update_repo "$p2" "$p3" "$p4" "$p5" "$p6" "$p7" "$p8" else eval echo -e "命令输入错误...\\\n" $cmd eval usage $cmd @@ -497,7 +501,7 @@ main() { resetlet) auth_value=$(cat $file_auth_user | jq '.retries =0' -c) echo "$auth_value" >$file_auth_user - echo -e "重置登录错误次数成功" $cmd + eval echo -e "重置登录错误次数成功" $cmd ;; resettfa) 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_timestamp=$(format_timestamp "$time_format" "$etime") 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" - eval echo -e "\\\n          " $cmd + + if [[ "$p1" != "repo" ]] && [[ "$p1" != "raw" ]]; then + eval echo -e "\\\n\#\# 执行结束... $end_time 耗时 $diff_time 秒" $cmd + eval echo -e "\\\n          " $cmd + fi if [[ -f $file_path ]]; then cat $file_path