mirror of
https://github.com/4ev-link/4ev.link.git
synced 2026-01-14 00:28:05 +00:00
22 lines
748 B
JavaScript
22 lines
748 B
JavaScript
export async function onRequestGet({ request, env }) {
|
|
try {
|
|
const url = new URL(request.url);
|
|
const slug = url.searchParams.get('slug');
|
|
if (!slug) return new Response("Missing slug", { status: 400 });
|
|
|
|
let dest = await env.KV_EV.get(slug);
|
|
if (!dest) return new Response("Link not found", { status: 404 });
|
|
|
|
const seized = dest.startsWith('🚫');
|
|
if (seized) dest = dest.substring(1);
|
|
|
|
const analytics_enabled = dest.startsWith('✺');
|
|
const destination_url = analytics_enabled ? dest.substring(1) : dest;
|
|
|
|
return Response.json({ destination_url, analytics_enabled, seized });
|
|
} catch (e) {
|
|
return new Response(e.message, { status: 500 });
|
|
}
|
|
}
|
|
|