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." };