diff --git a/src/hooks/useShorturlchange.js b/src/hooks/useShorturlchange.js index 228568f..1357617 100644 --- a/src/hooks/useShorturlchange.js +++ b/src/hooks/useShorturlchange.js @@ -3,7 +3,7 @@ import useConversationStore from '@/stores/ConversationStore'; const useShortUrlChange = () => { const setGlobalNotify = useConversationStore((state) => state.setGlobalNotify); - + const apiPrefix = { "japanhighlights.com": "https://www.japanhighlights.com/index.php", "chinahighlights.com": "https://www.chinahighlights.com/guide-use.php", @@ -35,11 +35,11 @@ const useShortUrlChange = () => { const urlBase64 = (longUrl) => { try { const extracted2 = longUrl.match(/https:\/\/www\.([^\/]+)/)?.[1] || ''; - + const encoder = new TextEncoder(); const utf8Bytes = encoder.encode(longUrl); const base64Url = btoa(String.fromCharCode(...utf8Bytes)); - + return { base64Url, extracted2 }; } catch (error) { setGlobalNotify([{ @@ -63,8 +63,8 @@ const useShortUrlChange = () => { valid: true, origin: url.origin, hostname: url.hostname, - pathname: url.pathname, - params + pathname: url.pathname, + params }; } catch (e) { return { valid: false, error: "Invalid URL" }; @@ -76,18 +76,18 @@ const useShortUrlChange = () => { setGlobalNotify([{ key: Date.now().toString(), title: '错误', - content: '不是有效的长链接', - type: 'error' + content: '没有需要转换的长链接, 请重新输入', + type: 'warning' }]); return null; } const { base64Url, extracted2 } = urlBase64(normalizedUrl.url); - + if (base64Url) { const apiUrl = apiPrefix[extracted2] || apiPrefix["chinahighlights.com"]; const extracted1 = apiUrl.match(/^https?:\/\/[^\/]*\.com/)?.[0] || ''; - + const data = await fetchNowConversationsitems(base64Url, apiUrl); if (data) { const resultShortUrl = extracted1 + data.isl_link; @@ -121,4 +121,4 @@ const useShortUrlChange = () => { return { convertUrl }; }; -export default useShortUrlChange; \ No newline at end of file +export default useShortUrlChange;