WIP Hello world
This commit is contained in:
36
handlers/naddr.ts
Normal file
36
handlers/naddr.ts
Normal 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
10
handlers/nprofile.ts
Normal 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;
|
||||
Reference in New Issue
Block a user