Skip to content

Commit b168f0f

Browse files
committed
feat(api): add size check to app_data field in newPostSchema
1 parent de60cff commit b168f0f

File tree

1 file changed

+5
-1
lines changed
  • apps/miiverse-api/src/services/api/routes

1 file changed

+5
-1
lines changed

apps/miiverse-api/src/services/api/routes/posts.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,13 @@ import type { CommunityShotMode, HydratedCommunityDocument } from '@/types/mongo
2727
import type { HydratedSettingsDocument } from '@/types/mongoose/settings';
2828
import type { ParamPack } from '@/types/common/param-pack';
2929

30+
// TODO - Is this the best place to put constants like these?
31+
const APP_DATA_MAX_SIZE = 0x400; // * Real name is `nn::olv::APP_DATA_MAX_SIZE`
32+
3033
const newPostSchema = z.object({
3134
community_id: z.string().optional(),
32-
app_data: z.string().base64().optional(),
35+
// TODO - This will trigger the generic `ApiErrorCode.BAD_PARAMS` error when the size check fails, is there a specific error code for this case?
36+
app_data: z.string().base64().max(APP_DATA_MAX_SIZE).refine((appData: string) => Buffer.from(appData, 'base64').length < APP_DATA_MAX_SIZE).optional(),
3337
painting: z.string().base64().optional(),
3438
screenshot: z.string().base64().optional(),
3539
body: z.string().optional(),

0 commit comments

Comments
 (0)