Clean event before publishing
This commit is contained in:
parent
0b6874bb44
commit
67a52c3b7d
|
@ -0,0 +1,16 @@
|
||||||
|
import { type NostrEvent } from '@/deps.ts';
|
||||||
|
|
||||||
|
/** Return a normalized event without any non-standard keys. */
|
||||||
|
function cleanEvent(event: NostrEvent): NostrEvent {
|
||||||
|
return {
|
||||||
|
id: event.id,
|
||||||
|
pubkey: event.pubkey,
|
||||||
|
kind: event.kind,
|
||||||
|
content: event.content,
|
||||||
|
tags: event.tags,
|
||||||
|
sig: event.sig,
|
||||||
|
created_at: event.created_at,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export { cleanEvent };
|
|
@ -1,6 +1,7 @@
|
||||||
import { Conf } from '@/config.ts';
|
import { Conf } from '@/config.ts';
|
||||||
import { type DittoDB } from '@/db.ts';
|
import { type DittoDB } from '@/db.ts';
|
||||||
import { Debug, Kysely, type NostrEvent, type SelectQueryBuilder } from '@/deps.ts';
|
import { Debug, Kysely, type NostrEvent, type SelectQueryBuilder } from '@/deps.ts';
|
||||||
|
import { cleanEvent } from '@/events.ts';
|
||||||
import { normalizeFilters } from '@/filter.ts';
|
import { normalizeFilters } from '@/filter.ts';
|
||||||
import { DittoEvent } from '@/interfaces/DittoEvent.ts';
|
import { DittoEvent } from '@/interfaces/DittoEvent.ts';
|
||||||
import { type DittoFilter } from '@/interfaces/DittoFilter.ts';
|
import { type DittoFilter } from '@/interfaces/DittoFilter.ts';
|
||||||
|
@ -68,7 +69,7 @@ class EventsDB implements EventStore {
|
||||||
|
|
||||||
/** Insert an event (and its tags) into the database. */
|
/** Insert an event (and its tags) into the database. */
|
||||||
async add(event: NostrEvent): Promise<void> {
|
async add(event: NostrEvent): Promise<void> {
|
||||||
event = cloneEvent(event);
|
event = cleanEvent(event);
|
||||||
this.#debug('EVENT', JSON.stringify(event));
|
this.#debug('EVENT', JSON.stringify(event));
|
||||||
|
|
||||||
if (isDittoInternalKind(event.kind) && event.pubkey !== Conf.pubkey) {
|
if (isDittoInternalKind(event.kind) && event.pubkey !== Conf.pubkey) {
|
||||||
|
@ -409,19 +410,6 @@ function buildSearchContent(event: NostrEvent): string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Return a normalized event without any non-standard keys. */
|
|
||||||
function cloneEvent(event: NostrEvent): NostrEvent {
|
|
||||||
return {
|
|
||||||
id: event.id,
|
|
||||||
pubkey: event.pubkey,
|
|
||||||
kind: event.kind,
|
|
||||||
content: event.content,
|
|
||||||
tags: event.tags,
|
|
||||||
sig: event.sig,
|
|
||||||
created_at: event.created_at,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Build search content for a user. */
|
/** Build search content for a user. */
|
||||||
function buildUserSearchContent(event: NostrEvent): string {
|
function buildUserSearchContent(event: NostrEvent): string {
|
||||||
const { name, nip05, about } = jsonMetaContentSchema.parse(event.content);
|
const { name, nip05, about } = jsonMetaContentSchema.parse(event.content);
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { Debug, matchFilters, type NostrEvent, type NostrFilter, NSet, type RelayPoolWorker } from '@/deps.ts';
|
import { Debug, matchFilters, type NostrEvent, type NostrFilter, NSet, type RelayPoolWorker } from '@/deps.ts';
|
||||||
|
import { cleanEvent } from '@/events.ts';
|
||||||
import { normalizeFilters } from '@/filter.ts';
|
import { normalizeFilters } from '@/filter.ts';
|
||||||
import { type EventStore, type GetEventsOpts, type StoreEventOpts } from '@/storages/types.ts';
|
import { type EventStore, type GetEventsOpts, type StoreEventOpts } from '@/storages/types.ts';
|
||||||
|
|
||||||
|
@ -28,6 +29,7 @@ class PoolStore implements EventStore {
|
||||||
|
|
||||||
add(event: NostrEvent, opts: StoreEventOpts = {}): Promise<void> {
|
add(event: NostrEvent, opts: StoreEventOpts = {}): Promise<void> {
|
||||||
const { relays = this.#relays } = opts;
|
const { relays = this.#relays } = opts;
|
||||||
|
event = cleanEvent(event);
|
||||||
this.#debug('EVENT', event);
|
this.#debug('EVENT', event);
|
||||||
this.#pool.publish(event, relays);
|
this.#pool.publish(event, relays);
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
|
|
Loading…
Reference in New Issue