Fixing Git History
Some checks are pending
Docker Build and Push / build (push) Waiting to run

This commit is contained in:
Lucas Santana 2024-12-29 08:46:22 -03:00
parent 4765be66da
commit de28dea3b5
2 changed files with 71 additions and 0 deletions

22
netlify.toml Normal file
View File

@ -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"

View File

@ -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();