@ -57,6 +57,42 @@ export function toAbs(url: string): string {
|
||||
return /^https?:\/\//i.test(url) ? url : getBase() + url
|
||||
}
|
||||
|
||||
// 客户端运行期 base:仅 PUBLIC_API_BASE(空 → 同源相对 /api),
|
||||
// 与 getBase()(含 SSR / DEV 覆盖,用于 RunwayLooks 等)区分,保持 articles 页既有行为。
|
||||
export function publicBase(): string {
|
||||
return ((import.meta.env as any).PUBLIC_API_BASE ?? "").replace(/\/$/, "")
|
||||
}
|
||||
|
||||
// 相对路径补成绝对(基于 PUBLIC_API_BASE);供 articles.astro 客户端脚本复用,
|
||||
// 避免在每个 .astro 文件的 <script> 里重复写 base URL 解析。
|
||||
export function toAbsPublic(url: string): string {
|
||||
if (!url) return ""
|
||||
if (/^https?:\/\//i.test(url)) return url
|
||||
return publicBase() + url
|
||||
}
|
||||
|
||||
// 走秀档案列表(articles.astro 客户端按需拉取):保留该页独有的
|
||||
// 「单值 brand_id / collection_type / season」参数形态与 summary 字段,
|
||||
// 与 getArticles(RunwayLooks 用,参数形态不同)分开维护。
|
||||
export async function fetchArticlesList(opts?: {
|
||||
page?: number
|
||||
size?: number
|
||||
collection_type?: string
|
||||
season?: string
|
||||
brand_id?: string
|
||||
}): Promise<any[]> {
|
||||
const base = publicBase()
|
||||
if (!base) return []
|
||||
const p = new URLSearchParams({ page: String(opts?.page ?? 1), size: String(opts?.size ?? 30) })
|
||||
if (opts?.collection_type) p.set("collection_type", opts.collection_type)
|
||||
if (opts?.season) p.set("season", opts.season)
|
||||
if (opts?.brand_id) p.set("brand_id", opts.brand_id)
|
||||
const res = await fetch(`${base}/api/public/articles?${p.toString()}`)
|
||||
if (!res.ok) throw new Error(`list ${res.status}`)
|
||||
const json = await res.json()
|
||||
return json?.data ?? []
|
||||
}
|
||||
|
||||
async function request<T>(path: string, params?: URLSearchParams): Promise<T> {
|
||||
const qs = params && params.toString() ? "?" + params.toString() : ""
|
||||
const url = getBase() + "/api" + path + qs
|
||||
|
||||
Reference in New Issue
Block a user