From 6126701025eb5011018e086f21e2a21f7e9d8d90 Mon Sep 17 00:00:00 2001 From: Steven Date: Fri, 29 Sep 2023 21:34:23 +0800 Subject: [PATCH] chore: update favicon getter --- .../extension/src/components/ShortcutView.tsx | 14 +------ frontend/extension/src/helpers/api.ts | 14 ------- frontend/extension/src/helpers/utils.ts | 9 ++++ frontend/extension/src/popup.tsx | 3 +- frontend/extension/src/stores/favicon.ts | 41 ------------------- 5 files changed, 13 insertions(+), 68 deletions(-) delete mode 100644 frontend/extension/src/helpers/api.ts delete mode 100644 frontend/extension/src/stores/favicon.ts diff --git a/frontend/extension/src/components/ShortcutView.tsx b/frontend/extension/src/components/ShortcutView.tsx index 447616f..ac196d0 100644 --- a/frontend/extension/src/components/ShortcutView.tsx +++ b/frontend/extension/src/components/ShortcutView.tsx @@ -1,8 +1,7 @@ import type { Shortcut } from "@/types/proto/api/v2/shortcut_service"; import { useStorage } from "@plasmohq/storage/hook"; import classNames from "classnames"; -import { useEffect, useState } from "react"; -import useFaviconStore from "../stores/favicon"; +import { getFaviconWithGoogleS2 } from "@/helpers/utils"; import Icon from "./Icon"; interface Props { @@ -11,17 +10,8 @@ interface Props { const ShortcutView = (props: Props) => { const { shortcut } = props; - const faviconStore = useFaviconStore(); const [domain] = useStorage("domain", ""); - const [favicon, setFavicon] = useState(undefined); - - useEffect(() => { - faviconStore.getOrFetchUrlFavicon(shortcut.link).then((url) => { - if (url) { - setFavicon(url); - } - }); - }, [shortcut.link]); + const favicon = getFaviconWithGoogleS2(shortcut.link); const handleShortcutLinkClick = () => { const shortcutLink = `${domain}/s/${shortcut.name}`; diff --git a/frontend/extension/src/helpers/api.ts b/frontend/extension/src/helpers/api.ts deleted file mode 100644 index 9b7c7c1..0000000 --- a/frontend/extension/src/helpers/api.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { Storage } from "@plasmohq/storage"; -import axios from "axios"; - -const storage = new Storage(); - -export const getUrlFavicon = async (url: string) => { - const domain = await storage.getItem("domain"); - const accessToken = await storage.getItem("access_token"); - return axios.get(`${domain}/api/v1/url/favicon?url=${url}`, { - headers: { - Authorization: `Bearer ${accessToken}`, - }, - }); -}; diff --git a/frontend/extension/src/helpers/utils.ts b/frontend/extension/src/helpers/utils.ts index fad7257..2280589 100644 --- a/frontend/extension/src/helpers/utils.ts +++ b/frontend/extension/src/helpers/utils.ts @@ -3,3 +3,12 @@ import { isNull, isUndefined } from "lodash-es"; export const isNullorUndefined = (value: any) => { return isNull(value) || isUndefined(value); }; + +export const getFaviconWithGoogleS2 = (url: string) => { + try { + const urlObject = new URL(url); + return `https://www.google.com/s2/favicons?sz=128&domain=${urlObject.hostname}`; + } catch (error) { + return undefined; + } +}; diff --git a/frontend/extension/src/popup.tsx b/frontend/extension/src/popup.tsx index b55ec0e..85f4cf7 100644 --- a/frontend/extension/src/popup.tsx +++ b/frontend/extension/src/popup.tsx @@ -86,7 +86,8 @@ const IndexPopup = () => { ) : (
-

No domain and access token found.

+ +

Please set your domain and access token first.