fix: client route type hacking

This commit is contained in:
DecDuck
2025-08-10 11:36:10 +10:00
parent 94e795787e
commit 824b4e708b
3 changed files with 40 additions and 30 deletions

View File

@ -15,6 +15,7 @@ const GetChunk = type({
* Part of v2 download API. Intended to be client-only.
*
* Returns raw stream of all files requested, in order.
* @response `application/octet-stream` stream of all files concatenated
*/
export default defineEventHandler<{ body: typeof GetChunk.infer }>(
async (h3) => {

View File

@ -1,5 +1,5 @@
import { type } from "arktype";
import { readDropValidatedBody, throwingArktype } from "~/server/arktype";
import { throwingArktype } from "~/server/arktype";
import { defineClientEventHandler } from "~/server/internal/clients/event-handler";
import contextManager from "~/server/internal/downloads/coordinator";
@ -11,17 +11,13 @@ const CreateContext = type({
/**
* Part of v2 download API. Create a download context for use with `/api/v2/client/chunk`.
*/
export default defineClientEventHandler<{ body: typeof CreateContext.infer }>(
async (h3) => {
const body = await readDropValidatedBody(h3, CreateContext);
export default defineClientEventHandler(async (h3, { body }) => {
const context = await contextManager.createContext(body.game, body.version);
if (!context)
throw createError({
statusCode: 400,
statusMessage: "Invalid game or version",
});
const context = await contextManager.createContext(body.game, body.version);
if (!context)
throw createError({
statusCode: 400,
statusMessage: "Invalid game or version",
});
return { context };
},
);
return { context };
}, CreateContext);