Skip to content

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 (or POST /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 IClashfinderEvent TypeScript contract.
  • Iterate through the stages and execute an INSERT ... ON CONFLICT DO NOTHING into the D1 stages table.
  • Iterate through the acts. For every act where the highlight value is > 0, execute an INSERT ... ON CONFLICT DO UPDATE into the D1 bands table, 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.