feat(api): 🏷️ Only allow JSON values in JSON HTTP responses

This commit is contained in:
Jesse Wierzbinski 2024-07-22 22:02:17 +02:00
parent d4894c362e
commit 8a6d71d958
No known key found for this signature in database
3 changed files with 12 additions and 3 deletions

View file

@ -344,7 +344,7 @@ export const Instances = pgTable("Instances", {
baseUrl: text("base_url").notNull(), baseUrl: text("base_url").notNull(),
name: text("name").notNull(), name: text("name").notNull(),
version: text("version").notNull(), version: text("version").notNull(),
logo: jsonb("logo"), logo: jsonb("logo").$type<ContentFormat>(),
disableAutomoderation: boolean("disable_automoderation") disableAutomoderation: boolean("disable_automoderation")
.default(false) .default(false)
.notNull(), .notNull(),

View file

@ -38,7 +38,7 @@ export default (app: Hono) =>
and(isNull(Users.instanceId), eq(Users.isAdmin, true)), and(isNull(Users.instanceId), eq(Users.isAdmin, true)),
); );
const knownDomainsCount = Instance.getCount(); const knownDomainsCount = await Instance.getCount();
// TODO: fill in more values // TODO: fill in more values
return jsonResponse({ return jsonResponse({

View file

@ -27,8 +27,17 @@ export const response = (
}); });
}; };
export type Json =
| string
| number
| boolean
| null
| undefined
| Json[]
| { [key: string]: Json };
export const jsonResponse = ( export const jsonResponse = (
data: object, data: Json,
status = 200, status = 200,
headers: Record<string, string> = {}, headers: Record<string, string> = {},
) => { ) => {