fix(script): redirect output to stderr and improve JSON creation
This commit is contained in:
@@ -83,10 +83,10 @@ test_api_connection() {
|
|||||||
"https://newapi.sususu.cf"
|
"https://newapi.sususu.cf"
|
||||||
)
|
)
|
||||||
|
|
||||||
print_info "Testing API connections..."
|
print_info "Testing API connections..." >&2
|
||||||
|
|
||||||
for base_url in "${test_urls[@]}"; do
|
for base_url in "${test_urls[@]}"; do
|
||||||
print_info "Testing $base_url..."
|
print_info "Testing $base_url..." >&2
|
||||||
|
|
||||||
local test_endpoint="$base_url/v1/models"
|
local test_endpoint="$base_url/v1/models"
|
||||||
|
|
||||||
@@ -102,25 +102,25 @@ test_api_connection() {
|
|||||||
local model_count
|
local model_count
|
||||||
model_count=$(cat /tmp/claude_test_response | jq -r '.data | length' 2>/dev/null || echo "0")
|
model_count=$(cat /tmp/claude_test_response | jq -r '.data | length' 2>/dev/null || echo "0")
|
||||||
if [ "$model_count" -gt "0" ]; then
|
if [ "$model_count" -gt "0" ]; then
|
||||||
print_success "API connection successful! Found $model_count models at $base_url"
|
print_success "API connection successful! Found $model_count models at $base_url" >&2
|
||||||
rm -f /tmp/claude_test_response
|
rm -f /tmp/claude_test_response
|
||||||
echo "$base_url"
|
echo "$base_url"
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
print_warning "API responded but no models found at $base_url"
|
print_warning "API responded but no models found at $base_url" >&2
|
||||||
fi
|
fi
|
||||||
elif [ "$response" = "401" ]; then
|
elif [ "$response" = "401" ]; then
|
||||||
print_warning "API key authentication failed for $base_url"
|
print_warning "API key authentication failed for $base_url" >&2
|
||||||
elif [ "$response" = "000" ]; then
|
elif [ "$response" = "000" ]; then
|
||||||
print_warning "Cannot connect to $base_url"
|
print_warning "Cannot connect to $base_url" >&2
|
||||||
else
|
else
|
||||||
print_warning "API test failed for $base_url with HTTP status: $response"
|
print_warning "API test failed for $base_url with HTTP status: $response" >&2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
rm -f /tmp/claude_test_response
|
rm -f /tmp/claude_test_response
|
||||||
done
|
done
|
||||||
|
|
||||||
print_error "All API connections failed. Please check your API key and internet connection."
|
print_error "All API connections failed. Please check your API key and internet connection." >&2
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,20 +129,21 @@ create_settings() {
|
|||||||
local base_url="$1"
|
local base_url="$1"
|
||||||
local api_key="$2"
|
local api_key="$2"
|
||||||
|
|
||||||
|
# Create JSON using jq to ensure proper escaping
|
||||||
local settings_json
|
local settings_json
|
||||||
settings_json=$(cat <<EOF
|
settings_json=$(jq -n \
|
||||||
{
|
--arg base_url "$base_url" \
|
||||||
|
--arg api_key "$api_key" \
|
||||||
|
'{
|
||||||
"env": {
|
"env": {
|
||||||
"ANTHROPIC_BASE_URL": "$base_url",
|
"ANTHROPIC_BASE_URL": $base_url,
|
||||||
"ANTHROPIC_AUTH_TOKEN": "$api_key",
|
"ANTHROPIC_AUTH_TOKEN": $api_key,
|
||||||
"DISABLE_TELEMETRY": 1,
|
"DISABLE_TELEMETRY": 1,
|
||||||
"DISABLE_ERROR_REPORTING": 1,
|
"DISABLE_ERROR_REPORTING": 1,
|
||||||
"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": 1,
|
"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": 1
|
||||||
},
|
},
|
||||||
"model": "sonnet"
|
"model": "sonnet"
|
||||||
}
|
}')
|
||||||
EOF
|
|
||||||
)
|
|
||||||
|
|
||||||
# Validate JSON
|
# Validate JSON
|
||||||
if ! echo "$settings_json" | jq . > /dev/null 2>&1; then
|
if ! echo "$settings_json" | jq . > /dev/null 2>&1; then
|
||||||
|
|||||||
Reference in New Issue
Block a user