Spaces:
Paused
Paused
Update start.sh
Browse files18 unmodified lines192021222223242524 unmodified lines50515253545354555657575859606158596061626364656667686970717273747576777879808182838485868788896690919293949596729798991001017510210310410510610710810981110111112113114115831161171181191 unmodified line121122123911241251261271289612913013113213313413510313613713813928 unmodified lines16816917013813914017117217318 unmodified linesexport CONFIG_ID="mcp_settings"
echo "Debug: SUPABASE_URL = ${SUPABASE_URL}"echo "Debug: SUPABASE_ANON_KEY = ${SUPABASE_ANON_KEY:0:20}..." # Show first 20 chars onlyecho "Debug: SUPABASE_ANON_KEY = ${SUPABASE_ANON_KEY:0:20}..."# ================================================================
# --- Define paths ---24 unmodified lines exit 1fi
# Make the request with error checkingRESPONSE=$(curl -s -f -X GET \# Make the request with HTTP/1.1 and better error handlingecho "Debug: Attempting connection with HTTP/1.1..."RESPONSE=$(curl --http1.1 -s -S -X GET \ "${SUPABASE_URL}/rest/v1/configs?id=eq.${CONFIG_ID}&select=content" \ -H "apikey: ${SUPABASE_ANON_KEY}" \ -H "Authorization: Bearer ${SUPABASE_ANON_KEY}" 2>&1) || { echo "ERROR: curl failed with exit code $?" echo "Response/Error: $RESPONSE" exit 1} -H "Authorization: Bearer ${SUPABASE_ANON_KEY}" \ -H "Accept: application/json" \ 2>&1)
CURL_EXIT_CODE=$?if [ $CURL_EXIT_CODE -ne 0 ]; then echo "ERROR: curl failed with exit code $CURL_EXIT_CODE" echo "Trying alternative approach with wget..." # Fallback to wget if available if command -v wget &> /dev/null; then RESPONSE=$(wget -qO- \ --header="apikey: ${SUPABASE_ANON_KEY}" \ --header="Authorization: Bearer ${SUPABASE_ANON_KEY}" \ "${SUPABASE_URL}/rest/v1/configs?id=eq.${CONFIG_ID}&select=content" 2>&1) if [ $? -ne 0 ]; then echo "ERROR: Both curl and wget failed" echo "Creating empty config as fallback..." echo "{}" > "$CONFIG_FILE_PATH" fi else echo "wget not available, creating empty config..." echo "{}" > "$CONFIG_FILE_PATH" fielse echo "Debug: Request successful"fi
echo "Debug: Raw response from Supabase: $RESPONSE"
# Extract JSON content from responseif [ -n "$RESPONSE" ] && [ "$RESPONSE" != "[]" ]; thenif [ -n "$RESPONSE" ] && [ "$RESPONSE" != "[]" ] && [[ ! "$RESPONSE" =~ "ERROR" ]]; then echo "Debug: Processing response..." echo "$RESPONSE" | python3 -c "import sys, jsontry: data = json.load(sys.stdin) if data and len(data) > 0: print(json.dumps(data[0]['content'] if data else {})) print(json.dumps(data[0]['content'])) else: print('{}')except Exception as e: print(f'ERROR: Failed to parse JSON: {e}', file=sys.stderr) sys.exit(1) print('{}')" > "$CONFIG_FILE_PATH" || { echo "ERROR: Failed to parse JSON response" echo "Creating empty config instead..." echo "{}" > "$CONFIG_FILE_PATH" } if [ -s "$CONFIG_FILE_PATH" ]; then echo "✅ Config downloaded successfully." echo "✅ Config downloaded successfully." else echo "⚠️ Config file is empty, using default..." echo "{}" > "$CONFIG_FILE_PATH" fielse echo "⚠️ No config found in Supabase (empty response), creating empty file..." echo "⚠️ No config found in Supabase (empty/error response), creating empty file..." echo "{}" > "$CONFIG_FILE_PATH"fi
1 unmodified lineecho "Debug: Config file contents:"cat "$CONFIG_FILE_PATH"
# 3. Function to sync file to Supabase# 3. Function to sync file to Supabase (also using HTTP/1.1)sync_to_supabase() { if [ -f "$CONFIG_FILE_PATH" ]; then FILE_CONTENT=$(cat "$CONFIG_FILE_PATH" | python3 -c "import sys, json; print(json.dumps(json.load(sys.stdin)))") curl -s -X PATCH \ curl --http1.1 -s -X PATCH \ "${SUPABASE_URL}/rest/v1/configs?id=eq.${CONFIG_ID}" \ -H "apikey: ${SUPABASE_ANON_KEY}" \ -H "Authorization: Bearer ${SUPABASE_ANON_KEY}" \ -H "Content-Type: application/json" \ -H "Prefer: return=minimal" \ -d "{\"content\":${FILE_CONTENT},\"updated_at\":\"$(date -u +%Y-%m-%dT%H:%M:%S)\"}" \ > /dev/null > /dev/null 2>&1 || echo "Warning: Sync failed, will retry..." echo "✅ [Sync] Config uploaded to Supabase at $(date)" fi28 unmodified linescd "$RUN_DIR"
echo "Debug: Current directory: $(pwd)"echo "Debug: Files in directory:"ls -la
echo "Debug: Running npm start..."npm start || { echo "ERROR: npm start failed with exit code $?"start.sh+49-19