53 lines
1.4 KiB
TypeScript
53 lines
1.4 KiB
TypeScript
import { businessConfig } from "@/lib/seo-config"
|
|
|
|
function cleanBaseUrl(value: string) {
|
|
return value.replace(/\/$/, "")
|
|
}
|
|
|
|
function getSiteBaseUrl() {
|
|
return cleanBaseUrl(
|
|
process.env.NEXT_PUBLIC_SITE_URL ||
|
|
process.env.VOICE_ASSISTANT_SITE_URL ||
|
|
businessConfig.website,
|
|
)
|
|
}
|
|
|
|
export function getManualsAssetBaseUrl() {
|
|
return cleanBaseUrl(process.env.NEXT_PUBLIC_MANUALS_BASE_URL || `${getSiteBaseUrl()}/manuals`)
|
|
}
|
|
|
|
export function getThumbnailsAssetBaseUrl() {
|
|
return cleanBaseUrl(process.env.NEXT_PUBLIC_THUMBNAILS_BASE_URL || `${getSiteBaseUrl()}/thumbnails`)
|
|
}
|
|
|
|
export function getManualsAssetSource() {
|
|
return process.env.NEXT_PUBLIC_MANUALS_BASE_URL && process.env.NEXT_PUBLIC_THUMBNAILS_BASE_URL
|
|
? "external-object-storage"
|
|
: "site-static"
|
|
}
|
|
|
|
export function buildManualAssetUrl(relativePath: string) {
|
|
const encodedPath = relativePath
|
|
.split("/")
|
|
.map((segment) => encodeURIComponent(decodeURIComponentSafe(segment)))
|
|
.join("/")
|
|
|
|
return `${getManualsAssetBaseUrl()}/${encodedPath}`
|
|
}
|
|
|
|
export function buildThumbnailAssetUrl(relativePath: string) {
|
|
const encodedPath = relativePath
|
|
.split("/")
|
|
.map((segment) => encodeURIComponent(decodeURIComponentSafe(segment)))
|
|
.join("/")
|
|
|
|
return `${getThumbnailsAssetBaseUrl()}/${encodedPath}`
|
|
}
|
|
|
|
function decodeURIComponentSafe(value: string) {
|
|
try {
|
|
return decodeURIComponent(value)
|
|
} catch {
|
|
return value
|
|
}
|
|
}
|