diff --git a/src/component/Admin/Node/Guide/Aria2RPC.js b/src/component/Admin/Node/Guide/Aria2RPC.js new file mode 100644 index 0000000..e4964e7 --- /dev/null +++ b/src/component/Admin/Node/Guide/Aria2RPC.js @@ -0,0 +1,429 @@ +import { lighten, makeStyles } from "@material-ui/core/styles"; +import React, { useCallback, useState } from "react"; +import Typography from "@material-ui/core/Typography"; +import { useDispatch } from "react-redux"; +import { toggleSnackbar } from "../../../../actions"; +import Link from "@material-ui/core/Link"; +import FormControl from "@material-ui/core/FormControl"; +import InputLabel from "@material-ui/core/InputLabel"; +import Input from "@material-ui/core/Input"; +import RadioGroup from "@material-ui/core/RadioGroup"; +import FormControlLabel from "@material-ui/core/FormControlLabel"; +import Radio from "@material-ui/core/Radio"; +import Collapse from "@material-ui/core/Collapse"; +import Button from "@material-ui/core/Button"; +import Alert from "@material-ui/lab/Alert"; +import Box from "@material-ui/core/Box"; +import FormHelperText from "@material-ui/core/FormHelperText"; +import API from "../../../../middleware/Api"; + +const useStyles = makeStyles((theme) => ({ + stepContent: { + padding: "16px 32px 16px 32px", + }, + form: { + maxWidth: 400, + marginTop: 20, + }, + formContainer: { + [theme.breakpoints.up("md")]: { + padding: "0px 24px 0 24px", + }, + }, + subStepContainer: { + display: "flex", + marginBottom: 20, + padding: 10, + transition: theme.transitions.create("background-color", { + easing: theme.transitions.easing.sharp, + duration: theme.transitions.duration.leavingScreen, + }), + "&:focus-within": { + backgroundColor: theme.palette.background.default, + }, + }, + stepNumber: { + width: 20, + height: 20, + backgroundColor: lighten(theme.palette.secondary.light, 0.2), + color: theme.palette.secondary.contrastText, + textAlign: "center", + borderRadius: " 50%", + }, + stepNumberContainer: { + marginRight: 10, + }, + stepFooter: { + marginTop: 32, + }, + button: { + marginRight: theme.spacing(1), + }, + viewButtonLabel: { textTransform: "none" }, + "@global": { + code: { + color: "rgba(0, 0, 0, 0.87)", + display: "inline-block", + padding: "2px 6px", + fontFamily: + ' Consolas, "Liberation Mono", Menlo, Courier, monospace', + borderRadius: "2px", + backgroundColor: "rgba(255,229,100,0.1)", + }, + pre: { + margin: "24px 0", + padding: "12px 18px", + overflow: "auto", + direction: "ltr", + borderRadius: "4px", + backgroundColor: "#272c34", + color: "#fff", + fontFamily: + ' Consolas, "Liberation Mono", Menlo, Courier, monospace', + }, + }, +})); + +export default function Aria2RPC(props) { + const classes = useStyles(); + const dispatch = useDispatch(); + const [loading, setLoading] = useState(false); + const ToggleSnackbar = useCallback( + (vertical, horizontal, msg, color) => + dispatch(toggleSnackbar(vertical, horizontal, msg, color)), + [dispatch] + ); + + const testAria2 = () => { + setLoading(true); + API.post("/admin/node/aria2/test", { + type: props.node.Type, + server: props.node.Server, + secret: props.node.SlaveKey, + rpc: props.node.Aria2Options.Server, + token: props.node.Aria2Options.Token, + }) + .then((response) => { + ToggleSnackbar( + "top", + "right", + "连接成功,Aria2 版本为:" + response.data, + "success" + ); + }) + .catch((error) => { + ToggleSnackbar("top", "right", error.message, "error"); + }) + .then(() => { + setLoading(false); + }); + }; + + const mode = props.node.Type === 0 ? "从机" : "主机"; + + return ( +
+ ); +} diff --git a/src/component/Admin/Node/Guide/Communication.js b/src/component/Admin/Node/Guide/Communication.js index 5698499..d813378 100644 --- a/src/component/Admin/Node/Guide/Communication.js +++ b/src/component/Admin/Node/Guide/Communication.js @@ -1,29 +1,15 @@ import { lighten, makeStyles } from "@material-ui/core/styles"; import React, { useCallback, useState } from "react"; -import Stepper from "@material-ui/core/Stepper"; -import StepLabel from "@material-ui/core/StepLabel"; -import Step from "@material-ui/core/Step"; import Typography from "@material-ui/core/Typography"; import { useDispatch } from "react-redux"; import { toggleSnackbar } from "../../../../actions"; -import Link from "@material-ui/core/Link"; import FormControl from "@material-ui/core/FormControl"; import InputLabel from "@material-ui/core/InputLabel"; import Input from "@material-ui/core/Input"; -import RadioGroup from "@material-ui/core/RadioGroup"; -import FormControlLabel from "@material-ui/core/FormControlLabel"; -import Radio from "@material-ui/core/Radio"; -import Collapse from "@material-ui/core/Collapse"; import Button from "@material-ui/core/Button"; import API from "../../../../middleware/Api"; -import MagicVar from "../../Dialogs/MagicVar"; -import DomainInput from "../../Common/DomainInput"; -import SizeInput from "../../Common/SizeInput"; -import { useHistory } from "react-router"; -import { getNumber, randomStr } from "../../../../utils"; -import Select from "@material-ui/core/Select"; -import MenuItem from "@material-ui/core/MenuItem"; import Alert from "@material-ui/lab/Alert"; +import Box from "@material-ui/core/Box"; const useStyles = makeStyles((theme) => ({ stepContent: { @@ -78,40 +64,49 @@ const useStyles = makeStyles((theme) => ({ borderRadius: "2px", backgroundColor: "rgba(255,229,100,0.1)", }, + pre: { + margin: "24px 0", + padding: "12px 18px", + overflow: "auto", + direction: "ltr", + borderRadius: "4px", + backgroundColor: "#272c34", + color: "#fff", + fontFamily: + ' Consolas, "Liberation Mono", Menlo, Courier, monospace', + }, }, })); export default function Communication(props) { const classes = useStyles(); - const history = useHistory(); - - const [activeStep, setActiveStep] = useState(0); - const [skipped, setSkipped] = React.useState(new Set()); - const [node, setNode] = useState( - props.node - ? props.node - : { - Status: 1, - Type: 0, - Aria2Enabled: false, - Server: "https://example.com:5212", - SlaveKey: randomStr(64), - MasterKey: randomStr(64), - Aria2Options: {}, - } - ); - - const isStepSkipped = (step) => { - return skipped.has(step); - }; - const dispatch = useDispatch(); + const [loading, setLoading] = useState(false); const ToggleSnackbar = useCallback( (vertical, horizontal, msg, color) => dispatch(toggleSnackbar(vertical, horizontal, msg, color)), [dispatch] ); + const testSlave = () => { + setLoading(true); + + // 测试路径是否可用 + API.post("/admin/policy/test/slave", { + server: props.node.Server, + secret: props.node.SlaveKey, + }) + .then(() => { + ToggleSnackbar("top", "right", "通信正常", "success"); + }) + .catch((error) => { + ToggleSnackbar("top", "right", error.message, "error"); + }) + .then(() => { + setLoading(false); + }); + }; + return (