mirror of
https://github.com/clash-verge-rev/clash-verge-rev
synced 2025-05-05 08:53:44 +08:00
feat: check bypass format
This commit is contained in:
parent
183f0f6c42
commit
1f197965e0
@ -1,7 +1,7 @@
|
|||||||
import { forwardRef, useImperativeHandle, useState } from "react";
|
import { forwardRef, useImperativeHandle, useState } from "react";
|
||||||
import { useLockFn } from "ahooks";
|
import { useLockFn } from "ahooks";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { IconButton, Tooltip } from "@mui/material";
|
import { Box, IconButton, Tooltip } from "@mui/material";
|
||||||
import { InfoRounded } from "@mui/icons-material";
|
import { InfoRounded } from "@mui/icons-material";
|
||||||
import {
|
import {
|
||||||
InputAdornment,
|
InputAdornment,
|
||||||
@ -19,12 +19,21 @@ import { BaseDialog, DialogRef, Notice, Switch } from "@/components/base";
|
|||||||
import { Edit } from "@mui/icons-material";
|
import { Edit } from "@mui/icons-material";
|
||||||
import { EditorViewer } from "@/components/profile/editor-viewer";
|
import { EditorViewer } from "@/components/profile/editor-viewer";
|
||||||
import { BaseFieldset } from "@/components/base/base-fieldset";
|
import { BaseFieldset } from "@/components/base/base-fieldset";
|
||||||
|
import getSystem from "@/utils/get-system";
|
||||||
const DEFAULT_PAC = `function FindProxyForURL(url, host) {
|
const DEFAULT_PAC = `function FindProxyForURL(url, host) {
|
||||||
return "PROXY 127.0.0.1:%mixed-port%; SOCKS5 127.0.0.1:%mixed-port%; DIRECT;";
|
return "PROXY 127.0.0.1:%mixed-port%; SOCKS5 127.0.0.1:%mixed-port%; DIRECT;";
|
||||||
}`;
|
}`;
|
||||||
|
|
||||||
export const SysproxyViewer = forwardRef<DialogRef>((props, ref) => {
|
export const SysproxyViewer = forwardRef<DialogRef>((props, ref) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
let validReg;
|
||||||
|
if (getSystem() === "windows") {
|
||||||
|
validReg =
|
||||||
|
/^(\*?\w+(\.\w+)*|\d{1,3}(\.\d{1,3}){0,2}\.\*|\d{1,3}(\.\d{1,3}){3})(;(\*?\w+(\.\w+)*|\d{1,3}(\.\d{1,3}){0,2}\.\*|\d{1,3}(\.\d{1,3}){3}))*$/;
|
||||||
|
} else {
|
||||||
|
validReg =
|
||||||
|
/^((\*\.)?([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}|(\d{1,3}\.){3}\d{1,3}(\/\d{1,2})?|([a-fA-F0-9:]+:+)+[a-fA-F0-9]+(\/\d{1,3})?)(,((\*\.)?([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}|(\d{1,3}\.){3}\d{1,3}(\/\d{1,2})?|([a-fA-F0-9:]+:+)+[a-fA-F0-9]+(\/\d{1,3})?))*$/;
|
||||||
|
}
|
||||||
|
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
const [editorOpen, setEditorOpen] = useState(false);
|
const [editorOpen, setEditorOpen] = useState(false);
|
||||||
@ -92,7 +101,10 @@ export const SysproxyViewer = forwardRef<DialogRef>((props, ref) => {
|
|||||||
if (value.pac_content !== pac_file_content) {
|
if (value.pac_content !== pac_file_content) {
|
||||||
patch.pac_file_content = value.pac_content;
|
patch.pac_file_content = value.pac_content;
|
||||||
}
|
}
|
||||||
|
if (value.bypass && !validReg.test(value.bypass)) {
|
||||||
|
Notice.error(t("Invalid Bypass Format"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
await patchVerge(patch);
|
await patchVerge(patch);
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
@ -136,6 +148,12 @@ export const SysproxyViewer = forwardRef<DialogRef>((props, ref) => {
|
|||||||
</FlexBox>
|
</FlexBox>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
{value.pac && (
|
||||||
|
<FlexBox>
|
||||||
|
<Typography className="label">{t("PAC URL")}</Typography>
|
||||||
|
<Typography className="value">{autoproxy?.url || "-"}</Typography>
|
||||||
|
</FlexBox>
|
||||||
|
)}
|
||||||
</BaseFieldset>
|
</BaseFieldset>
|
||||||
<ListItem sx={{ padding: "5px 2px" }}>
|
<ListItem sx={{ padding: "5px 2px" }}>
|
||||||
<ListItemText primary={t("Use PAC Mode")} />
|
<ListItemText primary={t("Use PAC Mode")} />
|
||||||
@ -183,30 +201,23 @@ export const SysproxyViewer = forwardRef<DialogRef>((props, ref) => {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</ListItem>
|
</ListItem>
|
||||||
|
|
||||||
{!value.pac && (
|
{!value.pac && (
|
||||||
<>
|
<>
|
||||||
<FlexBox>
|
<ListItemText primary={t("Proxy Bypass")} />
|
||||||
<Typography className="label">{t("Proxy Bypass")}</Typography>
|
<TextField
|
||||||
</FlexBox>
|
error={value.bypass ? !validReg.test(value.bypass) : false}
|
||||||
<FlexBox>
|
disabled={!enabled}
|
||||||
<TextField
|
size="small"
|
||||||
disabled={!enabled}
|
autoComplete="off"
|
||||||
size="small"
|
multiline
|
||||||
autoComplete="off"
|
rows={4}
|
||||||
multiline
|
sx={{ width: "100%" }}
|
||||||
rows={4}
|
value={value.bypass}
|
||||||
sx={{ width: "100%" }}
|
onChange={(e) => {
|
||||||
value={value.bypass}
|
setValue((v) => ({ ...v, bypass: e.target.value }));
|
||||||
placeholder={sysproxy?.bypass || `-`}
|
}}
|
||||||
onChange={(e) =>
|
/>
|
||||||
setValue((v) => ({ ...v, bypass: e.target.value }))
|
<ListItemText primary={t("Bypass")} />
|
||||||
}
|
|
||||||
/>
|
|
||||||
</FlexBox>
|
|
||||||
<FlexBox>
|
|
||||||
<Typography className="label">{t("Bypass")}</Typography>
|
|
||||||
</FlexBox>
|
|
||||||
<FlexBox>
|
<FlexBox>
|
||||||
<TextField
|
<TextField
|
||||||
disabled={true}
|
disabled={true}
|
||||||
@ -220,7 +231,6 @@ export const SysproxyViewer = forwardRef<DialogRef>((props, ref) => {
|
|||||||
</FlexBox>
|
</FlexBox>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{value.pac && (
|
{value.pac && (
|
||||||
<>
|
<>
|
||||||
<ListItem sx={{ padding: "5px 2px", alignItems: "start" }}>
|
<ListItem sx={{ padding: "5px 2px", alignItems: "start" }}>
|
||||||
@ -257,13 +267,6 @@ export const SysproxyViewer = forwardRef<DialogRef>((props, ref) => {
|
|||||||
</ListItem>
|
</ListItem>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{value.pac && (
|
|
||||||
<FlexBox>
|
|
||||||
<Typography className="label">{t("PAC URL")}</Typography>
|
|
||||||
<Typography className="value">{autoproxy?.url || "-"}</Typography>
|
|
||||||
</FlexBox>
|
|
||||||
)}
|
|
||||||
</List>
|
</List>
|
||||||
</BaseDialog>
|
</BaseDialog>
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user