Files
EpicNext-Cms/src/lib/article-draft.ts
T
Simo c389c3893d
CI / check (push) Successful in 52s
CI / deploy (push) Successful in 2m10s
CI / publish-container (push) Failing after 1m18s
feat(cms): improve catalog, editorial recovery and operations
2026-09-09 19:36:15 +02:00

40 lines
914 B
TypeScript

export type ArticleDraft = {
title: string;
slug: string;
image: string;
shortStory: string;
fullStory: string;
status: string;
publishAt: string;
baseToken: string;
};
export function readArticleDraft(form: FormData): ArticleDraft {
const keys = [
"title",
"slug",
"image",
"shortStory",
"fullStory",
"status",
"publishAt",
"baseToken",
] as const;
const result = {} as ArticleDraft;
for (const key of keys) {
const value = form.get(key) ?? "";
if (
typeof value !== "string" ||
value.length > (key === "fullStory" ? 500_000 : 255)
)
throw new Error("draftInvalid");
result[key] = value;
}
if (!["draft", "scheduled", "published"].includes(result.status))
throw new Error("draftInvalid");
return result;
}
export function articleKey(value: string): string {
if (value === "new" || /^[1-9]\d{0,19}$/.test(value)) return value;
throw new Error("draftInvalid");
}