owncast/web/pages/storage.tsx

94 lines
1.9 KiB
TypeScript
Raw Normal View History

2020-11-01 08:01:37 +01:00
/* eslint-disable react/prop-types */
import React, { useState, useEffect } from "react";
2020-11-01 08:01:37 +01:00
import { SERVER_CONFIG, fetchData, FETCH_INTERVAL } from "../utils/apis";
import KeyValueTable from "./components/key-value-table";
2020-10-29 18:16:13 +01:00
function Storage({ config }) {
2020-11-01 08:01:37 +01:00
if (!config || !config.s3) {
2020-10-29 18:16:13 +01:00
return null;
}
if (!config.s3.enabled) {
return (
<h3>
Local storage is being used. Enable external S3 storage if you want
to use it.
</h3>
);
}
2020-10-29 18:16:13 +01:00
const data = [
{
name: "Enabled",
value: config.s3.enabled.toString(),
},
{
name: "Endpoint",
value: config.s3.endpoint,
},
{
name: "Access Key",
value: config.s3.accessKey,
},
{
name: "Secret",
value: config.s3.secret,
},
{
name: "Bucket",
value: config.s3.bucket,
},
{
name: "Region",
value: config.s3.region,
},
];
return <KeyValueTable title="External Storage" data={data} />;
}
export default function ServerConfig() {
2020-11-01 08:01:37 +01:00
const [config, setConfig] = useState({});
2020-10-29 18:16:13 +01:00
const getInfo = async () => {
try {
const result = await fetchData(SERVER_CONFIG);
console.log("viewers result", result);
2020-10-29 18:16:13 +01:00
setConfig({ ...result });
} catch (error) {
setConfig({ ...config, message: error.message });
}
};
2020-10-29 18:16:13 +01:00
useEffect(() => {
let getStatusIntervalId = null;
getInfo();
getStatusIntervalId = setInterval(getInfo, FETCH_INTERVAL);
// returned function will be called on component unmount
2020-10-29 18:16:13 +01:00
return () => {
clearInterval(getStatusIntervalId);
};
2020-10-29 18:16:13 +01:00
}, []);
return (
<div>
<h2>Server Config</h2>
<p>
Display this data all pretty, most things will be editable in the
future, not now.
</p>
<div
style={{
border: "1px solid pink",
width: "100%",
overflow: "auto",
}}
>
<Storage config={config} />
</div>
</div>
);
2020-10-29 18:16:13 +01:00
}