[FEATURE] Initial Backup Interval
This commit is contained in:
parent
a5ffe1694e
commit
b538ab5089
5 changed files with 77 additions and 4 deletions
|
@ -16,12 +16,20 @@ function payloadFilter(req, res) {
|
|||
const serverSpec = req.body;
|
||||
if (!serverSpec) return res.sendStatus(400);
|
||||
const { name, host, version, serverType, memory } = serverSpec;
|
||||
const { backupHost, backupBucket, backupId, backupKey } = serverSpec;
|
||||
if (!name) return res.status(400).send("Server name is required!");
|
||||
if (!host) return res.status(400).send("Server host is required!");
|
||||
if (!dnsRegex.test(host)) return res.status(400).send("Hostname invalid!");
|
||||
if (!version) return res.status(400).send("Server version is required!");
|
||||
if (!serverType) return res.status(400).send("Server type is required!");
|
||||
if (!memory) return res.status(400).send("Memory is required!");
|
||||
if (!!backupHost || !!backupBucket || !!backupId || !!backupKey) {
|
||||
// If any keys are required, all are required
|
||||
if (!(!!backupHost && !!backupBucket && !!backupId && !!backupKey))
|
||||
return res.status(400).send("All backup keys are required!");
|
||||
if (!dnsRegex.test(backupHost))
|
||||
return res.status(400).send("Backup Host invalid!");
|
||||
}
|
||||
return "filtered";
|
||||
}
|
||||
|
||||
|
|
|
@ -9,8 +9,9 @@ CREATE TABLE servers (
|
|||
memory varchar(63) DEFAULT '512',
|
||||
backup_host varchar(255) DEFAULT NULL,
|
||||
backup_bucket_path varchar(255) DEFAULT NULL,
|
||||
backup_user varchar(255) DEFAULT NULL,
|
||||
backup_pass varchar(255) DEFAULT NULL,
|
||||
backup_id varchar(255) DEFAULT NULL,
|
||||
backup_key varchar(255) DEFAULT NULL,
|
||||
backup_interval varchar(255) DEFAULT NULL,
|
||||
CONSTRAINT unique_host UNIQUE(host)
|
||||
);
|
||||
ALTER SEQUENCE servers_id_seq OWNED BY servers.id;
|
|
@ -10,8 +10,28 @@ const asExpressClientError = (e) => {
|
|||
const getMclName = (host, id) => `${host.replaceAll(".", "-")}-${id}`;
|
||||
|
||||
export async function createServerEntry(serverSpec) {
|
||||
const { name, host, version, serverType: server_type, memory } = serverSpec;
|
||||
var q = insertQuery(table, { name, host, version, server_type, memory });
|
||||
const {
|
||||
name,
|
||||
host,
|
||||
version,
|
||||
serverType: server_type,
|
||||
memory,
|
||||
backupHost: backup_host,
|
||||
backupBucket: backup_bucket_path,
|
||||
backupId: backup_id,
|
||||
backupKey: backup_key,
|
||||
} = serverSpec;
|
||||
var q = insertQuery(table, {
|
||||
name,
|
||||
host,
|
||||
version,
|
||||
server_type,
|
||||
memory,
|
||||
backup_host,
|
||||
backup_bucket_path,
|
||||
backup_id,
|
||||
backup_key,
|
||||
});
|
||||
q += "\n RETURNING *";
|
||||
try {
|
||||
const entries = await pg.query(q);
|
||||
|
|
42
src/components/server-options/BackupIntervalOption.jsx
Normal file
42
src/components/server-options/BackupIntervalOption.jsx
Normal file
|
@ -0,0 +1,42 @@
|
|||
import { useState } from "react";
|
||||
import Box from "@mui/material/Box";
|
||||
import MenuItem from "@mui/material/MenuItem";
|
||||
import TextField from "@mui/material/TextField";
|
||||
|
||||
export const backupIntervalStepOptions = ["m", "h", "d"];
|
||||
export default function BackupIntervalOption(props) {
|
||||
const { onChange } = props;
|
||||
const [interval, setInterval] = useState(1);
|
||||
const [intervalStep, setIntervalStep] = useState(
|
||||
backupIntervalStepOptions[2],
|
||||
);
|
||||
|
||||
const changeInterval = (e) => console.log(e.target.value);
|
||||
|
||||
return (
|
||||
<Box>
|
||||
<TextField
|
||||
label="Backup Interval"
|
||||
sx={{ width: "100%" }}
|
||||
onChange={changeInterval}
|
||||
helperText="Examples: 1m, 3h, 3.5d"
|
||||
FormHelperTextProps={{ sx: { ml: 0 } }}
|
||||
required
|
||||
/>
|
||||
<TextField
|
||||
label="Backup Step"
|
||||
onChange={onChange}
|
||||
value={intervalStep}
|
||||
select
|
||||
required
|
||||
SelectProps={{ MenuProps: { sx: { maxHeight: "20rem" } } }}
|
||||
>
|
||||
{backupIntervalStepOptions.map((o, i) => (
|
||||
<MenuItem value={o} key={i}>
|
||||
{o}
|
||||
</MenuItem>
|
||||
))}
|
||||
</TextField>
|
||||
</Box>
|
||||
);
|
||||
}
|
|
@ -26,6 +26,7 @@ import BackupHostOption from "@mcl/components/server-options/BackupHostOption.js
|
|||
import BackupBucketOption from "@mcl/components/server-options/BackupBucketOption.jsx";
|
||||
import BackupIdOption from "@mcl/components/server-options/BackupIdOption.jsx";
|
||||
import BackupKeyOption from "@mcl/components/server-options/BackupKeyOption.jsx";
|
||||
import BackupIntervalOption from "@mcl/components/server-options/BackupIntervalOption.jsx";
|
||||
|
||||
const defaultServer = {
|
||||
version: "latest",
|
||||
|
@ -118,6 +119,7 @@ export default function CreateCoreOptions() {
|
|||
value={spec.backupKey}
|
||||
onChange={coreUpdate("backupKey")}
|
||||
/>
|
||||
<BackupIntervalOption onChange={coreUpdate("backupInterval")} />
|
||||
</FormControl>
|
||||
)}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue