Files
geo/apps/admin-web/src/lib/cover-requirements.ts
T
root 4c4795e029 feat(publish/dongchedi): publish via page context with cover and conservative HTML
懂车帝发布闸现走 Playwright/WebContents 内的 fetch,附带 CSRF token、自动
draft+commit 两步保存,并在前置流程中把正文 HTML 收敛到 p/strong/img、表格
降级为段落、过滤本地素材 URL。同步把懂车帝纳入封面强制平台,更新中英文
提示与错误码文案。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-28 18:35:36 +08:00

94 lines
2.7 KiB
TypeScript

import { normalizePublishPlatformIds } from "./publish-platforms";
export type CoverSupportMode = "native" | "unsupported";
export interface PlatformCoverRequirement {
platformId: string;
required: boolean;
supportMode: CoverSupportMode;
aspectRatio: number | null;
aspectLabel: string | null;
outputWidth: number | null;
outputHeight: number | null;
priority: number;
}
const defaultRequirement = {
required: false,
supportMode: "unsupported" as CoverSupportMode,
aspectRatio: null,
aspectLabel: null,
outputWidth: null,
outputHeight: null,
priority: 0,
};
const requirementCatalog: Record<string, Partial<PlatformCoverRequirement>> = {
baijiahao: {
required: true,
supportMode: "native",
aspectRatio: 3 / 2,
aspectLabel: "3:2",
outputWidth: 1200,
outputHeight: 800,
priority: 100,
},
dongchedi: {
required: true,
supportMode: "native",
aspectRatio: 4 / 3,
aspectLabel: "4:3",
outputWidth: 1200,
outputHeight: 900,
priority: 90,
},
};
export function getPlatformCoverRequirements(platformIds?: Array<string | null | undefined>): PlatformCoverRequirement[] {
return normalizePublishPlatformIds(platformIds).map((platformId) => {
const config = requirementCatalog[platformId] ?? {};
return {
platformId,
required: config.required ?? defaultRequirement.required,
supportMode: config.supportMode ?? defaultRequirement.supportMode,
aspectRatio: config.aspectRatio ?? defaultRequirement.aspectRatio,
aspectLabel: config.aspectLabel ?? defaultRequirement.aspectLabel,
outputWidth: config.outputWidth ?? defaultRequirement.outputWidth,
outputHeight: config.outputHeight ?? defaultRequirement.outputHeight,
priority: config.priority ?? defaultRequirement.priority,
};
});
}
export function coverUploadRequired(platformIds?: Array<string | null | undefined>): boolean {
return getPlatformCoverRequirements(platformIds).some((item) => item.required);
}
export function getPrimaryCoverRequirement(platformIds?: Array<string | null | undefined>): PlatformCoverRequirement {
const requirements = getPlatformCoverRequirements(platformIds);
if (!requirements.length) {
return {
platformId: "default",
...defaultRequirement,
};
}
return [...requirements].sort((left, right) => right.priority - left.priority)[0];
}
export function deriveCoverFileName(value?: string | null): string {
const trimmed = String(value ?? "").trim();
if (!trimmed) {
return "";
}
try {
const pathname = new URL(trimmed, "https://cover.local").pathname;
const lastSegment = pathname.split("/").filter(Boolean).at(-1) ?? "";
return decodeURIComponent(lastSegment);
} catch {
return "";
}
}