Appearance
Agent Directive: Clashfinder API Worker Implementation
Objective
Implement the Edge ingestion endpoint within the Cloudflare Worker (api/src/index.ts) to fetch a user's highlighted schedule directly from the Clashfinder JSON API, map it to the ERO data schema, and persist it to the D1 database.
Execution Sequence
1. Create the Ingestion Endpoint
- Modify
api/src/index.ts. - Expose a new route:
POST /api/ingest(orPOST /api/ingest/clashfinder). - The endpoint must accept a JSON payload:
{ "festivalId": "string", "username": "string" }.
2. Implement the Fetch & Map Logic
- Within the new route, execute a
fetch()call to:https://clashfinder.com/data/event/{festivalId}.json?user={username}. - Map the incoming JSON response to the
IClashfinderEventTypeScript contract. - Iterate through the
stagesand execute anINSERT ... ON CONFLICT DO NOTHINGinto the D1stagestable. - Iterate through the
acts. For every act where thehighlightvalue is > 0, execute anINSERT ... ON CONFLICT DO UPDATEinto the D1bandstable, translating dates to epoch millisecond numbers for Dexie.js parity.
3. Response Formatting
- Return a JSON success response detailing the number of stages and acts successfully imported/updated.