fix urls for storybook static build

This commit is contained in:
Gauthier Roebroeck 2026-03-12 11:08:44 +08:00
parent f82e5e7dc6
commit 9c9d4ace3b
5 changed files with 20 additions and 15 deletions

View file

@ -4,5 +4,13 @@ declare global {
}
}
export const API_BASE_URL =
import.meta.env.VITE_KOMGA_API_URL || window.location.origin + window.resourceBaseUrl
const fullUrl =
import.meta.env.VITE_KOMGA_API_URL || window.location.origin + (window.resourceBaseUrl || '/')
const baseUrlSlash = !fullUrl.endsWith('/') ? `${fullUrl}/` : fullUrl
const baseUrlNoSlash = baseUrlSlash.endsWith('/') ? baseUrlSlash.slice(0, -1) : baseUrlSlash
export const ApiBaseUrl = {
slash: baseUrlSlash,
noSlash: baseUrlNoSlash,
}

View file

@ -1,26 +1,26 @@
import { API_BASE_URL } from '@/api/base'
import { ApiBaseUrl } from '@/api/base'
export function seriesThumbnailUrl(seriesId?: string): string | undefined {
if (seriesId) return `${API_BASE_URL}/api/v1/series/${seriesId}/thumbnail`
if (seriesId) return `${ApiBaseUrl.noSlash}/api/v1/series/${seriesId}/thumbnail`
return undefined
}
export function bookThumbnailUrl(bookId?: string): string | undefined {
if (bookId) return `${API_BASE_URL}/api/v1/books/${bookId}/thumbnail`
if (bookId) return `${ApiBaseUrl.noSlash}/api/v1/books/${bookId}/thumbnail`
return undefined
}
export function bookPageThumbnailUrl(bookId?: string, page?: number): string | undefined {
if (bookId && page) return `${API_BASE_URL}/api/v1/books/${bookId}/pages/${page}/thumbnail`
if (bookId && page) return `${ApiBaseUrl.noSlash}/api/v1/books/${bookId}/pages/${page}/thumbnail`
return undefined
}
export function pageHashKnownThumbnailUrl(hash?: string): string | undefined {
if (hash) return `${API_BASE_URL}/api/v1/page-hashes/${hash}/thumbnail`
if (hash) return `${ApiBaseUrl.noSlash}/api/v1/page-hashes/${hash}/thumbnail`
return undefined
}
export function pageHashUnknownThumbnailUrl(hash?: string): string | undefined {
if (hash) return `${API_BASE_URL}/api/v1/page-hashes/unknown/${hash}/thumbnail`
if (hash) return `${ApiBaseUrl.noSlash}/api/v1/page-hashes/unknown/${hash}/thumbnail`
return undefined
}

View file

@ -1,7 +1,7 @@
import type { Middleware } from 'openapi-fetch'
import createClient from 'openapi-fetch'
import type { paths } from '@/generated/openapi/komga'
import { API_BASE_URL } from '@/api/base'
import { ApiBaseUrl } from '@/api/base'
// Middleware that throws on error, so it works with Pinia Colada
const coladaMiddleware: Middleware = {
@ -28,7 +28,7 @@ const coladaMiddleware: Middleware = {
}
const client = createClient<paths>({
baseUrl: API_BASE_URL,
baseUrl: ApiBaseUrl.noSlash,
// required to pass the session cookie on all requests
credentials: 'include',
// required to avoid browser basic-auth popups

View file

@ -21,8 +21,6 @@ declare module 'vue' {
BookDeletionWarning: typeof import('./components/book/DeletionWarning.vue')['default']
BookMenu: typeof import('./components/book/menu/BookMenu.vue')['default']
BookMenuBottomSheet: typeof import('./components/book/menu/BookMenuBottomSheet.vue')['default']
BookMenuSeriesMenu: typeof import('./components/book/menu/SeriesMenu.vue')['default']
BookMenuSeriesMenuBottomSheet: typeof import('./components/book/menu/SeriesMenuBottomSheet.vue')['default']
BuildCommit: typeof import('./components/BuildCommit.vue')['default']
BuildVersion: typeof import('./components/BuildVersion.vue')['default']
DialogBookPicker: typeof import('./components/dialog/BookPicker.vue')['default']
@ -103,7 +101,6 @@ declare module 'vue' {
SeriesFormEditMetadata: typeof import('./components/series/form/EditMetadata.vue')['default']
SeriesMenu: typeof import('./components/series/menu/SeriesMenu.vue')['default']
SeriesMenuBottomSheet: typeof import('./components/series/menu/SeriesMenuBottomSheet.vue')['default']
'SeriesMenuBottomSheet.stories': typeof import('./components/series/menu/SeriesMenuBottomSheet.stories.ts')['default']
ServerSettings: typeof import('./components/server/Settings.vue')['default']
SnackQueue: typeof import('./components/SnackQueue.vue')['default']
ThemeSelector: typeof import('./components/ThemeSelector.vue')['default']

View file

@ -1,5 +1,5 @@
import { createOpenApiHttp } from 'openapi-msw'
import type { paths } from '@/generated/openapi/komga'
import { API_BASE_URL } from '@/api/base'
import { ApiBaseUrl } from '@/api/base'
export const httpTyped = createOpenApiHttp<paths>({ baseUrl: API_BASE_URL })
export const httpTyped = createOpenApiHttp<paths>({ baseUrl: ApiBaseUrl.noSlash })