wip: fully migrate to tauri v2

This commit is contained in:
Ren Amamiya
2023-10-06 09:08:37 +07:00
parent 9627c40d75
commit c71bfb3f6d
21 changed files with 62 additions and 193 deletions

View File

@@ -1,54 +0,0 @@
import { NDKCacheAdapter } from '@nostr-dev-kit/ndk';
import { NDKEvent, NDKSubscription } from '@nostr-dev-kit/ndk';
import { Store } from 'tauri-plugin-store-api';
export default class TauriAdapter implements NDKCacheAdapter {
public store: Store;
readonly locking: boolean;
constructor() {
this.store = new Store('.ndk_cache.dat');
this.locking = true;
}
public async query(subscription: NDKSubscription): Promise<void> {
const { filter } = subscription;
if (filter.authors && filter.kinds) {
const promises = [];
for (const author of filter.authors) {
for (const kind of filter.kinds) {
const key = `${author}:${kind}`;
promises.push(this.store.get(key));
}
}
const results = await Promise.all(promises);
for (const result of results) {
if (result) {
const ndkEvent = new NDKEvent(subscription.ndk, JSON.parse(result as string));
subscription.eventReceived(ndkEvent, undefined, true);
}
}
}
}
public async setEvent(event: NDKEvent): Promise<void> {
const nostrEvent = await event.toNostrEvent();
if (event.kind !== 3) {
const key = `${nostrEvent.pubkey}:${nostrEvent.kind}`;
return new Promise((resolve) => {
Promise.all([this.store.set(key, JSON.stringify(nostrEvent))]).then(() =>
resolve()
);
});
}
}
public async saveCache(): Promise<void> {
return await this.store.save();
}
}

View File

@@ -30,7 +30,6 @@ export const NDKInstance = () => {
try {
const res = await fetch(`https://${url.hostname}`, {
method: 'GET',
timeout: { secs: 5, nanos: 0 },
headers: {
Accept: 'application/nostr+json',
},