From 4807bfeeb189013acca3aa14ed28c7d30460601b Mon Sep 17 00:00:00 2001 From: Jannis Braun <151788261+TheZwiss@users.noreply.github.com> Date: Mon, 23 Mar 2026 02:22:22 +0100 Subject: [PATCH] feat: read/write maxUploadSizeMb in instance settings API --- packages/server/src/routes/settings.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/server/src/routes/settings.ts b/packages/server/src/routes/settings.ts index 8e03a1ff..b5312024 100644 --- a/packages/server/src/routes/settings.ts +++ b/packages/server/src/routes/settings.ts @@ -176,12 +176,14 @@ export async function settingsRoutes(app: FastifyInstance): Promise { } const gifKey = row.gifApiKey as string | null; + const maxUploadBytes = row.maxUploadSizeBytes ?? config.maxUploadSize; const response: InstanceAdminSettings = { instanceName: row.instanceName ?? 'Backspace', registrationOpen: row.registrationOpen !== null ? row.registrationOpen === 1 : config.registrationOpen, discoveryEnabled: row.discoveryEnabled === 1, gifApiKey: gifKey ? `****${gifKey.slice(-4)}` : undefined, gifEnabled: !!gifKey, + maxUploadSizeMb: Math.round(maxUploadBytes / (1024 * 1024)), }; return reply.code(200).send(response); @@ -220,6 +222,14 @@ export async function settingsRoutes(app: FastifyInstance): Promise { } } + if (body.maxUploadSizeMb !== undefined) { + const mb = Number(body.maxUploadSizeMb); + if (isNaN(mb) || mb < 1 || mb > 500) { + return reply.code(400).send({ error: 'maxUploadSizeMb must be between 1 and 500', statusCode: 400 }); + } + updateData.maxUploadSizeBytes = Math.round(mb * 1024 * 1024); + } + db.update(schema.instanceSettings).set(updateData).where(eq(schema.instanceSettings.id, 1)).run(); const updatedRow = db.select().from(schema.instanceSettings).where(eq(schema.instanceSettings.id, 1)).get(); @@ -228,12 +238,14 @@ export async function settingsRoutes(app: FastifyInstance): Promise { } const updatedGifKey = updatedRow.gifApiKey as string | null; + const updatedMaxUploadBytes = updatedRow.maxUploadSizeBytes ?? config.maxUploadSize; const response: InstanceAdminSettings = { instanceName: updatedRow.instanceName ?? 'Backspace', registrationOpen: updatedRow.registrationOpen !== null ? updatedRow.registrationOpen === 1 : config.registrationOpen, discoveryEnabled: updatedRow.discoveryEnabled === 1, gifApiKey: updatedGifKey ? `****${updatedGifKey.slice(-4)}` : undefined, gifEnabled: !!updatedGifKey, + maxUploadSizeMb: Math.round(updatedMaxUploadBytes / (1024 * 1024)), }; return reply.code(200).send(response);