feat: show urlPattern option when needed

This commit is contained in:
ReaJason
2025-05-28 01:22:54 +08:00
parent be3ec77e11
commit f2c4d16278
6 changed files with 30 additions and 43 deletions
+8 -6
View File
@@ -1,3 +1,4 @@
import { shouldHidden } from "@/lib/utils";
import {
AntSwordShellToolConfig,
BehinderShellToolConfig,
@@ -33,11 +34,13 @@ export function BasicInfo({ generateResult }: Readonly<{ generateResult?: Genera
<CopyableField label={t("mainConfig.server")} text={generateResult?.shellConfig.server} />
<CopyableField label={t("mainConfig.shellTool")} text={generateResult?.shellConfig.shellTool} />
<CopyableField label={t("mainConfig.shellMountType")} text={generateResult?.shellConfig.shellType} />
<CopyableField
label={t("mainConfig.urlPattern")}
text={generateResult?.injectorConfig.urlPattern}
value={generateResult?.injectorConfig.urlPattern}
/>
{!shouldHidden(generateResult?.shellConfig?.shellType) && (
<CopyableField
label={t("mainConfig.urlPattern")}
text={generateResult?.injectorConfig.urlPattern}
value={generateResult?.injectorConfig.urlPattern}
/>
)}
</div>
{generateResult?.shellConfig.shellTool !== ShellToolType.Custom && <Separator className="my-2" />}
<div className="grid grid-cols-1 md:grid-cols-2 gap-2">
@@ -72,7 +75,6 @@ export function BasicInfo({ generateResult }: Readonly<{ generateResult?: Genera
text={(generateResult?.shellToolConfig as GodzillaShellToolConfig).key}
value={(generateResult?.shellToolConfig as GodzillaShellToolConfig).key}
/>
<CopyableField label={t("shellToolConfig.godzillaPayload")} text="JavaDynamicPayload" />
<CopyableField label={t("shellToolConfig.godzillaEncryptor")} text="JAVA_AES_BASE64" />
<CopyableField
label={t("shellToolConfig.godzillaHeader")}
@@ -1,21 +0,0 @@
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip.tsx";
import { InfoIcon } from "lucide-react";
import { useTranslation } from "react-i18next";
export function UrlPatternTip() {
const { t } = useTranslation();
return (
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>
<InfoIcon className="cursor-pointer h-4" />
</TooltipTrigger>
<TooltipContent>
<p>{t("tips.servletUrlPattern")}</p>
<p>{t("tips.controllerUrlPattern")}</p>
<p>{t("tips.handlerUrlPattern")}</p>
</TooltipContent>
</Tooltip>
</TooltipProvider>
);
}
@@ -1,24 +1,24 @@
import { UrlPatternTip } from "@/components/tips/url-pattern-tip.tsx";
import { FormField, FormItem, FormLabel } from "@/components/ui/form.tsx";
import { FormField, FormFieldItem, FormFieldLabel, FormMessage } from "@/components/ui/form.tsx";
import { Input } from "@/components/ui/input.tsx";
import { shouldHidden } from "@/lib/utils";
import { FormSchema } from "@/types/schema.ts";
import { FormProvider, UseFormReturn } from "react-hook-form";
import { useTranslation } from "react-i18next";
export function UrlPatternFormField({ form }: Readonly<{ form: UseFormReturn<FormSchema> }>) {
const { t } = useTranslation();
const shellType = form.watch("shellType");
return (
<FormProvider {...form}>
<FormField
control={form.control}
name="urlPattern"
render={({ field }) => (
<FormItem className="gap-1">
<FormLabel className="h-6 flex items-center gap-1">
{t("mainConfig.urlPattern")} <UrlPatternTip />
</FormLabel>
<Input {...field} placeholder={t("placeholders.input")} className="h-8" />
</FormItem>
<FormFieldItem className={shouldHidden(shellType) ? "hidden" : "grid"}>
<FormFieldLabel>{t("mainConfig.urlPattern")}</FormFieldLabel>
<Input {...field} placeholder={t("placeholders.input")} />
<FormMessage />
</FormFieldItem>
)}
/>
</FormProvider>
+14
View File
@@ -47,3 +47,17 @@ export function formatBytes(bytes: number) {
const kbValue = Number.parseFloat((bytes / k ** 1).toFixed(1));
return `${kbValue} ${sizes[1]}`;
}
export function shouldHidden(shellType: string | undefined) {
if (shellType === undefined) {
return false;
}
return (
shellType.endsWith("Listener") ||
shellType.endsWith("Valve") ||
shellType.startsWith("Agent") ||
shellType.endsWith("Interceptor") ||
shellType.endsWith("NettyHandler") ||
shellType.endsWith("WebFilter")
);
}