37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import { Context } from "@oak/oak";
|
|
import { lookupPubkeyByUsername } from "../directory.ts";
|
|
import { fetchArticlesByAuthor, fetchProfileEvent } from "../nostr.ts";
|
|
import { profileAtomFeed } from "../feeds.ts";
|
|
import Profile from "../models/profile.ts";
|
|
import { notFoundHandler } from "../handlers/errors.ts";
|
|
import { generateOgProfileImage } from "../magick.ts";
|
|
|
|
const userAtomFeedHandler = async function (ctx: Context) {
|
|
const username = ctx.state.username;
|
|
const pubkey = await lookupPubkeyByUsername(ctx.state.username);
|
|
|
|
if (!pubkey) {
|
|
notFoundHandler(ctx);
|
|
return;
|
|
}
|
|
|
|
const profileEvent = await fetchProfileEvent(pubkey);
|
|
|
|
if (profileEvent) {
|
|
const profile = new Profile(profileEvent, username);
|
|
|
|
if (profile.nip05) {
|
|
await generateOgProfileImage(profile);
|
|
const articles = await fetchArticlesByAuthor(pubkey, 10);
|
|
const atom = await profileAtomFeed(profile, articles);
|
|
|
|
ctx.response.headers.set("Content-Type", "application/atom+xml");
|
|
ctx.response.body = atom;
|
|
return;
|
|
}
|
|
}
|
|
notFoundHandler(ctx);
|
|
};
|
|
|
|
export default userAtomFeedHandler;
|