polish
This commit is contained in:
@@ -5,6 +5,7 @@ import { fetch } from '@tauri-apps/api/http';
|
||||
import { NostrFetcher } from 'nostr-fetch';
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
|
||||
import TauriAdapter from '@libs/ndk/cache';
|
||||
import { useStorage } from '@libs/storage/provider';
|
||||
|
||||
export const NDKInstance = () => {
|
||||
@@ -13,6 +14,7 @@ export const NDKInstance = () => {
|
||||
const [ndk, setNDK] = useState<NDK | undefined>(undefined);
|
||||
const [relayUrls, setRelayUrls] = useState<string[]>([]);
|
||||
|
||||
const cacheAdapter = useMemo(() => new TauriAdapter(), []);
|
||||
const fetcher = useMemo(
|
||||
() => (ndk ? NostrFetcher.withCustomPool(ndkAdapter(ndk)) : null),
|
||||
[ndk]
|
||||
@@ -58,6 +60,7 @@ export const NDKInstance = () => {
|
||||
const explicitRelayUrls = await getExplicitRelays();
|
||||
const instance = new NDK({
|
||||
explicitRelayUrls,
|
||||
cacheAdapter,
|
||||
});
|
||||
|
||||
try {
|
||||
@@ -75,6 +78,10 @@ export const NDKInstance = () => {
|
||||
|
||||
useEffect(() => {
|
||||
if (!ndk) initNDK();
|
||||
|
||||
return () => {
|
||||
cacheAdapter.saveCache();
|
||||
};
|
||||
}, []);
|
||||
|
||||
return {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { NDKEvent } from '@nostr-dev-kit/ndk';
|
||||
import { NDKEvent, NDKUserProfile } from '@nostr-dev-kit/ndk';
|
||||
import { BaseDirectory, removeFile } from '@tauri-apps/api/fs';
|
||||
import Database from 'tauri-plugin-sql-api';
|
||||
import { Stronghold } from 'tauri-plugin-stronghold-api';
|
||||
@@ -302,6 +302,13 @@ export class LumeStorage {
|
||||
);
|
||||
}
|
||||
|
||||
public async createProfile(pubkey: string, profile: NDKUserProfile) {
|
||||
return await this.db.execute(
|
||||
'INSERT OR REPLACE INTO metadata (id, event, author, kind, created_at) VALUES ($1, $2, $3, $4, $5);',
|
||||
[pubkey, JSON.stringify(profile), pubkey, 0, Math.round(Date.now() / 1000)]
|
||||
);
|
||||
}
|
||||
|
||||
public async getMetadataByPubkey(pubkey: string) {
|
||||
const results: DBEvent[] = await this.db.select(
|
||||
'SELECT * FROM metadata WHERE author = $1 AND kind = "0" LIMIT 1;',
|
||||
|
||||
Reference in New Issue
Block a user