refactor: use yup custom validator

This commit is contained in:
ReaJason
2025-05-28 01:22:54 +08:00
parent e31fcdeca9
commit c75cb2f8ef
8 changed files with 176 additions and 72 deletions
+1 -23
View File
@@ -1,27 +1,5 @@
import { FormSchema } from "@/types/schema.ts";
import { InjectorConfig, ShellConfig, ShellToolConfig, ShellToolType } from "@/types/shell.ts";
import { TFunction } from "i18next";
export function customValidation(t: TFunction<"translation", undefined>, values: FormSchema) {
if (values.shellType.endsWith("Servlet") && (values.urlPattern === "/*" || !values.urlPattern)) {
throw new Error(t("tips.servletUrlPattern"));
}
if (values.shellType.endsWith("ControllerHandler") && (values.urlPattern === "/*" || !values.urlPattern)) {
throw new Error(t("tips.controllerUrlPattern"));
}
if (
(values.shellType === "HandlerMethod" || values.shellType === "HandlerFunction") &&
(values.urlPattern === "/*" || !values.urlPattern)
) {
throw new Error(t("tips.handlerUrlPattern"));
}
if (values.shellTool === ShellToolType.Custom && !values.shellClassBase64) {
throw new Error(t("tips.customShellClass"));
}
}
import { InjectorConfig, ShellConfig, ShellToolConfig } from "@/types/shell.ts";
export function transformToPostData(formValue: FormSchema) {
const shellConfig: ShellConfig = {