Typing
This commit is contained in:
parent
07f881d543
commit
fb37db8583
@ -2,7 +2,7 @@ import config from "./config.ts";
|
|||||||
import { lookupUsernameByPubkey as ldapLookupUsername } from "./ldap.ts";
|
import { lookupUsernameByPubkey as ldapLookupUsername } from "./ldap.ts";
|
||||||
import { lookupPubkeyByUsername as ldapLookupPubkey } 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;
|
let username;
|
||||||
for (const [key, value] of Object.entries(config.staticUsers)) {
|
for (const [key, value] of Object.entries(config.staticUsers)) {
|
||||||
if (value === pubkey) {
|
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];
|
const pubkey = config.staticUsers[username];
|
||||||
|
|
||||||
if (pubkey) {
|
if (pubkey) {
|
||||||
|
12
ldap.ts
12
ldap.ts
@ -8,8 +8,8 @@ if (ldapEnabled) {
|
|||||||
client = new Client({ url: ldap.url as string });
|
client = new Client({ url: ldap.url as string });
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function lookupPubkeyByUsername(username: string) {
|
export async function lookupPubkeyByUsername(username: string): Promise<string | undefined> {
|
||||||
let pubkey;
|
let pubkey: string | undefined;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await client.bind(ldap.bindDN as string, ldap.password as string);
|
await client.bind(ldap.bindDN as string, ldap.password as string);
|
||||||
@ -23,7 +23,7 @@ export async function lookupPubkeyByUsername(username: string) {
|
|||||||
searchEntries.length > 0 &&
|
searchEntries.length > 0 &&
|
||||||
typeof searchEntries[0].nostrKey === "string"
|
typeof searchEntries[0].nostrKey === "string"
|
||||||
) {
|
) {
|
||||||
pubkey = searchEntries[0].nostrKey;
|
pubkey = searchEntries[0].nostrKey.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
await client.unbind();
|
await client.unbind();
|
||||||
@ -35,8 +35,8 @@ export async function lookupPubkeyByUsername(username: string) {
|
|||||||
return pubkey;
|
return pubkey;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function lookupUsernameByPubkey(pubkey: string) {
|
export async function lookupUsernameByPubkey(pubkey: string): Promise<string | undefined> {
|
||||||
let username;
|
let username: string | undefined;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await client.bind(ldap.bindDN as string, ldap.password as string);
|
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) {
|
if (searchEntries.length > 0) {
|
||||||
username = searchEntries[0].cn;
|
username = searchEntries[0].cn.toString();
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
await client.unbind();
|
await client.unbind();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user