19 lines
562 B
TypeScript
19 lines
562 B
TypeScript
import { getDb, type RelayRecord } from '../database';
|
|
import { normalizeRelayUrl } from '$lib/utils/relay-url';
|
|
|
|
/** storage for the relays the user has added. */
|
|
export const relayRepository = {
|
|
async list(): Promise<RelayRecord[]> {
|
|
return getDb().relays.orderBy('addedAt').toArray();
|
|
},
|
|
|
|
async add(url: string): Promise<void> {
|
|
const normalized = normalizeRelayUrl(url);
|
|
await getDb().relays.put({ url: normalized, addedAt: Date.now() });
|
|
},
|
|
|
|
async remove(url: string): Promise<void> {
|
|
await getDb().relays.delete(normalizeRelayUrl(url));
|
|
}
|
|
};
|