리팩터링
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
import type { Block } from "@/features/editor/state/editorStore";
|
||||
import type { Block, ProjectConfig } from "@/features/editor/state/editorStore";
|
||||
|
||||
interface PublicProjectSnapshot {
|
||||
slug: string;
|
||||
title: string;
|
||||
contentJson: Block[];
|
||||
status: string;
|
||||
blocks: Block[];
|
||||
projectConfig: ProjectConfig | null;
|
||||
}
|
||||
|
||||
function getStore(): Map<string, PublicProjectSnapshot> {
|
||||
@@ -23,3 +25,26 @@ export function getCachedPublicProject(slug: string): PublicProjectSnapshot | nu
|
||||
const store = getStore();
|
||||
return store.get(slug) ?? null;
|
||||
}
|
||||
|
||||
export function parseProjectContentJson(rawContent: any): {
|
||||
blocks: Block[];
|
||||
projectConfig: ProjectConfig | null;
|
||||
} {
|
||||
let blocks: Block[] = [];
|
||||
let projectConfig: ProjectConfig | null = null;
|
||||
|
||||
if (Array.isArray(rawContent)) {
|
||||
blocks = rawContent as Block[];
|
||||
} else if (rawContent && typeof rawContent === "object") {
|
||||
const maybeBlocks = (rawContent as any).blocks;
|
||||
if (Array.isArray(maybeBlocks)) {
|
||||
blocks = maybeBlocks as Block[];
|
||||
const maybeConfig = (rawContent as any).projectConfig;
|
||||
if (maybeConfig && typeof maybeConfig === "object") {
|
||||
projectConfig = maybeConfig as ProjectConfig;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return { blocks, projectConfig };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user