WIP Hello world

This commit is contained in:
2024-10-20 19:59:06 +02:00
commit b618c6a1a1
9 changed files with 657 additions and 0 deletions

36
handlers/naddr.ts Normal file
View File

@@ -0,0 +1,36 @@
import { ctx } from "@oak/oak";
import { nip19 } from "@nostr/tools";
import { log } from "../log.ts";
import { articleHtml } from "../html.ts"
import {
fetchReplaceableEvent,
fetchProfileEvent
} from "../nostr.ts";
const naddrHandler = async function (ctx: ctx) {
const { request } = ctx;
const { path } = ctx.params;
try {
const r = nip19.decode(path);
const articleEvent = await fetchReplaceableEvent(r.data.pubkey, r.data.identifier);
const profileEvent = await fetchProfileEvent(r.data.pubkey);
let profile;
if (articleEvent && profileEvent) {
const profile = JSON.parse(profileEvent.content);
const html = articleHtml(articleEvent, profile);
ctx.response.body = html;
} else {
ctx.response.status = 404;
ctx.response.body = "Not Found";
}
} catch (e) {
log(e, "yellow");
ctx.response.status = 404;
ctx.response.body = "Not Found";
}
};
export default naddrHandler;

10
handlers/nprofile.ts Normal file
View File

@@ -0,0 +1,10 @@
import { Context } from "@oak/oak";
const nprofileHandler = function (context: Context) {
const { request, response } = context;
const fullPath = request.url.pathname;
response.body = `You are viewing an nprofile with address: ${fullPath}`;
};
export default nprofileHandler;