clean up and refactor open graph

This commit is contained in:
Ren Amamiya
2023-08-14 09:03:58 +07:00
parent 33fd7512e7
commit c42c78fc98
12 changed files with 256 additions and 654 deletions

View File

@@ -1,12 +1,13 @@
import { useQuery } from '@tanstack/react-query';
import { invoke } from '@tauri-apps/api/tauri';
import { getLinkPreview } from '@libs/openGraph';
import { Opengraph } from '@utils/types';
export function useOpenGraph(url: string) {
const { status, data, error, isFetching } = useQuery(
['preview', url],
async () => {
const res = await getLinkPreview(url);
const res: Opengraph = await invoke('opengraph', { url });
if (!res) {
throw new Error('fetch preview failed');
}

View File

@@ -62,3 +62,10 @@ export interface Relays {
relay: string;
purpose?: string;
}
export interface Opengraph {
url: string;
title?: string;
description?: string;
image?: string;
}