This commit is contained in:
toom1996
2026-09-14 21:30:15 +08:00
parent 548155625d
commit afff2d9a49
52 changed files with 2997 additions and 2753 deletions

56
src/lib/ssg.ts Normal file
View File

@ -0,0 +1,56 @@
// src/lib/ssg.ts — SSG 构建专用接口层(仅 Node 构建期)
//
// 本文件只装「构建期 SSG 取数」:所有函数调用 /api/internal/ssg/* 内部端口
// (仅 127.0.0.1,nginx 不反代,由 astro build 时的 Node 进程调用),
// 走 request.ts 的 requestSsg()(自动带 SSG_TOKEN + ?locale=)。
//
// 与 api.ts 的「浏览器运行期公开业务 + 鉴权 + 收藏 + 历史」隔离,
// 避免「仅构建期才有意义」的代码混进客户端逻辑(这些函数从不进客户端 bundle)。
import { requestSsg } from "./request"
import { endpoints } from "./endpoints"
import type { BrandEntry, StreetSnapItem } from "./api"
// 后端热门品牌项(与 SSG popular brand 对齐)。
export interface SsgPopularBrand {
id: string
article_id: string
brand: string
cover: string
title: string
}
// 接口:GET /api/internal/ssg/home/runway(SSG 内部端口,构建期 Node 调用)
// 首页 runway 区块数据,含多个模块;hotBrand 为其中之一(当前仅此模块)。
export async function getSsgIndexRunway(): Promise<{ hotBrand: SsgPopularBrand[] }> {
const j = await requestSsg<{ data?: { hotBrand?: SsgPopularBrand[] } }>(endpoints.ssg.homeRunway)
return { hotBrand: j?.data?.hotBrand ?? [] }
}
// 接口:GET /api/internal/ssg/brands/popular(SSG 内部端口,构建期 Node 调用)
// 走秀页热门品牌(按图片总数排名,结果按热度顺序)。后端固定返回前 30 个。
export async function getSsgHotBrands(): Promise<BrandEntry[]> {
const j = await requestSsg<{ data?: any[] }>(endpoints.ssg.hotBrands)
return (j?.data ?? []).map((b: any) => {
const nameEn = (b.name_en || b.name || "").toString()
return {
id: String(b.id),
name: nameEn,
nameCn: (b.name_cn || "").toString(),
display: nameEn,
}
})
}
// 接口:GET /api/internal/ssg/street-snaps/popular(SSG 内部端口,构建期 Node 调用)
// 首页「Street Style」热门街拍(按图片数前 N,返回完整对象含封面)。
export async function getSsgStreetSnapPopular(limit = 12): Promise<StreetSnapItem[]> {
const j = await requestSsg<{ data?: any[] }>(`${endpoints.ssg.streetSnapPopular}?limit=${limit}`)
return (j?.data ?? []).map((b: any) => ({
id: String(b.id),
title: b.title ?? "",
cover: b.cover ?? "",
image_count: Number(b.image_count ?? 0),
images: [],
}))
}