substr/directory.ts
Râu Cao 5b0397268b
Some checks failed
CI / Test and lint (push) Failing after 10m22s
Improve Nostr link handling
Fixes a bunch of problems with how Nostr links are created and replaced
in Markdown content
2025-04-21 16:53:22 +04:00

35 lines
874 B
TypeScript

// deno-lint-ignore-file require-await
import config from "./config.ts";
import { lookupUsernameByPubkey as ldapLookupUsername } from "./ldap.ts";
import { lookupPubkeyByUsername as ldapLookupPubkey } from "./ldap.ts";
export async function lookupUsernameByPubkey(pubkey: string): Promise<string | undefined> {
let username;
for (const [key, value] of Object.entries(config.staticUsers)) {
if (value === pubkey) {
username = key;
break;
}
}
if (username) {
return username;
} else {
if (config.ldapEnabled) {
return ldapLookupUsername(pubkey);
}
}
}
export async function lookupPubkeyByUsername(username: string): Promise<string | undefined> {
const pubkey = config.staticUsers[username];
if (pubkey) {
return pubkey;
} else {
if (config.ldapEnabled) {
return ldapLookupPubkey(username);
}
}
}