fix(web): respect base path for icon assets (#2192)

This commit is contained in:
Guoyu Su 2026-06-30 20:01:10 +08:00 committed by GitHub
parent c6719eec55
commit 9d97197a61
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 7 additions and 3 deletions

View File

@ -3,6 +3,7 @@ import { computed, ref, watch } from "vue";
import { Settings2 } from "@lucide/vue";
import type { AiProvider } from "@/stores/settingsStore";
import { useTheme } from "@/composables/useTheme";
import { webPath } from "@/lib/webPath";
const props = defineProps<{
provider: AiProvider;
@ -22,8 +23,8 @@ watch(
const usesWhiteDarkIcon = computed(() => props.provider === "claude" || props.provider === "ollama" || props.provider === "openai" || props.provider === "openai-compatible");
const localIconUrl = computed(() => {
if (props.provider === "openai-compatible") return "/icons/ai/openai.svg";
return props.iconSlug ? `/icons/ai/${props.iconSlug}.svg` : "";
if (props.provider === "openai-compatible") return webPath("/icons/ai/openai.svg");
return props.iconSlug ? webPath(`/icons/ai/${props.iconSlug}.svg`) : "";
});
const fallbackText = computed(() => {
if (props.provider === "openai-compatible") return "OC";

View File

@ -1,6 +1,7 @@
<script setup lang="ts">
import { computed } from "vue";
import { Database } from "@lucide/vue";
import { webPath } from "@/lib/webPath";
const props = defineProps<{
dbType: string;
@ -97,7 +98,7 @@ const normalizedType = computed(() => props.dbType.toLowerCase().replace(/[\s-]+
const assetName = computed(() => assetIcons[normalizedType.value]);
const assetSrc = computed(() => {
if (!assetName.value) return "";
return assetName.value.includes(".") ? `/icons/database/${assetName.value}` : `/icons/database/${assetName.value}.svg`;
return webPath(assetName.value.includes(".") ? `/icons/database/${assetName.value}` : `/icons/database/${assetName.value}.svg`);
});
const letter = computed(() => letterIcons[normalizedType.value]);
</script>

View File

@ -11,6 +11,8 @@ describe("webPath", () => {
expect(dbxWebBasePath("/", "/dbx/")).toBe("/dbx");
expect(webPath("/login", "/dbx")).toBe("/dbx/login");
expect(webPath("/", "/dbx")).toBe("/dbx/");
expect(webPath("/icons/database/mysql.svg", "/dbx")).toBe("/dbx/icons/database/mysql.svg");
expect(webPath("/icons/ai/openai.svg", "/dbx")).toBe("/dbx/icons/ai/openai.svg");
expect(apiUrl("/auth/check", "/dbx")).toBe("/dbx/api/auth/check");
expect(apiUrl("/api/auth/check", "/dbx")).toBe("/dbx/api/auth/check");
expect(apiUrl("api/auth/check", "/dbx")).toBe("/dbx/api/auth/check");