media: enforce a filesize limit on uploads

This commit is contained in:
Alex Gleason 2023-09-08 16:48:27 -05:00
parent acc18adffb
commit 2c943872a8
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
2 changed files with 10 additions and 2 deletions

View File

@ -111,6 +111,10 @@ const Conf = {
return value;
},
/** Max upload size for files in number of bytes. Default 100MiB. */
get maxUploadSize() {
return Number(Deno.env.get('MAX_UPLOAD_SIZE') || 100 * 1024 * 1024);
},
/** Domain of the Ditto server as a `URL` object, for easily grabbing the `hostname`, etc. */
get url() {
return new URL(Conf.localDomain);

View File

@ -5,9 +5,13 @@ import { fileSchema } from '@/schema.ts';
import { configUploader as uploader } from '@/uploaders/config.ts';
import { parseBody } from '@/utils/web.ts';
const uploadSchema = fileSchema
.refine((file) => !!file.type, 'File type is required.')
.refine((file) => file.size <= Conf.maxUploadSize, 'File size is too large.');
const mediaBodySchema = z.object({
file: fileSchema.refine((file) => !!file.type),
thumbnail: fileSchema.optional(),
file: uploadSchema,
thumbnail: uploadSchema.optional(),
description: z.string().optional(),
focus: z.string().optional(),
});