add link preview

This commit is contained in:
Ren Amamiya
2023-06-04 17:20:47 +07:00
parent be6de2344e
commit c4bc67410c
11 changed files with 154 additions and 81 deletions

View File

@@ -0,0 +1,28 @@
import { OPENGRAPH_KEY } from "@stores/constants";
import { fetch } from "@tauri-apps/api/http";
import useSWR from "swr";
const fetcher = async (url: string) => {
const result = await fetch(url, {
method: "GET",
timeout: 20,
});
if (result.ok) {
return result.data;
} else {
return null;
}
};
export function useOpenGraph(url: string) {
const { data, error, isLoading } = useSWR(
`https://skrape.dev/api/opengraph/?url=${url}&key=${OPENGRAPH_KEY}`,
fetcher,
);
return {
data: data,
error: error,
isLoading: isLoading,
};
}