This commit is contained in:
Râu Cao 2025-04-21 14:31:38 +04:00
parent 07f881d543
commit fb37db8583
Signed by: raucao
GPG Key ID: 37036C356E56CC51
2 changed files with 8 additions and 8 deletions

View File

@ -2,7 +2,7 @@ import config from "./config.ts";
import { lookupUsernameByPubkey as ldapLookupUsername } from "./ldap.ts";
import { lookupPubkeyByUsername as ldapLookupPubkey } from "./ldap.ts";
export function lookupUsernameByPubkey(pubkey: string) {
export async function lookupUsernameByPubkey(pubkey: string): Promise<string | undefined> {
let username;
for (const [key, value] of Object.entries(config.staticUsers)) {
if (value === pubkey) {
@ -20,7 +20,7 @@ export function lookupUsernameByPubkey(pubkey: string) {
}
}
export function lookupPubkeyByUsername(username: string) {
export async function lookupPubkeyByUsername(username: string): Promise<string | undefined> {
const pubkey = config.staticUsers[username];
if (pubkey) {

12
ldap.ts
View File

@ -8,8 +8,8 @@ if (ldapEnabled) {
client = new Client({ url: ldap.url as string });
}
export async function lookupPubkeyByUsername(username: string) {
let pubkey;
export async function lookupPubkeyByUsername(username: string): Promise<string | undefined> {
let pubkey: string | undefined;
try {
await client.bind(ldap.bindDN as string, ldap.password as string);
@ -23,7 +23,7 @@ export async function lookupPubkeyByUsername(username: string) {
searchEntries.length > 0 &&
typeof searchEntries[0].nostrKey === "string"
) {
pubkey = searchEntries[0].nostrKey;
pubkey = searchEntries[0].nostrKey.toString();
}
await client.unbind();
@ -35,8 +35,8 @@ export async function lookupPubkeyByUsername(username: string) {
return pubkey;
}
export async function lookupUsernameByPubkey(pubkey: string) {
let username;
export async function lookupUsernameByPubkey(pubkey: string): Promise<string | undefined> {
let username: string | undefined;
try {
await client.bind(ldap.bindDN as string, ldap.password as string);
@ -47,7 +47,7 @@ export async function lookupUsernameByPubkey(pubkey: string) {
});
if (searchEntries.length > 0) {
username = searchEntries[0].cn;
username = searchEntries[0].cn.toString();
}
} catch (e) {
await client.unbind();