mirror of
https://github.com/4ev-link/4ev.link.git
synced 2026-01-14 16:48:41 +00:00
Refactor: Return full link details instead of slugs
This commit is contained in:
@@ -9,12 +9,20 @@ export async function onRequestPost({ request, env }) {
|
|||||||
let slugs = [];
|
let slugs = [];
|
||||||
try {
|
try {
|
||||||
const parsed = JSON.parse(user.custom_slugs);
|
const parsed = JSON.parse(user.custom_slugs);
|
||||||
if (Array.isArray(parsed)) slugs = parsed;
|
if (Array.isArray(parsed)) slugs = parsed.reverse();
|
||||||
} catch {}
|
} catch {}
|
||||||
|
|
||||||
return Response.json(slugs);
|
if (slugs.length === 0) return Response.json([]);
|
||||||
|
|
||||||
|
const linkDetails = await Promise.all(
|
||||||
|
slugs.map(async slug => ({
|
||||||
|
slug,
|
||||||
|
destination: await env.KV_EV.get(slug) || 'Destination not found'
|
||||||
|
}))
|
||||||
|
);
|
||||||
|
|
||||||
|
return Response.json(linkDetails);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return new Response(e.message, { status: 500 });
|
return new Response(e.message, { status: 500 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user