diff --git a/server/api/objects/:id/index.ts b/server/api/objects/:id/index.ts index aa7bade0..31429d99 100644 --- a/server/api/objects/:id/index.ts +++ b/server/api/objects/:id/index.ts @@ -1,5 +1,5 @@ import { applyConfig, handleZodError } from "@/api"; -import { errorResponse, jsonResponse } from "@/response"; +import { errorResponse, jsonResponse, response } from "@/response"; import type { Hono } from "@hono/hono"; import { zValidator } from "@hono/zod-validator"; import type { Entity } from "@lysand-org/federation/types"; @@ -26,6 +26,12 @@ export const schemas = { param: z.object({ id: z.string().uuid(), }), + query: z.object({ + debug: z + .string() + .transform((v) => ["true", "1", "on"].includes(v.toLowerCase())) + .optional(), + }), }; export default (app: Hono) => @@ -33,8 +39,10 @@ export default (app: Hono) => meta.allowedMethods, meta.route, zValidator("param", schemas.param, handleZodError), + zValidator("query", schemas.query, handleZodError), async (context) => { const { id } = context.req.valid("param"); + const { debug } = context.req.valid("query"); let foundObject: Note | LikeType | null = null; let apiObject: Entity | null = null; @@ -63,6 +71,12 @@ export default (app: Hono) => return errorResponse("Object not found", 404); } + if (debug) { + return response(JSON.stringify(apiObject, null, 4), 200, { + "Content-Type": "application/json", + }); + } + return jsonResponse(apiObject); }, ); diff --git a/server/api/users/:uuid/index.ts b/server/api/users/:uuid/index.ts index 7a073362..9bba0b41 100644 --- a/server/api/users/:uuid/index.ts +++ b/server/api/users/:uuid/index.ts @@ -1,5 +1,5 @@ import { applyConfig, handleZodError } from "@/api"; -import { errorResponse, jsonResponse } from "@/response"; +import { errorResponse, jsonResponse, response } from "@/response"; import type { Hono } from "@hono/hono"; import { zValidator } from "@hono/zod-validator"; import { z } from "zod"; @@ -21,6 +21,12 @@ export const schemas = { param: z.object({ uuid: z.string().uuid(), }), + query: z.object({ + debug: z + .string() + .transform((v) => ["true", "1", "on"].includes(v.toLowerCase())) + .optional(), + }), }; export default (app: Hono) => @@ -28,8 +34,10 @@ export default (app: Hono) => meta.allowedMethods, meta.route, zValidator("param", schemas.param, handleZodError), + zValidator("query", schemas.query, handleZodError), async (context) => { const { uuid } = context.req.valid("param"); + const { debug } = context.req.valid("query"); const user = await User.fromId(uuid); @@ -44,6 +52,12 @@ export default (app: Hono) => ); } + if (debug) { + return response(JSON.stringify(user.toLysand(), null, 4), 200, { + "Content-Type": "application/json", + }); + } + return jsonResponse(user.toLysand()); }, );