mirror of
https://github.com/Moe-Sakura/frontend.git
synced 2026-05-10 00:44:13 +08:00
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.
This commit is contained in:
@@ -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) {
|
||||
<div v-if="source.url" class="flex items-center gap-2 mt-2 ml-7 sm:ml-9">
|
||||
<LinkIcon :size="12" class="text-theme-primary/50 dark:text-theme-accent/50 shrink-0" />
|
||||
<span class="text-xs text-gray-500 dark:text-slate-400 break-all font-mono bg-gray-100/80 dark:bg-slate-800/80 px-2 py-1 rounded">
|
||||
{{ extractPath(source.url) }}
|
||||
{{ decodeUrl(source.url) }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -559,12 +559,14 @@ const apiUrls: Record<string, string> = 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] || ''
|
||||
|
||||
@@ -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": "香港 雨云",
|
||||
|
||||
Reference in New Issue
Block a user