feat: add new settings form in dashboard

This commit is contained in:
HFO4 2022-04-19 16:14:53 +08:00
parent 2c09425869
commit 2da499799d
4 changed files with 288 additions and 53 deletions

View File

@ -182,7 +182,12 @@ export default function Index() {
setNewsUsers(res);
})
.catch((error) => {
ToggleSnackbar("top", "right", error.message, "error");
ToggleSnackbar(
"top",
"right",
"Cloudreve 公告加载失败",
"warning"
);
});
}, []);

View File

@ -12,6 +12,8 @@ import MenuItem from "@material-ui/core/MenuItem";
import Input from "@material-ui/core/Input";
import Link from "@material-ui/core/Link";
import { toggleSnackbar } from "../../../redux/explorer";
import FormControlLabel from "@material-ui/core/FormControlLabel";
import Switch from "@material-ui/core/Switch";
const useStyles = makeStyles((theme) => ({
root: {
@ -40,7 +42,14 @@ export default function Captcha() {
captcha_height: "1",
captcha_width: "1",
captcha_mode: "3",
captcha_CaptchaLen: "",
captcha_CaptchaLen: "6",
captcha_ComplexOfNoiseText: "0",
captcha_ComplexOfNoiseDot: "0",
captcha_IsShowHollowLine: "0",
captcha_IsShowNoiseDot: "0",
captcha_IsShowNoiseText: "0",
captcha_IsShowSlimeLine: "0",
captcha_IsShowSineLine: "0",
captcha_ReCaptchaKey: "",
captcha_ReCaptchaSecret: "",
captcha_TCaptcha_CaptchaAppId: "",
@ -100,6 +109,14 @@ export default function Captcha() {
});
};
const handleCheckChange = (name) => (event) => {
const value = event.target.checked ? "1" : "0";
setOptions({
...options,
[name]: value,
});
};
return (
<div>
<form onSubmit={submit}>
@ -178,6 +195,25 @@ export default function Captcha() {
</FormControl>
</div>
<div className={classes.form}>
<FormControl>
<InputLabel htmlFor="component-helper">
长度
</InputLabel>
<Input
type={"number"}
inputProps={{
min: 1,
step: 1,
}}
value={options.captcha_CaptchaLen}
onChange={handleChange(
"captcha_CaptchaLen"
)}
required
/>
</FormControl>
</div>
<div className={classes.form}>
<FormControl>
<InputLabel htmlFor="component-helper">
@ -200,6 +236,55 @@ export default function Captcha() {
</FormHelperText>
</FormControl>
</div>
{[
{
name: "加强干扰文字",
field: "captcha_ComplexOfNoiseText",
},
{
name: "加强干扰点",
field: "captcha_ComplexOfNoiseDot",
},
{
name: "使用空心线",
field: "captcha_IsShowHollowLine",
},
{
name: "使用噪点",
field: "captcha_IsShowNoiseDot",
},
{
name: "使用干扰文字",
field: "captcha_IsShowNoiseText",
},
{
name: "使用波浪线",
field: "captcha_IsShowSlimeLine",
},
{
name: "使用正弦线",
field: "captcha_IsShowSineLine",
},
].map((input) => (
<div key={input.name} className={classes.form}>
<FormControl fullWidth>
<FormControlLabel
control={
<Switch
checked={
options[input.field] ===
"1"
}
onChange={handleCheckChange(
input.field
)}
/>
}
label={input.name}
/>
</FormControl>
</div>
))}
</div>
</div>
)}

View File

@ -10,6 +10,9 @@ import { useDispatch } from "react-redux";
import { toggleSnackbar } from "../../../redux/explorer";
import API from "../../../middleware/Api";
import SizeInput from "../Common/SizeInput";
import Alert from "@material-ui/lab/Alert";
import FormControlLabel from "@material-ui/core/FormControlLabel";
import Switch from "@material-ui/core/Switch";
const useStyles = makeStyles((theme) => ({
root: {
@ -43,6 +46,11 @@ export default function ImageSetting() {
thumb_width: "",
thumb_height: "",
office_preview_service: "",
thumb_file_suffix: "",
thumb_max_task_count: "",
thumb_encode_method: "",
thumb_gc_after_gen: "0",
thumb_encode_quality: "",
});
const handleChange = (name) => (event) => {
@ -96,6 +104,14 @@ export default function ImageSetting() {
});
};
const handleCheckChange = (name) => (event) => {
const value = event.target.checked ? "1" : "0";
setOptions({
...options,
[name]: value,
});
};
return (
<div>
<form onSubmit={submit}>
@ -215,43 +231,6 @@ export default function ImageSetting() {
</Typography>
<div className={classes.formContainer}>
<div className={classes.form}>
<FormControl>
<InputLabel htmlFor="component-helper">
缩略图宽度
</InputLabel>
<Input
type={"number"}
inputProps={{
min: 1,
step: 1,
}}
value={options.thumb_width}
onChange={handleChange("thumb_width")}
required
/>
</FormControl>
</div>
</div>
<div className={classes.formContainer}>
<div className={classes.form}>
<FormControl>
<InputLabel htmlFor="component-helper">
缩略图高度
</InputLabel>
<Input
type={"number"}
inputProps={{
min: 1,
step: 1,
}}
value={options.thumb_height}
onChange={handleChange("thumb_height")}
required
/>
</FormControl>
</div>
<div className={classes.form}>
<FormControl>
<InputLabel htmlFor="component-helper">
@ -277,6 +256,155 @@ export default function ImageSetting() {
</div>
</div>
<div className={classes.root}>
<Typography variant="h6" gutterBottom>
缩略图
</Typography>
<div className={classes.formContainer}>
<div className={classes.form}>
<Alert severity="info">
以下设置只针对本机存储策略有效
</Alert>
</div>
<div className={classes.form}>
<FormControl>
<InputLabel htmlFor="component-helper">
缩略图宽度
</InputLabel>
<Input
type={"number"}
inputProps={{
min: 1,
step: 1,
}}
value={options.thumb_width}
onChange={handleChange("thumb_width")}
required
/>
</FormControl>
</div>
<div className={classes.form}>
<FormControl>
<InputLabel htmlFor="component-helper">
缩略图高度
</InputLabel>
<Input
type={"number"}
inputProps={{
min: 1,
step: 1,
}}
value={options.thumb_height}
onChange={handleChange("thumb_height")}
required
/>
</FormControl>
</div>
<div className={classes.form}>
<FormControl>
<InputLabel htmlFor="component-helper">
缩略图文件后缀
</InputLabel>
<Input
type={"text"}
value={options.thumb_file_suffix}
onChange={handleChange("thumb_file_suffix")}
required
/>
</FormControl>
</div>
<div className={classes.form}>
<FormControl>
<InputLabel htmlFor="component-helper">
缩略图生成并行数量
</InputLabel>
<Input
type={"number"}
inputProps={{
min: -1,
step: 1,
}}
value={options.thumb_max_task_count}
onChange={handleChange(
"thumb_max_task_count"
)}
required
/>
<FormHelperText id="component-helper-text">
-1 表示不限制
</FormHelperText>
</FormControl>
</div>
<div className={classes.form}>
<FormControl>
<InputLabel htmlFor="component-helper">
缩略图格式
</InputLabel>
<Input
type={"test"}
value={options.thumb_encode_method}
onChange={handleChange(
"thumb_encode_method"
)}
required
/>
<FormHelperText id="component-helper-text">
可选png/jpg
</FormHelperText>
</FormControl>
</div>
<div className={classes.form}>
<FormControl>
<InputLabel htmlFor="component-helper">
缩略图生成并行数量
</InputLabel>
<Input
type={"number"}
inputProps={{
min: 1,
step: 1,
max: 100,
}}
value={options.thumb_encode_quality}
onChange={handleChange(
"thumb_encode_quality"
)}
required
/>
<FormHelperText id="component-helper-text">
压缩质量百分比只针对 jpg 编码有效
</FormHelperText>
</FormControl>
</div>
<div className={classes.form}>
<FormControl fullWidth>
<FormControlLabel
control={
<Switch
checked={
options.thumb_gc_after_gen ===
"1"
}
onChange={handleCheckChange(
"thumb_gc_after_gen"
)}
/>
}
label="生成完成后立即回收内存"
/>
</FormControl>
</div>
</div>
</div>
<div className={classes.root}>
<Button
disabled={loading}

View File

@ -40,7 +40,7 @@ export default function UploadDownload() {
max_parallel_transfer: "1",
temp_path: "",
maxEditSize: "0",
onedrive_chunk_retries: "0",
chunk_retries: "0",
archive_timeout: "0",
download_timeout: "0",
preview_timeout: "0",
@ -57,6 +57,7 @@ export default function UploadDownload() {
slave_ping_interval: "0",
slave_recover_interval: "0",
slave_transfer_timeout: "0",
use_temp_chunk_buffer: "1",
});
const handleCheckChange = (name) => (event) => {
@ -142,7 +143,7 @@ export default function UploadDownload() {
required
/>
<FormHelperText id="component-helper-text">
任务队列最多并行执行的任务数保存后需要重启
主机节点任务队列最多并行执行的任务数保存后需要重启
Cloudreve 生效
</FormHelperText>
</FormControl>
@ -182,7 +183,7 @@ export default function UploadDownload() {
required
/>
<FormHelperText id="component-helper-text">
用于存放打包下载解压缩压缩等任务产生的临时文件的目录路径
用于存放解压缩压缩等任务产生的临时文件的目录路径
</FormHelperText>
</FormControl>
</div>
@ -206,7 +207,7 @@ export default function UploadDownload() {
<div className={classes.form}>
<FormControl>
<InputLabel htmlFor="component-helper">
OneDrive 分片错误重试
分片错误重试
</InputLabel>
<Input
type={"number"}
@ -214,15 +215,35 @@ export default function UploadDownload() {
min: 0,
step: 1,
}}
value={options.onedrive_chunk_retries}
onChange={handleChange(
"onedrive_chunk_retries"
)}
value={options.chunk_retries}
onChange={handleChange("chunk_retries")}
required
/>
<FormHelperText id="component-helper-text">
OneDrive
存储策略分片上传失败后重试的最大次数只适用于服务端上传或中转
分片上传失败后重试的最大次数只适用于服务端上传或中转
</FormHelperText>
</FormControl>
</div>
<div className={classes.form}>
<FormControl fullWidth>
<FormControlLabel
control={
<Switch
checked={
options.use_temp_chunk_buffer ===
"1"
}
onChange={handleCheckChange(
"use_temp_chunk_buffer"
)}
/>
}
label="缓存流式分片文件以用于重试"
/>
<FormHelperText id="component-helper-text">
开启后流式中转分片上传时会将分片数据缓存在系统临时目录以便用于分片上传失败后的重试
关闭后流式中转分片上传不会额外占用硬盘空间但分片上传失败后整个上传会立即失败
</FormHelperText>
</FormControl>
</div>
@ -273,10 +294,6 @@ export default function UploadDownload() {
name: "Office 文档预览连接",
field: "doc_preview_timeout",
},
{
name: "上传凭证",
field: "upload_credential_timeout",
},
{
name: "上传会话",
field: "upload_session_timeout",