From ea386b9a33b8624690b2404880168c9666a1a832 Mon Sep 17 00:00:00 2001 From: Z8MB1E Date: Mon, 7 Sep 2026 04:37:01 -0400 Subject: [PATCH] feat(voiceover): limit takes to five per script Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus --- src/app/(frontend)/voiceover/actions.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/app/(frontend)/voiceover/actions.ts b/src/app/(frontend)/voiceover/actions.ts index 5b6da2f..070aed8 100644 --- a/src/app/(frontend)/voiceover/actions.ts +++ b/src/app/(frontend)/voiceover/actions.ts @@ -19,6 +19,8 @@ interface ActionResult { /** Server actions body limit is 10mb — enforce a 9 MB cap server-side with a clear error. */ const MAX_AUDIO_BYTES = 9 * 1024 * 1024; +const MAX_TAKES_PER_SCRIPT = 5; + async function authenticate() { const payloadConfig = await config; const payload = await getPayload({ config: payloadConfig }); @@ -83,6 +85,20 @@ export async function submitVoiceRecording( return { success: false, error: "This script is closed to new submissions." }; } + const takeCount = await payload.count({ + collection: "voice-submissions", + where: { + and: [{ user: { equals: user.id } }, { script: { equals: scriptId } }], + }, + overrideAccess: true, + }); + if (takeCount.totalDocs >= MAX_TAKES_PER_SCRIPT) { + return { + success: false, + error: `You have reached the limit of ${MAX_TAKES_PER_SCRIPT} takes for this script.`, + }; + } + const file = formData.get("file"); if (!(file instanceof File)) { return { success: false, error: "No audio file provided." };