refactor: add CID validation

This commit is contained in:
Derrick Hammer 2024-03-22 19:10:20 -04:00
parent b8999efcd7
commit 7ca98d0cfb
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 14 additions and 1 deletions

View File

@ -18,6 +18,7 @@ import { z } from "zod";
import { getFormProps, useForm } from "@conform-to/react";
import { getZodConstraint, parseWithZod } from "@conform-to/zod";
import { usePinning } from "~/hooks/usePinning";
import {CID} from "@lumeweb/libs5";
export default function FileManager() {
return (
@ -85,7 +86,19 @@ export default function FileManager() {
}
const PinFilesSchema = z.object({
cids: z.string().transform((value) => value.split(",")),
cids: z.string().transform((value) => value.split(",")).refine((value) => {
return value.every((cid) => {
try {
CID.decode(cid)
} catch (e) {
return false
}
return true
});
},(val) => ({
message: `${val} is not a valid CID`,
})),
});
const PinFilesForm = () => {