mirror of
https://github.com/ReaJason/MemShellParty.git
synced 2026-09-21 22:50:42 +08:00
style: fmt code
This commit is contained in:
@@ -1,12 +1,6 @@
|
||||
export type ProbeMethod = "ResponseBody" | "DNSLog" | "Sleep";
|
||||
|
||||
export type ProbeContent =
|
||||
| "BasicInfo"
|
||||
| "Server"
|
||||
| "OS"
|
||||
| "JDK"
|
||||
| "Bytecode"
|
||||
| "Command";
|
||||
export type ProbeContent = "BasicInfo" | "Server" | "OS" | "JDK" | "Bytecode" | "Command";
|
||||
|
||||
export interface ProbeConfig {
|
||||
probeMethod: string;
|
||||
|
||||
+25
-48
@@ -1,7 +1,9 @@
|
||||
import type { TFunction } from "i18next";
|
||||
import { useCallback } from "react";
|
||||
import type { FieldErrors, ResolverResult } from "react-hook-form";
|
||||
|
||||
import { useCallback } from "react";
|
||||
import * as yup from "yup";
|
||||
|
||||
import { ShellToolType } from "./memshell";
|
||||
|
||||
export const memShellFormSchema = yup.object({
|
||||
@@ -49,20 +51,11 @@ const urlPatternIsNeeded = (shellType: string) => {
|
||||
};
|
||||
|
||||
const isInvalidUrl = (urlPattern: string | undefined) =>
|
||||
urlPattern === "/" ||
|
||||
urlPattern === "/*" ||
|
||||
!urlPattern?.startsWith("/") ||
|
||||
!urlPattern;
|
||||
urlPattern === "/" || urlPattern === "/*" || !urlPattern?.startsWith("/") || !urlPattern;
|
||||
|
||||
export const useYupValidationResolver = (
|
||||
validationSchema: yup.ObjectSchema<any>,
|
||||
t: TFunction,
|
||||
) =>
|
||||
export const useYupValidationResolver = (validationSchema: yup.ObjectSchema<any>, t: TFunction) =>
|
||||
useCallback(
|
||||
async (
|
||||
data: MemShellFormSchema,
|
||||
_context: any,
|
||||
): Promise<ValidationResult> => {
|
||||
async (data: MemShellFormSchema, _context: any): Promise<ValidationResult> => {
|
||||
try {
|
||||
const values = (await validationSchema.validate(data, {
|
||||
abortEarly: false,
|
||||
@@ -73,19 +66,13 @@ export const useYupValidationResolver = (
|
||||
const serverVersion: keyof MemShellFormSchema = "serverVersion";
|
||||
const errors = {} as any;
|
||||
|
||||
if (
|
||||
urlPatternIsNeeded(values?.shellType) &&
|
||||
isInvalidUrl(values?.urlPattern)
|
||||
) {
|
||||
if (urlPatternIsNeeded(values?.shellType) && isInvalidUrl(values?.urlPattern)) {
|
||||
errors[urlPattern] = {
|
||||
type: "custom",
|
||||
message: t("memshell:tips.specificUrlPattern"),
|
||||
};
|
||||
}
|
||||
if (
|
||||
values.shellTool === ShellToolType.Custom &&
|
||||
!values.shellClassBase64
|
||||
) {
|
||||
if (values.shellTool === ShellToolType.Custom && !values.shellClassBase64) {
|
||||
errors[shellClassBase64] = {
|
||||
type: "custom",
|
||||
message: t("memshell:tips.customShellClass"),
|
||||
@@ -104,8 +91,7 @@ export const useYupValidationResolver = (
|
||||
|
||||
if (
|
||||
values.server === "Jetty" &&
|
||||
(values.shellType === "Handler" ||
|
||||
values.shellType === "JakartaHandler") &&
|
||||
(values.shellType === "Handler" || values.shellType === "JakartaHandler") &&
|
||||
values.serverVersion === "Unknown"
|
||||
) {
|
||||
errors[serverVersion] = {
|
||||
@@ -122,16 +108,13 @@ export const useYupValidationResolver = (
|
||||
if (errors instanceof yup.ValidationError) {
|
||||
return {
|
||||
values: {},
|
||||
errors: errors.inner.reduce(
|
||||
(allErrors, currentError) => {
|
||||
allErrors[currentError.path as keyof MemShellFormSchema] = {
|
||||
type: currentError.type ?? "validation",
|
||||
message: currentError.message,
|
||||
};
|
||||
return allErrors;
|
||||
},
|
||||
{} as FieldErrors<MemShellFormSchema>,
|
||||
),
|
||||
errors: errors.inner.reduce((allErrors, currentError) => {
|
||||
allErrors[currentError.path as keyof MemShellFormSchema] = {
|
||||
type: currentError.type ?? "validation",
|
||||
message: currentError.message,
|
||||
};
|
||||
return allErrors;
|
||||
}, {} as FieldErrors<MemShellFormSchema>),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -179,10 +162,7 @@ export const useYupValidationProbeResolver = (
|
||||
t: TFunction,
|
||||
) =>
|
||||
useCallback(
|
||||
async (
|
||||
data: ProbeShellFormSchema,
|
||||
_context: any,
|
||||
): Promise<ProbeValidationResult> => {
|
||||
async (data: ProbeShellFormSchema, _context: any): Promise<ProbeValidationResult> => {
|
||||
try {
|
||||
const values = (await validationSchema.validate(data, {
|
||||
abortEarly: false,
|
||||
@@ -205,17 +185,14 @@ export const useYupValidationProbeResolver = (
|
||||
if (errors instanceof yup.ValidationError) {
|
||||
return {
|
||||
values: {},
|
||||
errors: errors.inner.reduce(
|
||||
(allErrors, currentError) => {
|
||||
allErrors[currentError.path as keyof ProbeShellFormSchema] = {
|
||||
type: currentError.type ?? "validation",
|
||||
message: currentError.message,
|
||||
};
|
||||
console.log(allErrors);
|
||||
return allErrors;
|
||||
},
|
||||
{} as FieldErrors<ProbeShellFormSchema>,
|
||||
),
|
||||
errors: errors.inner.reduce((allErrors, currentError) => {
|
||||
allErrors[currentError.path as keyof ProbeShellFormSchema] = {
|
||||
type: currentError.type ?? "validation",
|
||||
message: currentError.message,
|
||||
};
|
||||
console.log(allErrors);
|
||||
return allErrors;
|
||||
}, {} as FieldErrors<ProbeShellFormSchema>),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user