1
0
Fork 0

feat(voiceover): limit takes to five per script

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
Jason Fraley 2026-09-07 04:37:01 -04:00
parent a0fa8889fc
commit ea386b9a33

View file

@ -19,6 +19,8 @@ interface ActionResult<T = undefined> {
/** 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." };