You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.1 KiB
41 lines
1.1 KiB
import { redirect } from "@sveltejs/kit"; |
|
import type { PageServerLoad } from "./$types"; |
|
|
|
// Route pattern constants |
|
const ROUTES = { |
|
PUBLICATION_BASE: "/publication", |
|
NADDR: "/publication/naddr", |
|
NEVENT: "/publication/nevent", |
|
ID: "/publication/id", |
|
D_TAG: "/publication/d", |
|
START: "/start", |
|
} as const; |
|
|
|
// Identifier prefixes |
|
const IDENTIFIER_PREFIXES = { |
|
NADDR: "naddr", |
|
NEVENT: "nevent", |
|
} as const; |
|
|
|
export const load: PageServerLoad = ({ url }) => { |
|
const id = url.searchParams.get("id"); |
|
const dTag = url.searchParams.get("d"); |
|
|
|
// Handle backward compatibility for old query-based routes |
|
if (id) { |
|
// Check if id is an naddr or nevent |
|
if (id.startsWith(IDENTIFIER_PREFIXES.NADDR)) { |
|
throw redirect(301, `${ROUTES.NADDR}/${id}`); |
|
} else if (id.startsWith(IDENTIFIER_PREFIXES.NEVENT)) { |
|
throw redirect(301, `${ROUTES.NEVENT}/${id}`); |
|
} else { |
|
// Assume it's a hex ID |
|
throw redirect(301, `${ROUTES.ID}/${id}`); |
|
} |
|
} else if (dTag) { |
|
throw redirect(301, `${ROUTES.D_TAG}/${dTag}`); |
|
} |
|
|
|
// If no query parameters, redirect to the start page |
|
throw redirect(301, ROUTES.START); |
|
};
|