mirror of
https://github.com/aljazceru/ditto.git
synced 2026-01-08 16:14:22 +01:00
Remove relays table from the database, track them with a NIP-65 admin event
This commit is contained in:
@@ -2,7 +2,6 @@ export interface DittoTables {
|
||||
events: EventRow;
|
||||
events_fts: EventFTSRow;
|
||||
tags: TagRow;
|
||||
relays: RelayRow;
|
||||
unattached_media: UnattachedMediaRow;
|
||||
author_stats: AuthorStatsRow;
|
||||
event_stats: EventStatsRow;
|
||||
@@ -45,12 +44,6 @@ interface TagRow {
|
||||
event_id: string;
|
||||
}
|
||||
|
||||
interface RelayRow {
|
||||
url: string;
|
||||
domain: string;
|
||||
active: boolean;
|
||||
}
|
||||
|
||||
interface UnattachedMediaRow {
|
||||
id: string;
|
||||
pubkey: string;
|
||||
|
||||
14
src/db/migrations/017_rm_relays.ts
Normal file
14
src/db/migrations/017_rm_relays.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { Kysely } from 'kysely';
|
||||
|
||||
export async function up(db: Kysely<any>): Promise<void> {
|
||||
await db.schema.dropTable('relays').execute();
|
||||
}
|
||||
|
||||
export async function down(db: Kysely<any>): Promise<void> {
|
||||
await db.schema
|
||||
.createTable('relays')
|
||||
.addColumn('url', 'text', (col) => col.primaryKey())
|
||||
.addColumn('domain', 'text', (col) => col.notNull())
|
||||
.addColumn('active', 'boolean', (col) => col.notNull())
|
||||
.execute();
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
import tldts from 'tldts';
|
||||
|
||||
import { db } from '@/db.ts';
|
||||
|
||||
interface AddRelaysOpts {
|
||||
active?: boolean;
|
||||
}
|
||||
|
||||
/** Inserts relays into the database, skipping duplicates. */
|
||||
function addRelays(relays: `wss://${string}`[], opts: AddRelaysOpts = {}) {
|
||||
if (!relays.length) return Promise.resolve();
|
||||
const { active = false } = opts;
|
||||
|
||||
const values = relays.map((url) => ({
|
||||
url: new URL(url).toString(),
|
||||
domain: tldts.getDomain(url)!,
|
||||
active,
|
||||
}));
|
||||
|
||||
return db.insertInto('relays')
|
||||
.values(values)
|
||||
.onConflict((oc) => oc.column('url').doNothing())
|
||||
.execute();
|
||||
}
|
||||
|
||||
/** Get a list of all known active relay URLs. */
|
||||
async function getActiveRelays(): Promise<string[]> {
|
||||
const rows = await db
|
||||
.selectFrom('relays')
|
||||
.select('relays.url')
|
||||
.where('relays.active', '=', true)
|
||||
.execute();
|
||||
|
||||
return rows.map((row) => row.url);
|
||||
}
|
||||
|
||||
export { addRelays, getActiveRelays };
|
||||
Reference in New Issue
Block a user