27 lines
605 B
TypeScript
27 lines
605 B
TypeScript
|
|
import { backend } from '$lib/backend';
|
||
|
|
import { error, redirect } from '@sveltejs/kit';
|
||
|
|
|
||
|
|
export async function load(event) {
|
||
|
|
const { params } = event;
|
||
|
|
const { id } = params;
|
||
|
|
|
||
|
|
const resp = await backend.withEvent(event).fetch('user/' + encodeURIComponent(id));
|
||
|
|
|
||
|
|
if(resp.status === 404) {
|
||
|
|
error(404);
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
const respJ = await resp.json();
|
||
|
|
|
||
|
|
let { users } = respJ;
|
||
|
|
if (users[id]) {
|
||
|
|
if (users[id].username) {
|
||
|
|
redirect(302, "/@" +users[id].username );
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
error(404);
|
||
|
|
|
||
|
|
}
|