From de28dea3b5db4aaf683cd3bad7703f9c09ae32bd Mon Sep 17 00:00:00 2001 From: Lucas Santana Date: Sun, 29 Dec 2024 08:46:22 -0300 Subject: [PATCH] Fixing Git History --- netlify.toml | 22 +++++++++ .../XXX_create_audio_processing_trigger.sql | 49 +++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 netlify.toml create mode 100644 supabase/migrations/XXX_create_audio_processing_trigger.sql diff --git a/netlify.toml b/netlify.toml new file mode 100644 index 0000000..3b87cef --- /dev/null +++ b/netlify.toml @@ -0,0 +1,22 @@ +[build] + command = "npm run build" + publish = "dist" + +[build.environment] + NODE_VERSION = "18" + VITE_SUPABASE_URL = "https://bsjlbnyslxzsdwxvkaap.supabase.co" + VITE_RESEND_API_KEY = "GEoM_cVt4qyBFVkngJWi8wBrMWOiPMUAuxuFGykcP0A" + VITE_APP_URL = "https://historiasmagicas.netlify.app/" + +[[redirects]] + from = "/*" + to = "/index.html" + status = 200 + +[dev] + command = "npm run dev" + port = 5173 + publish = "dist" + +[functions] + node_bundler = "esbuild" \ No newline at end of file diff --git a/supabase/migrations/XXX_create_audio_processing_trigger.sql b/supabase/migrations/XXX_create_audio_processing_trigger.sql new file mode 100644 index 0000000..20c38e5 --- /dev/null +++ b/supabase/migrations/XXX_create_audio_processing_trigger.sql @@ -0,0 +1,49 @@ +-- Criar a trigger function +create function handle_new_recording() +returns trigger +language plpgsql +security definer +as $$ +declare + response json; +begin + -- Apenas processa registros com status pending_analysis + if NEW.status = 'pending_analysis' then + -- Chama a Edge Function + select + content into response + from + http(( + 'POST', + current_setting('app.settings.edge_function_url') || '/process-audio', + ARRAY[ + ('Authorization', 'Bearer ' || current_setting('app.settings.service_role_key'))::http_header, + ('Content-Type', 'application/json')::http_header + ], + 'application/json', + json_build_object( + 'record', json_build_object( + 'id', NEW.id, + 'story_id', NEW.story_id, + 'student_id', NEW.student_id, + 'audio_url', NEW.audio_url, + 'status', NEW.status + ) + ) + )::http_request); + end if; + + return NEW; +end; +$$; + +-- Configurar as variáveis de ambiente +select set_config('app.settings.edge_function_url', 'https://bsjlbnyslxzsdwxvkaap.supabase.co/functions/v1', false); +select set_config('app.settings.service_role_key', 'seu_service_role_key', false); + +-- Criar a trigger +create trigger process_new_recording + after insert or update + on story_recordings + for each row + execute function handle_new_recording(); \ No newline at end of file