WIP Resolve username via npub, LDAP
This commit is contained in:
30
handlers/npub.ts
Normal file
30
handlers/npub.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { Context } from "@oak/oak";
|
||||
import { nip19 } from "@nostr/tools";
|
||||
import { log } from "../log.ts";
|
||||
import { fetchProfileEvent } from "../nostr.ts";
|
||||
import { profilePageHtml } from "../html.ts"
|
||||
|
||||
const npubHandler = async function (ctx: Context) {
|
||||
const { request } = ctx;
|
||||
const npub = ctx.params.path;
|
||||
|
||||
try {
|
||||
const r = nip19.decode(npub);
|
||||
const profileEvent = await fetchProfileEvent(r.data);
|
||||
|
||||
if (profileEvent) {
|
||||
const html = profilePageHtml(profileEvent);
|
||||
|
||||
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 npubHandler;
|
||||
Reference in New Issue
Block a user