Files
2026-08-24 13:38:25 +07:00

59 lines
1.7 KiB
TypeScript

import { createAdminClient } from "npm:@insforge/sdk";
const corsHeaders = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "POST, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type, Authorization",
};
export default async function (req: Request): Promise<Response> {
if (req.method === "OPTIONS") {
return new Response(null, { status: 204, headers: corsHeaders });
}
if (req.method !== "POST") {
return new Response(JSON.stringify({ error: "Method not allowed" }), {
status: 405,
headers: { ...corsHeaders, "Content-Type": "application/json" },
});
}
try {
const { key } = await req.json();
if (!key || typeof key !== "string") {
return new Response(JSON.stringify({ error: "Missing key" }), {
status: 400,
headers: { ...corsHeaders, "Content-Type": "application/json" },
});
}
const admin = createAdminClient({
baseUrl: Deno.env.get("INSFORGE_BASE_URL")!,
apiKey: Deno.env.get("INSFORGE_API_KEY")!,
});
const { error } = await admin.storage.from("gallery").remove(key);
if (error) {
return new Response(JSON.stringify({ error: error.message }), {
status: 500,
headers: { ...corsHeaders, "Content-Type": "application/json" },
});
}
return new Response(JSON.stringify({ success: true }), {
status: 200,
headers: { ...corsHeaders, "Content-Type": "application/json" },
});
} catch (err) {
return new Response(
JSON.stringify({ error: err instanceof Error ? err.message : "Unknown error" }),
{
status: 500,
headers: { ...corsHeaders, "Content-Type": "application/json" },
}
);
}
}