mirror of
https://github.com/4ev-link/4ev.link.git
synced 2026-01-13 16:18:05 +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 = [];
|
||||
try {
|
||||
const parsed = JSON.parse(user.custom_slugs);
|
||||
if (Array.isArray(parsed)) slugs = parsed;
|
||||
if (Array.isArray(parsed)) slugs = parsed.reverse();
|
||||
} 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) {
|
||||
return new Response(e.message, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user