Improve config, add home relay url

This commit is contained in:
Râu Cao 2024-10-21 15:36:22 +02:00
parent 79c77c9d3c
commit 7c311987f0
Signed by: raucao
GPG Key ID: 37036C356E56CC51
3 changed files with 25 additions and 17 deletions

16
config.ts Normal file
View File

@ -0,0 +1,16 @@
import { load } from "@std/dotenv";
const dirname = new URL(".", import.meta.url).pathname;
await load({ envPath: `${dirname}/.env`, export: true });
const config = {
home_relay_url: Deno.env.get("HOME_RELAY_URL"),
ldap: {
url: Deno.env.get("LDAP_URL"),
bindDN: Deno.env.get("LDAP_BIND_DN"),
password: Deno.env.get("LDAP_PASSWORD"),
searchDN: Deno.env.get("LDAP_SEARCH_DN"),
}
};
export default config;

23
ldap.ts
View File

@ -1,26 +1,17 @@
import { load } from "@std/dotenv";
import { Client } from "ldapts";
import { log } from "./log.ts";
import config from "./config.ts";
const dirname = new URL(".", import.meta.url).pathname;
await load({ envPath: `${dirname}/.env`, export: true });
const config = {
url: Deno.env.get("LDAP_URL"),
bindDN: Deno.env.get("LDAP_BIND_DN"),
password: Deno.env.get("LDAP_PASSWORD"),
searchDN: Deno.env.get("LDAP_SEARCH_DN"),
};
const client = new Client({ url: config.url });
const { ldap } = config;
const client = new Client({ url: ldap.url });
export async function lookupPubkeyByUsername(username: string) {
let pubkey;
try {
await client.bind(config.bindDN, config.password);
await client.bind(ldap.bindDN, ldap.password);
const { searchEntries } = await client.search(config.searchDN, {
const { searchEntries } = await client.search(ldap.searchDN, {
filter: `(cn=${username})`,
attributes: ["nostrKey"],
});
@ -39,9 +30,9 @@ export async function lookupUsernameByPubkey(pubkey: string) {
let username;
try {
await client.bind(config.bindDN, config.password);
await client.bind(ldap.bindDN, ldap.password);
const { searchEntries } = await client.search(config.searchDN, {
const { searchEntries } = await client.search(ldap.searchDN, {
filter: `(nostrKey=${pubkey})`,
attributes: ["cn"],
});

View File

@ -1,4 +1,5 @@
import { NRelay1 } from "@nostrify/nostrify";
import config from "./config.ts";
export interface NEvent {
content: string;
@ -10,7 +11,7 @@ export interface NEvent {
tags: Array<[string, string, string?]>;
}
export const relay = new NRelay1("wss://nostr.kosmos.org");
export const relay = new NRelay1(config.home_relay_url);
export async function fetchReplaceableEvent(
pubkey: string,