wip: fully migrate to tauri v2
This commit is contained in:
@@ -59,7 +59,7 @@ export default function App() {
|
||||
headers: {
|
||||
Accept: 'application/nostr+json',
|
||||
},
|
||||
}).then((res) => res.data),
|
||||
}).then((res) => res.json()),
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { appConfigDir } from '@tauri-apps/api/path';
|
||||
import { Stronghold } from '@tauri-apps/plugin-stronghold';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Resolver, useForm } from 'react-hook-form';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { Stronghold } from 'tauri-plugin-stronghold-api';
|
||||
|
||||
import { useStorage } from '@libs/storage/provider';
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { appConfigDir } from '@tauri-apps/api/path';
|
||||
import { Stronghold } from '@tauri-apps/plugin-stronghold';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Resolver, useForm } from 'react-hook-form';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { Stronghold } from 'tauri-plugin-stronghold-api';
|
||||
|
||||
import { useStorage } from '@libs/storage/provider';
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { useQueryClient } from '@tanstack/react-query';
|
||||
import { appConfigDir } from '@tauri-apps/api/path';
|
||||
import { Stronghold } from '@tauri-apps/plugin-stronghold';
|
||||
import { useState } from 'react';
|
||||
import { Resolver, useForm } from 'react-hook-form';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { Stronghold } from 'tauri-plugin-stronghold-api';
|
||||
|
||||
import { useStorage } from '@libs/storage/provider';
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { appConfigDir } from '@tauri-apps/api/path';
|
||||
import { Stronghold } from '@tauri-apps/plugin-stronghold';
|
||||
import { getPublicKey, nip19 } from 'nostr-tools';
|
||||
import { useState } from 'react';
|
||||
import { Resolver, useForm } from 'react-hook-form';
|
||||
import { Link, useNavigate } from 'react-router-dom';
|
||||
import { Stronghold } from 'tauri-plugin-stronghold-api';
|
||||
|
||||
import { useStorage } from '@libs/storage/provider';
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { appConfigDir } from '@tauri-apps/api/path';
|
||||
import { Stronghold } from '@tauri-apps/plugin-stronghold';
|
||||
import { useState } from 'react';
|
||||
import { Resolver, useForm } from 'react-hook-form';
|
||||
import { Link, useNavigate } from 'react-router-dom';
|
||||
import { Stronghold } from 'tauri-plugin-stronghold-api';
|
||||
|
||||
import { useStorage } from '@libs/storage/provider';
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { invoke } from '@tauri-apps/api';
|
||||
import { message } from '@tauri-apps/plugin-dialog';
|
||||
import { invoke } from '@tauri-apps/api/tauri';
|
||||
import { useEffect } from 'react';
|
||||
|
||||
import { useNDK } from '@libs/ndk/provider';
|
||||
|
||||
@@ -60,7 +60,6 @@ export function EditProfileModal() {
|
||||
|
||||
const res = await fetch(verifyURL, {
|
||||
method: 'GET',
|
||||
timeout: 10,
|
||||
headers: {
|
||||
'Content-Type': 'application/json; charset=utf-8',
|
||||
},
|
||||
@@ -68,7 +67,7 @@ export function EditProfileModal() {
|
||||
|
||||
if (!res.ok) throw new Error(`Failed to fetch NIP-05 service: ${nip05}`);
|
||||
|
||||
const data = res.data as NIP05;
|
||||
const data: NIP05 = await res.json();
|
||||
if (data.names) {
|
||||
if (data.names[localPath] !== db.account.pubkey) return false;
|
||||
return true;
|
||||
@@ -144,7 +143,7 @@ export function EditProfileModal() {
|
||||
Edit profile
|
||||
</button>
|
||||
</Dialog.Trigger>
|
||||
<Dialog.Portal className="relative z-10">
|
||||
<Dialog.Portal>
|
||||
<Dialog.Overlay className="fixed inset-0 z-50 bg-black/80 backdrop-blur-2xl" />
|
||||
<Dialog.Content className="fixed inset-0 z-50 flex min-h-full items-center justify-center">
|
||||
<div className="relative h-min w-full max-w-xl rounded-xl bg-white/10 backdrop-blur-xl">
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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',
|
||||
},
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { NDKEvent } from '@nostr-dev-kit/ndk';
|
||||
import { BaseDirectory, removeFile } from '@tauri-apps/plugin-fs';
|
||||
import { Platform } from '@tauri-apps/plugin-os';
|
||||
import Database from 'tauri-plugin-sql-api';
|
||||
import { Stronghold } from 'tauri-plugin-stronghold-api';
|
||||
import Database from '@tauri-apps/plugin-sql';
|
||||
import { Stronghold } from '@tauri-apps/plugin-stronghold';
|
||||
|
||||
import { FULL_RELAYS } from '@stores/constants';
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { message } from '@tauri-apps/plugin-dialog';
|
||||
import { platform } from '@tauri-apps/plugin-os';
|
||||
import Database from '@tauri-apps/plugin-sql';
|
||||
import { PropsWithChildren, createContext, useContext, useEffect, useState } from 'react';
|
||||
import Database from 'tauri-plugin-sql-api';
|
||||
|
||||
import { LumeStorage } from '@libs/storage/instance';
|
||||
|
||||
|
||||
@@ -30,7 +30,6 @@ export const NIP05 = memo(function NIP05({
|
||||
|
||||
const res = await fetch(verifyURL, {
|
||||
method: 'GET',
|
||||
timeout: 10,
|
||||
headers: {
|
||||
'Content-Type': 'application/json; charset=utf-8',
|
||||
},
|
||||
@@ -38,7 +37,7 @@ export const NIP05 = memo(function NIP05({
|
||||
|
||||
if (!res.ok) throw new Error(`Failed to fetch NIP-05 service: ${nip05}`);
|
||||
|
||||
const data = res.data as NIP05;
|
||||
const data: NIP05 = await res.json();
|
||||
if (data.names) {
|
||||
if (data.names[localPath] !== pubkey) return false;
|
||||
return true;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { downloadDir } from '@tauri-apps/api/path';
|
||||
import { download } from 'tauri-plugin-upload-api';
|
||||
import { download } from '@tauri-apps/plugin-upload';
|
||||
|
||||
import { DownloadIcon } from '@shared/icons';
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
NDKUser,
|
||||
} from '@nostr-dev-kit/ndk';
|
||||
import { message, open } from '@tauri-apps/plugin-dialog';
|
||||
import { Body, fetch } from '@tauri-apps/plugin-http';
|
||||
import { fetch } from '@tauri-apps/plugin-http';
|
||||
import { LRUCache } from 'lru-cache';
|
||||
import { NostrEventExt } from 'nostr-fetch';
|
||||
import { nip19 } from 'nostr-tools';
|
||||
@@ -18,7 +18,6 @@ import { useStorage } from '@libs/storage/provider';
|
||||
|
||||
import { useStronghold } from '@stores/stronghold';
|
||||
|
||||
import { createBlobFromFile } from '@utils/createBlobFromFile';
|
||||
import { nHoursAgo } from '@utils/date';
|
||||
import { getMultipleRandom } from '@utils/transform';
|
||||
import { NDKEventWithReplies, NostrBuildResponse } from '@utils/types';
|
||||
@@ -413,27 +412,19 @@ export function useNostr() {
|
||||
error: 'Cancelled',
|
||||
};
|
||||
} else {
|
||||
filepath = selected;
|
||||
filepath = selected.path;
|
||||
}
|
||||
}
|
||||
|
||||
const filename = filepath.split('/').pop();
|
||||
const filetype = filename.split('.').pop();
|
||||
const formData = new FormData();
|
||||
formData.append('file', filepath);
|
||||
|
||||
const fileData = await createBlobFromFile(filepath);
|
||||
const res: NostrBuildResponse = await fetch(
|
||||
'https://nostr.build/api/v2/upload/files',
|
||||
{
|
||||
method: 'POST',
|
||||
timeout: 30,
|
||||
headers: { 'Content-Type': 'multipart/form-data' },
|
||||
body: Body.form({
|
||||
fileData: {
|
||||
file: fileData,
|
||||
mime: `image/${filetype}`,
|
||||
fileName: filename,
|
||||
},
|
||||
}),
|
||||
body: formData,
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { invoke } from '@tauri-apps/api/tauri';
|
||||
import { invoke } from '@tauri-apps/api';
|
||||
|
||||
import { Opengraph } from '@utils/types';
|
||||
|
||||
|
||||
2
src/utils/types.d.ts
vendored
2
src/utils/types.d.ts
vendored
@@ -94,7 +94,7 @@ export interface NDKEventWithReplies extends NDKEvent {
|
||||
|
||||
export interface NostrBuildResponse extends Response {
|
||||
ok: boolean;
|
||||
data: {
|
||||
data?: {
|
||||
message: string;
|
||||
status: string;
|
||||
data: Array<{
|
||||
|
||||
Reference in New Issue
Block a user