diff --git a/src/route/wcl.ts b/src/route/wcl.ts index afaf55e..91927ba 100644 --- a/src/route/wcl.ts +++ b/src/route/wcl.ts @@ -1,6 +1,6 @@ import { FastifyPluginAsync } from "fastify"; import fights from "./wcl/fights"; -import events from "./wcl/events"; +import events, { eventsByType } from "./wcl/events"; import tables from "./wcl/tables"; import graph from "./wcl/graph"; import parses from "./wcl/character-parses"; @@ -12,6 +12,7 @@ const wcl: FastifyPluginAsync = async (app) => { app.register(cacheControl); fights(app); events(app); + eventsByType(app); tables(app); graph(app); parses(app); diff --git a/src/route/wcl/events.ts b/src/route/wcl/events.ts index 0e6c6ef..2e174e9 100644 --- a/src/route/wcl/events.ts +++ b/src/route/wcl/events.ts @@ -1,6 +1,6 @@ import * as api from "../../wcl/api"; import { gql } from "graphql-request"; -import { compress, wrapEndpoint } from "./common"; +import { ReportParams, camelCase, compress, wrapEndpoint } from "./common"; // TODO: migrate useAbilityIDs to true. // requires frontend changes, but means we no longer need to compress the event response (probably) @@ -89,3 +89,40 @@ const events = wrapEndpoint( true, ); export default events; + +export const eventsByType = wrapEndpoint( + "/i/v1/report/events/:type/:code", + "wcl-events", + async (req) => { + const rawData = await api.query< + EventData, + { + code: string; + translate: boolean; + startTime: number; + endTime: number; + playerId?: number; + filter?: string; + type?: string; + } + >(eventQuery, { + type: req.params.type ? camelCase(req.params.type) : undefined, + code: req.params.code, + translate: req.query.translate !== "false", + startTime: Number(req.query.start), + endTime: Number(req.query.end), + playerId: req.query.actorid ? Number(req.query.actorid) : undefined, + filter: req.query.filter, + }); + const { data: events, nextPageTimestamp } = + rawData.reportData.report.events; + const data = { + events: events, + nextPageTimestamp, + count: events.length, + }; + + return compress(JSON.stringify(data)); + }, + true, +);