Improve error handling and display for searches and uploads

Enhance user feedback by displaying search errors, refine photo submission fetching, add rate limiting cleanup logic, improve image upload cleanup, and strengthen moderator permission checks.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 2741d09b-80fb-4f0a-bfd6-ababb2ac4bfc
Replit-Commit-Checkpoint-Type: intermediate_checkpoint
This commit is contained in:
pac7
2025-10-08 19:55:55 +00:00
parent 7101632977
commit 13a4d8f64c
6 changed files with 90 additions and 33 deletions

View File

@@ -66,9 +66,17 @@ Deno.serve(async (req) => {
});
}
const { data: isMod } = await supabase.rpc('is_moderator', { _user_id: user.id });
const { data: isMod, error: modError } = await supabase.rpc('is_moderator', { _user_id: user.id });
if (modError) {
console.error('Failed to check moderator status:', modError);
return new Response(JSON.stringify({ error: 'Failed to verify permissions' }), {
status: 500,
headers: { ...corsHeaders, 'Content-Type': 'application/json' }
});
}
if (!isMod) {
return new Response(JSON.stringify({ error: 'Must be moderator' }), {
return new Response(JSON.stringify({ error: 'Insufficient permissions. Moderator role required.' }), {
status: 403,
headers: { ...corsHeaders, 'Content-Type': 'application/json' }
});
@@ -94,6 +102,11 @@ Deno.serve(async (req) => {
// Helper to create submission
async function createSubmission(userId: string, type: string, itemData: any, options: { escalated?: boolean; expiredLock?: boolean } = {}) {
// Ensure crypto.randomUUID is available
if (typeof crypto === 'undefined' || typeof crypto.randomUUID !== 'function') {
throw new Error('crypto.randomUUID is not available in this environment');
}
const submissionId = crypto.randomUUID();
const itemId = crypto.randomUUID();