|
|
@@ -371,7 +371,17 @@ Deno.serve(async (req) => {
|
|
|
case 'custom-urls': {
|
|
|
// Handle GET and POST for listing/adding custom URLs
|
|
|
if (pathParts.length === 1) {
|
|
|
- const storeId = url.searchParams.get('store_id') || (await req.json())?.store_id;
|
|
|
+ // For GET: use query params, for POST: use body
|
|
|
+ let storeId: string | null = null;
|
|
|
+ let bodyData: any = null;
|
|
|
+
|
|
|
+ if (req.method === 'GET') {
|
|
|
+ storeId = url.searchParams.get('store_id');
|
|
|
+ } else if (req.method === 'POST') {
|
|
|
+ bodyData = await req.json();
|
|
|
+ storeId = bodyData?.store_id;
|
|
|
+ }
|
|
|
+
|
|
|
if (!storeId) {
|
|
|
return new Response(
|
|
|
JSON.stringify({ error: 'store_id is required' }),
|
|
|
@@ -402,8 +412,9 @@ Deno.serve(async (req) => {
|
|
|
);
|
|
|
|
|
|
} else if (req.method === 'POST') {
|
|
|
- // Add custom URL
|
|
|
- const { url: customUrl, content_type } = await req.json();
|
|
|
+ // Add custom URL - bodyData was already parsed above
|
|
|
+ const customUrl = bodyData?.url;
|
|
|
+ const content_type = bodyData?.content_type;
|
|
|
|
|
|
if (!customUrl || !content_type) {
|
|
|
return new Response(
|
|
|
@@ -439,7 +450,18 @@ Deno.serve(async (req) => {
|
|
|
const customUrlId = pathParts[1];
|
|
|
const subAction = pathParts[2]; // 'toggle' or undefined
|
|
|
|
|
|
- const { store_id, enabled } = await req.json().catch(() => ({ store_id: null, enabled: null }));
|
|
|
+ // Parse body once for PATCH/DELETE
|
|
|
+ let bodyData: any = null;
|
|
|
+ if (req.method === 'PATCH' || req.method === 'DELETE') {
|
|
|
+ try {
|
|
|
+ bodyData = await req.json();
|
|
|
+ } catch {
|
|
|
+ bodyData = {};
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ const store_id = bodyData?.store_id;
|
|
|
+ const enabled = bodyData?.enabled;
|
|
|
|
|
|
if (!store_id) {
|
|
|
return new Response(
|