chore: Ensure comment data is validated before persisting (#6322)
Fix flash on render of comment create
This commit is contained in:
21
server/routes/api/schema.ts
Normal file
21
server/routes/api/schema.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import formidable from "formidable";
|
||||
import { Node } from "prosemirror-model";
|
||||
import { z } from "zod";
|
||||
import { ProsemirrorData as TProsemirrorData } from "@shared/types";
|
||||
import { schema } from "@server/editor";
|
||||
|
||||
export const BaseSchema = z.object({
|
||||
body: z.unknown(),
|
||||
query: z.unknown(),
|
||||
file: z.custom<formidable.File>().optional(),
|
||||
});
|
||||
|
||||
export const ProsemirrorSchema = z.custom<TProsemirrorData>((val) => {
|
||||
try {
|
||||
const node = Node.fromJSON(schema, val);
|
||||
node.check();
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}, "not valid data");
|
||||
Reference in New Issue
Block a user