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:
parent
a0fa8889fc
commit
ea386b9a33
1 changed files with 16 additions and 0 deletions
|
|
@ -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." };
|
||||
|
|
|
|||
Loading…
Reference in a new issue