WIP Resolve username via npub, LDAP
This commit is contained in:
@@ -1,10 +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 nprofileHandler = function (context: Context) {
|
||||
const { request, response } = context;
|
||||
const fullPath = request.url.pathname;
|
||||
const nprofileHandler = async function (ctx: Context) {
|
||||
const { request } = ctx;
|
||||
const nprofile = ctx.params.path;
|
||||
|
||||
response.body = `You are viewing an nprofile with address: ${fullPath}`;
|
||||
try {
|
||||
const r = nip19.decode(nprofile);
|
||||
const profileEvent = await fetchProfileEvent(r.data.pubkey);
|
||||
|
||||
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 nprofileHandler;
|
||||
|
||||
Reference in New Issue
Block a user