This commit is contained in:
2025-06-04 10:20:01 +08:00
parent 7994ecc100
commit ad1144ad69
42 changed files with 5536 additions and 3740 deletions

View File

@@ -1,10 +1,10 @@
import { useTranslation } from "react-i18next";
import { app } from "../app"
import { ErrorAlert, InfoAlert } from "../components/alert"
import { app } from "../app";
import { ErrorAlert, InfoAlert } from "../components/alert";
import { useEffect, useState } from "react";
import { ServerConfig } from "../network/models";
import Loading from "../components/loading";
import Input, {TextArea} from "../components/input";
import Input, { TextArea } from "../components/input";
import { network } from "../network/network";
import showToast from "../components/toast";
import Button from "../components/button";
@@ -24,21 +24,31 @@ export default function ManageServerConfigPage() {
showToast({
message: res.message,
type: "error",
})
});
}
})
});
}, []);
if (!app.user) {
return <ErrorAlert className={"m-4"} message={t("You are not logged in. Please log in to access this page.")} />
return (
<ErrorAlert
className={"m-4"}
message={t("You are not logged in. Please log in to access this page.")}
/>
);
}
if (!app.user?.is_admin) {
return <ErrorAlert className={"m-4"} message={t("You are not authorized to access this page.")} />
return (
<ErrorAlert
className={"m-4"}
message={t("You are not authorized to access this page.")}
/>
);
}
if (config == null) {
return <Loading />
return <Loading />;
}
const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
@@ -62,40 +72,107 @@ export default function ManageServerConfigPage() {
setIsLoading(false);
};
return <form className="px-4 pb-4" onSubmit={handleSubmit}>
<Input type="number" value={config.max_uploading_size_in_mb.toString()} label="Max uploading size (MB)" onChange={(e) => {
setConfig({...config, max_uploading_size_in_mb: parseInt(e.target.value) })
}}></Input>
<Input type="number" value={config.max_file_size_in_mb.toString()} label="Max file size (MB)" onChange={(e) => {
setConfig({...config, max_file_size_in_mb: parseInt(e.target.value) })
}}></Input>
<Input type="number" value={config.max_downloads_per_day_for_single_ip.toString()} label="Max downloads per day for single IP" onChange={(e) => {
setConfig({...config, max_downloads_per_day_for_single_ip: parseInt(e.target.value) })
}}></Input>
<fieldset className="fieldset w-full">
<legend className="fieldset-legend">Allow register</legend>
<input type="checkbox" checked={config.allow_register} className="toggle-primary toggle" onChange={(e) => {
setConfig({ ...config, allow_register: e.target.checked })
}} />
</fieldset>
<Input type="text" value={config.server_name} label="Server name" onChange={(e) => {
setConfig({...config, server_name: e.target.value })
}}></Input>
<Input type="text" value={config.server_description} label="Server description" onChange={(e) => {
setConfig({...config, server_description: e.target.value })
}}></Input>
<Input type="text" value={config.cloudflare_turnstile_site_key} label="Cloudflare Turnstile Site Key" onChange={(e) => {
setConfig({...config, cloudflare_turnstile_site_key: e.target.value })
}}></Input>
<Input type="text" value={config.cloudflare_turnstile_secret_key} label="Cloudflare Turnstile Secret Key" onChange={(e) => {
setConfig({...config, cloudflare_turnstile_secret_key: e.target.value })
}}></Input>
<TextArea value={config.site_info} onChange={(e) => {
setConfig({...config, site_info: e.target.value })
}} label="Site info (Markdown)" height={180} />
<InfoAlert className="my-2" message="If the cloudflare turnstile keys are not empty, the turnstile will be used for register and download." />
<div className="flex justify-end">
<Button className="btn-accent shadow" isLoading={isLoading}>{t("Submit")}</Button>
</div>
</form>
}
return (
<form className="px-4 pb-4" onSubmit={handleSubmit}>
<Input
type="number"
value={config.max_uploading_size_in_mb.toString()}
label="Max uploading size (MB)"
onChange={(e) => {
setConfig({
...config,
max_uploading_size_in_mb: parseInt(e.target.value),
});
}}
></Input>
<Input
type="number"
value={config.max_file_size_in_mb.toString()}
label="Max file size (MB)"
onChange={(e) => {
setConfig({
...config,
max_file_size_in_mb: parseInt(e.target.value),
});
}}
></Input>
<Input
type="number"
value={config.max_downloads_per_day_for_single_ip.toString()}
label="Max downloads per day for single IP"
onChange={(e) => {
setConfig({
...config,
max_downloads_per_day_for_single_ip: parseInt(e.target.value),
});
}}
></Input>
<fieldset className="fieldset w-full">
<legend className="fieldset-legend">Allow register</legend>
<input
type="checkbox"
checked={config.allow_register}
className="toggle-primary toggle"
onChange={(e) => {
setConfig({ ...config, allow_register: e.target.checked });
}}
/>
</fieldset>
<Input
type="text"
value={config.server_name}
label="Server name"
onChange={(e) => {
setConfig({ ...config, server_name: e.target.value });
}}
></Input>
<Input
type="text"
value={config.server_description}
label="Server description"
onChange={(e) => {
setConfig({ ...config, server_description: e.target.value });
}}
></Input>
<Input
type="text"
value={config.cloudflare_turnstile_site_key}
label="Cloudflare Turnstile Site Key"
onChange={(e) => {
setConfig({
...config,
cloudflare_turnstile_site_key: e.target.value,
});
}}
></Input>
<Input
type="text"
value={config.cloudflare_turnstile_secret_key}
label="Cloudflare Turnstile Secret Key"
onChange={(e) => {
setConfig({
...config,
cloudflare_turnstile_secret_key: e.target.value,
});
}}
></Input>
<TextArea
value={config.site_info}
onChange={(e) => {
setConfig({ ...config, site_info: e.target.value });
}}
label="Site info (Markdown)"
height={180}
/>
<InfoAlert
className="my-2"
message="If the cloudflare turnstile keys are not empty, the turnstile will be used for register and download."
/>
<div className="flex justify-end">
<Button className="btn-accent shadow" isLoading={isLoading}>
{t("Submit")}
</Button>
</div>
</form>
);
}