mirror of
https://github.com/yuaotian/go-cursor-help.git
synced 2026-03-08 06:44:14 +00:00
```
feat(cursor): 添加环境变量配置下载节点功能 支持通过 CURSOR_HOOK_DOWNLOAD_URLS 环境变量自定义外置 Hook 下载节点列表,以逗号分隔多个 URL 地址。同时增强下载过程 的日志显示,包括进度提示、下载状态和错误处理,提升用户 体验和问题排查效率。 ```
This commit is contained in:
@@ -959,6 +959,11 @@ EOF
|
||||
"https://gh-proxy.com/https://raw.githubusercontent.com/yuaotian/go-cursor-help/refs/heads/master/scripts/hook/cursor_hook.js"
|
||||
"https://gh.chjina.com/https://raw.githubusercontent.com/yuaotian/go-cursor-help/refs/heads/master/scripts/hook/cursor_hook.js"
|
||||
)
|
||||
# 支持通过环境变量覆盖下载节点(逗号分隔)
|
||||
if [ -n "$CURSOR_HOOK_DOWNLOAD_URLS" ]; then
|
||||
IFS=',' read -r -a hook_download_urls <<< "$CURSOR_HOOK_DOWNLOAD_URLS"
|
||||
log_info "ℹ️ [Hook] 检测到自定义下载节点列表,将优先使用"
|
||||
fi
|
||||
|
||||
if [ -f "$hook_source_path" ]; then
|
||||
if cp "$hook_source_path" "$hook_target_path"; then
|
||||
@@ -970,10 +975,17 @@ EOF
|
||||
fi
|
||||
|
||||
if [ ! -f "$hook_target_path" ]; then
|
||||
log_info "ℹ️ [Hook] 正在下载外置 Hook,用于设备标识拦截..."
|
||||
local hook_downloaded=false
|
||||
if command -v curl >/dev/null 2>&1; then
|
||||
local total_urls=${#hook_download_urls[@]}
|
||||
if [ "$total_urls" -eq 0 ]; then
|
||||
log_warn "⚠️ [Hook] 下载节点列表为空,跳过在线下载"
|
||||
elif command -v curl >/dev/null 2>&1; then
|
||||
local index=0
|
||||
for url in "${hook_download_urls[@]}"; do
|
||||
if curl -fsSL "$url" -o "$hook_target_path"; then
|
||||
index=$((index + 1))
|
||||
log_info "⏳ [Hook] ($index/$total_urls) 当前下载节点: $url"
|
||||
if curl -fL --progress-bar "$url" -o "$hook_target_path"; then
|
||||
chown "$CURRENT_USER":"$(id -g -n "$CURRENT_USER")" "$hook_target_path" 2>/dev/null || true
|
||||
log_info "✅ [Hook] 外置 Hook 已在线下载: $hook_target_path"
|
||||
hook_downloaded=true
|
||||
@@ -984,8 +996,11 @@ EOF
|
||||
fi
|
||||
done
|
||||
elif command -v wget >/dev/null 2>&1; then
|
||||
local index=0
|
||||
for url in "${hook_download_urls[@]}"; do
|
||||
if wget -qO "$hook_target_path" "$url"; then
|
||||
index=$((index + 1))
|
||||
log_info "⏳ [Hook] ($index/$total_urls) 当前下载节点: $url"
|
||||
if wget --progress=bar:force -O "$hook_target_path" "$url"; then
|
||||
chown "$CURRENT_USER":"$(id -g -n "$CURRENT_USER")" "$hook_target_path" 2>/dev/null || true
|
||||
log_info "✅ [Hook] 外置 Hook 已在线下载: $hook_target_path"
|
||||
hook_downloaded=true
|
||||
|
||||
@@ -1663,6 +1663,11 @@ EOF
|
||||
"https://gh-proxy.com/https://raw.githubusercontent.com/yuaotian/go-cursor-help/refs/heads/master/scripts/hook/cursor_hook.js"
|
||||
"https://gh.chjina.com/https://raw.githubusercontent.com/yuaotian/go-cursor-help/refs/heads/master/scripts/hook/cursor_hook.js"
|
||||
)
|
||||
# 支持通过环境变量覆盖下载节点(逗号分隔)
|
||||
if [ -n "$CURSOR_HOOK_DOWNLOAD_URLS" ]; then
|
||||
IFS=',' read -r -a hook_download_urls <<< "$CURSOR_HOOK_DOWNLOAD_URLS"
|
||||
log_info "ℹ️ [Hook] 检测到自定义下载节点列表,将优先使用"
|
||||
fi
|
||||
|
||||
if [ -f "$hook_source_path" ]; then
|
||||
if cp "$hook_source_path" "$hook_target_path"; then
|
||||
@@ -1674,10 +1679,17 @@ EOF
|
||||
fi
|
||||
|
||||
if [ ! -f "$hook_target_path" ]; then
|
||||
log_info "ℹ️ [Hook] 正在下载外置 Hook,用于设备标识拦截..."
|
||||
local hook_downloaded=false
|
||||
if command -v curl >/dev/null 2>&1; then
|
||||
local total_urls=${#hook_download_urls[@]}
|
||||
if [ "$total_urls" -eq 0 ]; then
|
||||
log_warn "⚠️ [Hook] 下载节点列表为空,跳过在线下载"
|
||||
elif command -v curl >/dev/null 2>&1; then
|
||||
local index=0
|
||||
for url in "${hook_download_urls[@]}"; do
|
||||
if curl -fsSL "$url" -o "$hook_target_path"; then
|
||||
index=$((index + 1))
|
||||
log_info "⏳ [Hook] ($index/$total_urls) 当前下载节点: $url"
|
||||
if curl -fL --progress-bar "$url" -o "$hook_target_path"; then
|
||||
chown "$TARGET_USER":"$(id -g -n "$TARGET_USER")" "$hook_target_path" 2>/dev/null || true
|
||||
log_info "✅ [Hook] 外置 Hook 已在线下载: $hook_target_path"
|
||||
hook_downloaded=true
|
||||
@@ -1688,8 +1700,11 @@ EOF
|
||||
fi
|
||||
done
|
||||
elif command -v wget >/dev/null 2>&1; then
|
||||
local index=0
|
||||
for url in "${hook_download_urls[@]}"; do
|
||||
if wget -qO "$hook_target_path" "$url"; then
|
||||
index=$((index + 1))
|
||||
log_info "⏳ [Hook] ($index/$total_urls) 当前下载节点: $url"
|
||||
if wget --progress=bar:force -O "$hook_target_path" "$url"; then
|
||||
chown "$TARGET_USER":"$(id -g -n "$TARGET_USER")" "$hook_target_path" 2>/dev/null || true
|
||||
log_info "✅ [Hook] 外置 Hook 已在线下载: $hook_target_path"
|
||||
hook_downloaded=true
|
||||
|
||||
@@ -139,6 +139,11 @@ function Modify-CursorJSFiles {
|
||||
"https://gh-proxy.com/https://raw.githubusercontent.com/yuaotian/go-cursor-help/refs/heads/master/scripts/hook/cursor_hook.js",
|
||||
"https://gh.chjina.com/https://raw.githubusercontent.com/yuaotian/go-cursor-help/refs/heads/master/scripts/hook/cursor_hook.js"
|
||||
)
|
||||
# 支持通过环境变量覆盖下载节点(逗号分隔)
|
||||
if ($env:CURSOR_HOOK_DOWNLOAD_URLS) {
|
||||
$hookDownloadUrls = $env:CURSOR_HOOK_DOWNLOAD_URLS -split '\s*,\s*' | Where-Object { $_ }
|
||||
Write-Host "$BLUEℹ️ [Hook]$NC 检测到自定义下载节点列表,将优先使用"
|
||||
}
|
||||
if ($hookSourcePath) {
|
||||
try {
|
||||
Copy-Item -Path $hookSourcePath -Destination $hookTargetPath -Force
|
||||
@@ -148,17 +153,32 @@ function Modify-CursorJSFiles {
|
||||
}
|
||||
}
|
||||
if (-not (Test-Path $hookTargetPath)) {
|
||||
foreach ($url in $hookDownloadUrls) {
|
||||
try {
|
||||
Invoke-WebRequest -Uri $url -OutFile $hookTargetPath -UseBasicParsing -ErrorAction Stop
|
||||
Write-Host "$GREEN✅ [Hook]$NC 外置 Hook 已在线下载: $hookTargetPath"
|
||||
break
|
||||
} catch {
|
||||
Write-Host "$YELLOW⚠️ [Hook]$NC 外置 Hook 下载失败: $url"
|
||||
if (Test-Path $hookTargetPath) {
|
||||
Remove-Item -Path $hookTargetPath -Force
|
||||
Write-Host "$BLUEℹ️ [Hook]$NC 正在下载外置 Hook,用于设备标识拦截..."
|
||||
$originalProgressPreference = $ProgressPreference
|
||||
$ProgressPreference = 'Continue'
|
||||
try {
|
||||
if ($hookDownloadUrls.Count -eq 0) {
|
||||
Write-Host "$YELLOW⚠️ [Hook]$NC 下载节点列表为空,跳过在线下载"
|
||||
} else {
|
||||
$totalUrls = $hookDownloadUrls.Count
|
||||
for ($i = 0; $i -lt $totalUrls; $i++) {
|
||||
$url = $hookDownloadUrls[$i]
|
||||
$attempt = $i + 1
|
||||
Write-Host "$BLUE⏳ [Hook]$NC ($attempt/$totalUrls) 当前下载节点: $url"
|
||||
try {
|
||||
Invoke-WebRequest -Uri $url -OutFile $hookTargetPath -UseBasicParsing -ErrorAction Stop
|
||||
Write-Host "$GREEN✅ [Hook]$NC 外置 Hook 已在线下载: $hookTargetPath"
|
||||
break
|
||||
} catch {
|
||||
Write-Host "$YELLOW⚠️ [Hook]$NC 外置 Hook 下载失败: $url"
|
||||
if (Test-Path $hookTargetPath) {
|
||||
Remove-Item -Path $hookTargetPath -Force
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
$ProgressPreference = $originalProgressPreference
|
||||
}
|
||||
if (-not (Test-Path $hookTargetPath)) {
|
||||
Write-Host "$YELLOW⚠️ [Hook]$NC 外置 Hook 全部下载失败"
|
||||
|
||||
Reference in New Issue
Block a user