From 04c8e43ef7425bdae53a78d79db7a91a32b27528 Mon Sep 17 00:00:00 2001 From: AdingApkgg Date: Wed, 21 Jan 2026 00:48:39 +0800 Subject: [PATCH] feat: enhance URL handling and update API server configuration - Renamed extractPath function to decodeUrl for clarity and updated its implementation to decode URLs properly. - Modified SettingsModal to use a new default API key variable for better maintainability. - Added new API server entries for Vercel and Netlify in api.json to expand available options. --- src/components/ResultItem.vue | 11 ++++++----- src/components/SettingsModal.vue | 10 ++++++---- src/data/api.json | 10 ++++++++++ 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/components/ResultItem.vue b/src/components/ResultItem.vue index ba50b66..43410a0 100644 --- a/src/components/ResultItem.vue +++ b/src/components/ResultItem.vue @@ -13,12 +13,13 @@ defineProps<{ const copied = ref(false) -// 从URL中提取路径 -function extractPath(url: string): string { +// 解码 URL 显示(包含完整网址) +function decodeUrl(url: string): string { try { - const urlObj = new URL(url) - return urlObj.pathname + urlObj.search + urlObj.hash + // 解码 URL 编码的中文等字符 + return decodeURIComponent(url) } catch { + // 解码失败则返回原始 URL return url } } @@ -86,7 +87,7 @@ async function copyLink(url: string) {
- {{ extractPath(source.url) }} + {{ decodeUrl(source.url) }}
diff --git a/src/components/SettingsModal.vue b/src/components/SettingsModal.vue index cab60e2..9182970 100644 --- a/src/components/SettingsModal.vue +++ b/src/components/SettingsModal.vue @@ -559,12 +559,14 @@ const apiUrls: Record = Object.fromEntries( const deployUrl = apiData.deployUrl const contributeUrl = apiData.contributeUrl +// 默认 API 服务器 key(第一个) +const defaultApiKey = apiData.servers[0]?.key || 'custom' + // 根据 URL 判断选中的选项 function getOptionFromUrl(url: string): string { // 空 URL 或匹配第一个服务器(默认) - const defaultKey = apiData.servers[0]?.key || 'cfapi' - if (!url || url === apiUrls[defaultKey]) { - return defaultKey + if (!url || url === apiUrls[defaultApiKey]) { + return defaultApiKey } // 遍历查找匹配的服务器 for (const [key, serverUrl] of Object.entries(apiUrls)) { @@ -693,7 +695,7 @@ const localCustomApi = computed(() => { if (selectedApiOption.value === 'custom') { return customApiInput.value } - if (selectedApiOption.value === 'cfapi') { + if (selectedApiOption.value === defaultApiKey) { return '' // 空字符串表示使用默认 } return apiUrls[selectedApiOption.value] || '' diff --git a/src/data/api.json b/src/data/api.json index ca7abc6..6f44e84 100644 --- a/src/data/api.json +++ b/src/data/api.json @@ -1,10 +1,20 @@ { "servers": [ + { + "key": "vercelapi", + "label": "Vercel", + "url": "https://vercel.api.searchgal.homes" + }, { "key": "cfapi", "label": "Cloudflare", "url": "https://cf.api.searchgal.homes" }, + { + "key": "netlifyapi", + "label": "Netlify", + "url": "https://netlify.api.searchgal.homes" + }, { "key": "api", "label": "香港 雨云",