33 lines
1015 B
TypeScript
33 lines
1015 B
TypeScript
import { Context } from "@oak/oak";
|
|
import { lookupPubkeyByUsername } from "../directory.ts";
|
|
import { fetchArticlesByAuthor, fetchProfileEvent } from "../nostr.ts";
|
|
import Profile from "../models/profile.ts";
|
|
import { profilePageHtml } from "../html.ts";
|
|
import { notFoundHandler } from "../handlers/errors.ts";
|
|
import { generateOgProfileImage } from "../magick.ts";
|
|
|
|
const userProfileHandler = async function (ctx: Context) {
|
|
const username = ctx.state.path.replace(/^(@|~)/, "");
|
|
const pubkey = await lookupPubkeyByUsername(username);
|
|
|
|
if (!pubkey) {
|
|
notFoundHandler(ctx);
|
|
return;
|
|
}
|
|
|
|
const profileEvent = await fetchProfileEvent(pubkey);
|
|
|
|
if (profileEvent) {
|
|
const profile = new Profile(profileEvent, username);
|
|
const articles = await fetchArticlesByAuthor(pubkey, 210);
|
|
const html = await profilePageHtml(profile, articles);
|
|
await generateOgProfileImage(profile);
|
|
|
|
ctx.response.body = html;
|
|
} else {
|
|
notFoundHandler(ctx);
|
|
}
|
|
};
|
|
|
|
export default userProfileHandler;
|