25 lines
2.2 KiB
TypeScript
25 lines
2.2 KiB
TypeScript
export const sections = [
|
|
{ path: "images", kind: "image", name: "图片素材", hint: "照片、插画与可以反复使用的画面" },
|
|
{ path: "videos", kind: "video", name: "视频素材", hint: "片段与镜头,声音随画面一起收好" },
|
|
{ path: "audio", kind: "audio", name: "声音素材", hint: "音乐、环境声与声音片段" },
|
|
{ path: "articles", kind: "article", name: "图文作品", hint: "用网页编写,慢慢打磨每一页" },
|
|
{ path: "motion", kind: "motion", name: "动态作品", hint: "让网页本身成为时间里的画面" },
|
|
] as const;
|
|
export type PostKind = typeof sections[number]["kind"];
|
|
export type Asset = { id: string; kind: "image" | "video" | "audio" | "text"; filename: string | null; body: string | null; width: number | null; height: number | null; duration: number | null; has_audio: boolean | null; processing_status: string; variants: string[]; role: string; source_asset_id: string | null; derivation: string | null };
|
|
export type Tag = { id: string; name: string; slug: string; path: string;kind?:'normal'|'system';system_key?:string|null };
|
|
export type Post = { archived?:boolean;archived_at?:string|null; description: string; id: string; public_id?: string | null; slug: string; kind: PostKind; title: string; created_at: string; updated_at: string; cover_asset_id: string | null; assets: Asset[]; tags: Tag[] };
|
|
export type FeedData = { posts: Post[]; tags: Tag[]; contributions: { day: string; total: number }[]; nextCursor: string | null; unavailable?: boolean };
|
|
export function validSection(path: string) { return sections.find(s => s.path === path); }
|
|
export const mediaUrl = (id: string, variant?: string) => `/api/media/${id}${variant ? `?variant=${variant}` : ""}`;
|
|
export function encodeCursor(date: string, id: string) { return Buffer.from(JSON.stringify([date,id])).toString("base64url"); }
|
|
export function decodeCursor(value?: string) {
|
|
if (!value) return null;
|
|
try { const [date,id] = JSON.parse(Buffer.from(value,"base64url").toString());
|
|
if (!Number.isNaN(Date.parse(date)) && /^[0-9a-f-]{36}$/.test(id)) return [date,id];
|
|
} catch { /* invalid pagination cursor */ }
|
|
throw new Error("Invalid cursor");
|
|
}
|
|
|
|
export const publicPostId=(post:Pick<Post,'id'|'public_id'>)=>post.public_id||post.id;
|