mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
Merge branch 'deno-2.0' into 'main'
Ugrade to Deno 2.0 See merge request soapbox-pub/ditto!511
This commit is contained in:
commit
70e27b04f4
8 changed files with 19 additions and 19 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
image: denoland/deno:1.46.3
|
image: denoland/deno:2.0.0-rc.3
|
||||||
|
|
||||||
default:
|
default:
|
||||||
interruptible: true
|
interruptible: true
|
||||||
|
|
|
||||||
|
|
@ -102,7 +102,7 @@ async function exportEvents(args: ExportFilter) {
|
||||||
let filter: NostrFilter = {};
|
let filter: NostrFilter = {};
|
||||||
try {
|
try {
|
||||||
filter = buildFilter(args);
|
filter = buildFilter(args);
|
||||||
} catch (e) {
|
} catch (e: any) {
|
||||||
die(1, e.message || e.toString());
|
die(1, e.message || e.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -104,7 +104,7 @@ function connectStream(socket: WebSocket, ip: string | undefined) {
|
||||||
for (const event of await store.query(filters, { limit: FILTER_LIMIT, timeout: Conf.db.timeouts.relay })) {
|
for (const event of await store.query(filters, { limit: FILTER_LIMIT, timeout: Conf.db.timeouts.relay })) {
|
||||||
send(['EVENT', subId, event]);
|
send(['EVENT', subId, event]);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e: any) {
|
||||||
if (e instanceof RelayError) {
|
if (e instanceof RelayError) {
|
||||||
send(['CLOSED', subId, e.message]);
|
send(['CLOSED', subId, e.message]);
|
||||||
} else if (e.message.includes('timeout')) {
|
} else if (e.message.includes('timeout')) {
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ export class ConnectSigner implements NostrSigner {
|
||||||
const signer = await this.signer;
|
const signer = await this.signer;
|
||||||
try {
|
try {
|
||||||
return await signer.signEvent(event);
|
return await signer.signEvent(event);
|
||||||
} catch (e) {
|
} catch (e: any) {
|
||||||
if (e.name === 'AbortError') {
|
if (e.name === 'AbortError') {
|
||||||
throw new HTTPException(408, { message: 'The event was not signed quickly enough' });
|
throw new HTTPException(408, { message: 'The event was not signed quickly enough' });
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -44,7 +44,7 @@ export class ConnectSigner implements NostrSigner {
|
||||||
const signer = await this.signer;
|
const signer = await this.signer;
|
||||||
try {
|
try {
|
||||||
return await signer.nip04.encrypt(pubkey, plaintext);
|
return await signer.nip04.encrypt(pubkey, plaintext);
|
||||||
} catch (e) {
|
} catch (e: any) {
|
||||||
if (e.name === 'AbortError') {
|
if (e.name === 'AbortError') {
|
||||||
throw new HTTPException(408, {
|
throw new HTTPException(408, {
|
||||||
message: 'Text was not encrypted quickly enough',
|
message: 'Text was not encrypted quickly enough',
|
||||||
|
|
@ -59,7 +59,7 @@ export class ConnectSigner implements NostrSigner {
|
||||||
const signer = await this.signer;
|
const signer = await this.signer;
|
||||||
try {
|
try {
|
||||||
return await signer.nip04.decrypt(pubkey, ciphertext);
|
return await signer.nip04.decrypt(pubkey, ciphertext);
|
||||||
} catch (e) {
|
} catch (e: any) {
|
||||||
if (e.name === 'AbortError') {
|
if (e.name === 'AbortError') {
|
||||||
throw new HTTPException(408, {
|
throw new HTTPException(408, {
|
||||||
message: 'Text was not decrypted quickly enough',
|
message: 'Text was not decrypted quickly enough',
|
||||||
|
|
@ -76,7 +76,7 @@ export class ConnectSigner implements NostrSigner {
|
||||||
const signer = await this.signer;
|
const signer = await this.signer;
|
||||||
try {
|
try {
|
||||||
return await signer.nip44.encrypt(pubkey, plaintext);
|
return await signer.nip44.encrypt(pubkey, plaintext);
|
||||||
} catch (e) {
|
} catch (e: any) {
|
||||||
if (e.name === 'AbortError') {
|
if (e.name === 'AbortError') {
|
||||||
throw new HTTPException(408, {
|
throw new HTTPException(408, {
|
||||||
message: 'Text was not encrypted quickly enough',
|
message: 'Text was not encrypted quickly enough',
|
||||||
|
|
@ -91,7 +91,7 @@ export class ConnectSigner implements NostrSigner {
|
||||||
const signer = await this.signer;
|
const signer = await this.signer;
|
||||||
try {
|
try {
|
||||||
return await signer.nip44.decrypt(pubkey, ciphertext);
|
return await signer.nip44.decrypt(pubkey, ciphertext);
|
||||||
} catch (e) {
|
} catch (e: any) {
|
||||||
if (e.name === 'AbortError') {
|
if (e.name === 'AbortError') {
|
||||||
throw new HTTPException(408, {
|
throw new HTTPException(408, {
|
||||||
message: 'Text was not decrypted quickly enough',
|
message: 'Text was not decrypted quickly enough',
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ class EventsDB extends NPostgres {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Insert an event (and its tags) into the database. */
|
/** Insert an event (and its tags) into the database. */
|
||||||
async event(event: NostrEvent, opts: { signal?: AbortSignal; timeout?: number } = {}): Promise<void> {
|
override async event(event: NostrEvent, opts: { signal?: AbortSignal; timeout?: number } = {}): Promise<void> {
|
||||||
event = purifyEvent(event);
|
event = purifyEvent(event);
|
||||||
this.console.debug('EVENT', JSON.stringify(event));
|
this.console.debug('EVENT', JSON.stringify(event));
|
||||||
dbEventsCounter.inc({ kind: event.kind });
|
dbEventsCounter.inc({ kind: event.kind });
|
||||||
|
|
@ -72,7 +72,7 @@ class EventsDB extends NPostgres {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await super.event(event, { ...opts, timeout: opts.timeout ?? this.opts.timeout });
|
await super.event(event, { ...opts, timeout: opts.timeout ?? this.opts.timeout });
|
||||||
} catch (e) {
|
} catch (e: any) {
|
||||||
if (e.message === 'Cannot add a deleted event') {
|
if (e.message === 'Cannot add a deleted event') {
|
||||||
throw new RelayError('blocked', 'event deleted by user');
|
throw new RelayError('blocked', 'event deleted by user');
|
||||||
} else if (e.message === 'Cannot replace an event with an older event') {
|
} else if (e.message === 'Cannot replace an event with an older event') {
|
||||||
|
|
@ -144,7 +144,7 @@ class EventsDB extends NPostgres {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected getFilterQuery(trx: Kysely<NPostgresSchema>, filter: NostrFilter) {
|
protected override getFilterQuery(trx: Kysely<NPostgresSchema>, filter: NostrFilter) {
|
||||||
if (filter.search) {
|
if (filter.search) {
|
||||||
const tokens = NIP50.parseInput(filter.search);
|
const tokens = NIP50.parseInput(filter.search);
|
||||||
|
|
||||||
|
|
@ -172,7 +172,7 @@ class EventsDB extends NPostgres {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get events for filters from the database. */
|
/** Get events for filters from the database. */
|
||||||
async query(
|
override async query(
|
||||||
filters: NostrFilter[],
|
filters: NostrFilter[],
|
||||||
opts: { signal?: AbortSignal; timeout?: number; limit?: number } = {},
|
opts: { signal?: AbortSignal; timeout?: number; limit?: number } = {},
|
||||||
): Promise<NostrEvent[]> {
|
): Promise<NostrEvent[]> {
|
||||||
|
|
@ -200,13 +200,13 @@ class EventsDB extends NPostgres {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Delete events based on filters from the database. */
|
/** Delete events based on filters from the database. */
|
||||||
async remove(filters: NostrFilter[], opts: { signal?: AbortSignal; timeout?: number } = {}): Promise<void> {
|
override async remove(filters: NostrFilter[], opts: { signal?: AbortSignal; timeout?: number } = {}): Promise<void> {
|
||||||
this.console.debug('DELETE', JSON.stringify(filters));
|
this.console.debug('DELETE', JSON.stringify(filters));
|
||||||
return super.remove(filters, { ...opts, timeout: opts.timeout ?? this.opts.timeout });
|
return super.remove(filters, { ...opts, timeout: opts.timeout ?? this.opts.timeout });
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get number of events that would be returned by filters. */
|
/** Get number of events that would be returned by filters. */
|
||||||
async count(
|
override async count(
|
||||||
filters: NostrFilter[],
|
filters: NostrFilter[],
|
||||||
opts: { signal?: AbortSignal; timeout?: number } = {},
|
opts: { signal?: AbortSignal; timeout?: number } = {},
|
||||||
): Promise<{ count: number; approximate: any }> {
|
): Promise<{ count: number; approximate: any }> {
|
||||||
|
|
@ -218,7 +218,7 @@ class EventsDB extends NPostgres {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Return only the tags that should be indexed. */
|
/** Return only the tags that should be indexed. */
|
||||||
static indexTags(event: NostrEvent): string[][] {
|
static override indexTags(event: NostrEvent): string[][] {
|
||||||
const tagCounts: Record<string, number> = {};
|
const tagCounts: Record<string, number> = {};
|
||||||
|
|
||||||
function getCount(name: string) {
|
function getCount(name: string) {
|
||||||
|
|
@ -325,7 +325,7 @@ class EventsDB extends NPostgres {
|
||||||
return filters;
|
return filters;
|
||||||
}
|
}
|
||||||
|
|
||||||
async transaction(callback: (store: NPostgres, kysely: Kysely<any>) => Promise<void>): Promise<void> {
|
override async transaction(callback: (store: NPostgres, kysely: Kysely<any>) => Promise<void>): Promise<void> {
|
||||||
return super.transaction((store, kysely) => callback(store, kysely as unknown as Kysely<DittoTables>));
|
return super.transaction((store, kysely) => callback(store, kysely as unknown as Kysely<DittoTables>));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -106,7 +106,7 @@ export async function updateTrendingTags(
|
||||||
|
|
||||||
await handleEvent(label, signal);
|
await handleEvent(label, signal);
|
||||||
console.info(`Trending ${l} updated.`);
|
console.info(`Trending ${l} updated.`);
|
||||||
} catch (e) {
|
} catch (e: any) {
|
||||||
console.error(`Error updating trending ${l}: ${e.message}`);
|
console.error(`Error updating trending ${l}: ${e.message}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ try {
|
||||||
adminPubkey: Conf.pubkey,
|
adminPubkey: Conf.pubkey,
|
||||||
});
|
});
|
||||||
console.debug(`Using custom policy: ${Conf.policy}`);
|
console.debug(`Using custom policy: ${Conf.policy}`);
|
||||||
} catch (e) {
|
} catch (e: any) {
|
||||||
if (e.message.includes('Module not found')) {
|
if (e.message.includes('Module not found')) {
|
||||||
console.debug('Custom policy not found <https://docs.soapbox.pub/ditto/policies/>');
|
console.debug('Custom policy not found <https://docs.soapbox.pub/ditto/policies/>');
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ export class CustomPolicy implements NPolicy {
|
||||||
try {
|
try {
|
||||||
const Policy = (await import(path)).default;
|
const Policy = (await import(path)).default;
|
||||||
this.policy = new Policy({ store });
|
this.policy = new Policy({ store });
|
||||||
} catch (e) {
|
} catch (e: any) {
|
||||||
if (e.message.includes('Module not found')) {
|
if (e.message.includes('Module not found')) {
|
||||||
this.policy = new NoOpPolicy();
|
this.policy = new NoOpPolicy();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue