feat(cms): improve catalog, editorial recovery and operations
This commit is contained in:
1 parent
2fead134e6
commit
c389c3893d
122 files changed
+8137
-703
No files matched your search
@@ -0,0 +1,39 @@
|
||||
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");
|
||||
}
|
||||
Reference in new issue
Block a user