Spaces:
Paused
Paused
Update start.sh
Browse files18 unmodified lines1920212223242524 unmodified lines505152535455565758596061626364656667686970717273747576777879808182838485861 unmodified line88899091929394959697989910010110210310410510628 unmodified lines13513613713813914014114214318 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 only# ================================================================# --- Define paths ---24 unmodified linesexit 1fi# Make the request with error checkingRESPONSE=$(curl -s -f -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}echo "Debug: Raw response from Supabase: $RESPONSE"# Extract JSON content from responseif [ -n "$RESPONSE" ] && [ "$RESPONSE" != "[]" ]; thenecho "Debug: Processing response..."echo "$RESPONSE" | python3 -c "import sys, jsontry:data = json.load(sys.stdin)print(json.dumps(data[0]['content'] if data else {}))except Exception as e:print(f'ERROR: Failed to parse JSON: {e}', file=sys.stderr)sys.exit(1)" > "$CONFIG_FILE_PATH" || {echo "ERROR: Failed to parse JSON response"echo "Creating empty config instead..."echo "{}" > "$CONFIG_FILE_PATH"}echo "✅ Config downloaded successfully."elseecho "⚠️ No config found in Supabase (empty response), creating empty file..."echo "{}" > "$CONFIG_FILE_PATH"fi1 unmodified lineecho "Debug: Config file contents:"cat "$CONFIG_FILE_PATH"# 3. Function to sync file to Supabasesync_to_supabase() {if [ -f "$CONFIG_FILE_PATH" ]; thenFILE_CONTENT=$(cat "$CONFIG_FILE_PATH" | python3 -c "import sys, json; print(json.dumps(json.load(sys.stdin)))")curl -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/nullecho "✅ [Sync] Config uploaded to Supabase at $(date)"fi28 unmodified linescd "$RUN_DIR"echo "Debug: Current directory: $(pwd)"echo "Debug: Files in directory:"ls -laecho "Debug: Running npm start..."npm start || {echo "ERROR: npm start failed with exit code $?"18 unmodified lines1920212223242524 unmodified lines50515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191 unmodified line12112212312412512612712812913013113213313413513613713813928 unmodified lines16816917017117217318 unmodified linesexport CONFIG_ID="mcp_settings"echo "Debug: SUPABASE_URL = ${SUPABASE_URL}"echo "Debug: SUPABASE_ANON_KEY = ${SUPABASE_ANON_KEY:0:20}..."# ================================================================# --- Define paths ---24 unmodified linesexit 1fi# 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}" \-H "Accept: application/json" \2>&1)CURL_EXIT_CODE=$?if [ $CURL_EXIT_CODE -ne 0 ]; thenecho "ERROR: curl failed with exit code $CURL_EXIT_CODE"echo "Trying alternative approach with wget..."# Fallback to wget if availableif command -v wget &> /dev/null; thenRESPONSE=$(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 ]; thenecho "ERROR: Both curl and wget failed"echo "Creating empty config as fallback..."echo "{}" > "$CONFIG_FILE_PATH"fielseecho "wget not available, creating empty config..."echo "{}" > "$CONFIG_FILE_PATH"fielseecho "Debug: Request successful"fiecho "Debug: Raw response from Supabase: $RESPONSE"# Extract JSON content from responseif [ -n "$RESPONSE" ] && [ "$RESPONSE" != "[]" ] && [[ ! "$RESPONSE" =~ "ERROR" ]]; thenecho "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']))else:print('{}')except Exception as e:print(f'ERROR: Failed to parse JSON: {e}', file=sys.stderr)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" ]; thenecho "✅ Config downloaded successfully."elseecho "⚠️ Config file is empty, using default..."echo "{}" > "$CONFIG_FILE_PATH"fielseecho "⚠️ No config found in Supabase (empty/error response), creating empty file..."echo "{}" > "$CONFIG_FILE_PATH"fi1 unmodified lineecho "Debug: Config file contents:"cat "$CONFIG_FILE_PATH"# 3. Function to sync file to Supabase (also using HTTP/1.1)sync_to_supabase() {if [ -f "$CONFIG_FILE_PATH" ]; thenFILE_CONTENT=$(cat "$CONFIG_FILE_PATH" | python3 -c "import sys, json; print(json.dumps(json.load(sys.stdin)))")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 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: Running npm start..."npm start || {echo "ERROR: npm start failed with exit code $?"
start.sh+49-19