Files
genesis-2/supabase/functions/ai-generate-plan/index.ts
T
2026-01-16 12:16:30 -06:00

57 lines
2.0 KiB
TypeScript

// Follow this setup guide to integrate the Deno language server with your editor:
// https://deno.land/manual/getting_started/setup_your_environment
// This enables autocomplete, go to definition, etc.
// Setup type definitions for built-in Supabase Runtime APIs
import "jsr:@supabase/functions-js/edge-runtime.d.ts";
import { corsHeaders } from "../_shared/cors.ts";
console.log("Hello from Functions!");
Deno.serve(async (req) => {
if (req.method === "OPTIONS") {
return new Response(null, { status: 204, headers: corsHeaders });
}
try {
const contentType = (req.headers.get("content-type") || "").toLowerCase();
if (contentType.startsWith("multipart/form-data")) {
const formData = await req.formData();
console.log("Received multipart/form-data:", formData);
// 1. Usa .getAll() para sacar TODOS los valores de esa llave
const archivos = formData.getAll("archivosAdjuntos");
// 2. Imprime la longitud y el arreglo explícito
console.log(`Total archivos recibidos: ${archivos.length}`);
console.log("Lista de archivos:", archivos);
return new Response(
JSON.stringify({ message: "Multipart/form-data received" }),
{
headers: { ...corsHeaders, "Content-Type": "application/json" },
status: 200,
},
);
} else {
console.error("Unsupported content type:", contentType);
return new Response(
JSON.stringify({ error: "Unsupported content type" }),
{
headers: { ...corsHeaders, "Content-Type": "application/json" },
status: 400,
},
);
}
} catch (error) {
// Log full error server-side for diagnostics
if (error instanceof Error) {
console.error("Request handler error:", error.message);
}
const message = error instanceof Error ? error.message : String(error);
return new Response(JSON.stringify({ error: message }), {
headers: { ...corsHeaders, "Content-Type": "application/json" },
status: 400,
});
}
});