Improve config, add home relay url
This commit is contained in:
parent
79c77c9d3c
commit
7c311987f0
16
config.ts
Normal file
16
config.ts
Normal 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
23
ldap.ts
@ -1,26 +1,17 @@
|
|||||||
import { load } from "@std/dotenv";
|
|
||||||
import { Client } from "ldapts";
|
import { Client } from "ldapts";
|
||||||
import { log } from "./log.ts";
|
import { log } from "./log.ts";
|
||||||
|
import config from "./config.ts";
|
||||||
|
|
||||||
const dirname = new URL(".", import.meta.url).pathname;
|
const { ldap } = config;
|
||||||
await load({ envPath: `${dirname}/.env`, export: true });
|
const client = new Client({ url: ldap.url });
|
||||||
|
|
||||||
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 });
|
|
||||||
|
|
||||||
export async function lookupPubkeyByUsername(username: string) {
|
export async function lookupPubkeyByUsername(username: string) {
|
||||||
let pubkey;
|
let pubkey;
|
||||||
|
|
||||||
try {
|
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})`,
|
filter: `(cn=${username})`,
|
||||||
attributes: ["nostrKey"],
|
attributes: ["nostrKey"],
|
||||||
});
|
});
|
||||||
@ -39,9 +30,9 @@ export async function lookupUsernameByPubkey(pubkey: string) {
|
|||||||
let username;
|
let username;
|
||||||
|
|
||||||
try {
|
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})`,
|
filter: `(nostrKey=${pubkey})`,
|
||||||
attributes: ["cn"],
|
attributes: ["cn"],
|
||||||
});
|
});
|
||||||
|
|||||||
3
nostr.ts
3
nostr.ts
@ -1,4 +1,5 @@
|
|||||||
import { NRelay1 } from "@nostrify/nostrify";
|
import { NRelay1 } from "@nostrify/nostrify";
|
||||||
|
import config from "./config.ts";
|
||||||
|
|
||||||
export interface NEvent {
|
export interface NEvent {
|
||||||
content: string;
|
content: string;
|
||||||
@ -10,7 +11,7 @@ export interface NEvent {
|
|||||||
tags: Array<[string, string, string?]>;
|
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(
|
export async function fetchReplaceableEvent(
|
||||||
pubkey: string,
|
pubkey: string,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user