From 5fc955d2a148acb34837a1007472f69c76013115 Mon Sep 17 00:00:00 2001 From: Gabe Kangas Date: Sun, 31 Jan 2021 19:45:26 -0800 Subject: [PATCH] storage form --- web/pages/config-storage.tsx | 140 ++++++++++++++++++++--------------- 1 file changed, 82 insertions(+), 58 deletions(-) diff --git a/web/pages/config-storage.tsx b/web/pages/config-storage.tsx index 6c1f5e3d0..e46713350 100644 --- a/web/pages/config-storage.tsx +++ b/web/pages/config-storage.tsx @@ -1,9 +1,10 @@ -import React, { useContext } from "react"; -import KeyValueTable from "./components/key-value-table"; +import React, { useContext, useState, useEffect } from 'react'; import { ServerStatusContext } from '../utils/server-status-context'; -import { Typography } from 'antd'; -import Link from 'next/link'; - +import { Typography, Switch, Input, Button } from 'antd'; +import { + postConfigUpdateToAPI, + API_S3_INFO, +} from './components/config/constants'; const { Title } = Typography; function Storage({ config }) { @@ -11,66 +12,89 @@ function Storage({ config }) { return null; } - if (!config.s3.enabled) { - return ( -
- External Storage -

- You are currently using the local storage of this Owncast server to store and distribute video. -

-

- Owncast can use S3-compatible external storage providers to offload the responsibility of disk and bandwidth utilization from your own server. -

+ const [endpoint, setEndpoint] = useState(config.s3.endpoint); + const [accessKey, setAccessKey] = useState(config.s3.accessKey); + const [secret, setSecret] = useState(config.s3.secret); + const [bucket, setBucket] = useState(config.s3.bucket); + const [region, setRegion] = useState(config.s3.region); + const [acl, setAcl] = useState(config.s3.acl); + const [servingEndpoint, setServingEndpoint] = useState(config.s3.servingEndpoint); + const [enabled, setEnabled] = useState(config.s3.enabled); -

- Visit our storage documentation to learn how to configure this. -

-
- ); + function storageEnabledChanged(storageEnabled) { + setEnabled(storageEnabled); } - 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, - }, - ]; + function endpointChanged(e) { + setEndpoint(e.target.value) + } - const advanced = [ - { - name: "ACL", - value: config.s3.acl - }, - { - name: "Serving Endpoint", - value: config.s3.servingEndpoint - }, - ]; + function accessKeyChanged(e) { + setAccessKey(e.target.value) + } + + function secretChanged(e) { + setSecret(e.target.value) + } + + function bucketChanged(e) { + setBucket(e.target.value) + } + + function regionChanged(e) { + setRegion(e.target.value) + } + + function aclChanged(e) { + setAcl(e.target.value) + } + + function servingEndpointChanged(e) { + setServingEndpoint(e.target.value) + } + + async function save() { + const payload = { + value: { + enabled: enabled, + endpoint: endpoint, + accessKey: accessKey, + secret: secret, + bucket: bucket, + region: region, + acl: acl, + servingEndpoint: servingEndpoint, + } + }; + + try { + await postConfigUpdateToAPI({apiPath: API_S3_INFO, data: payload}); + } catch(e) { + console.error(e); + } + } + + const table = enabled ? ( + <> +

+ endpoint + access key + secret + bucket + region + advanced

+ acl + serving endpoint + + + ): null; return ( <> - - + Storage + Enabled: + + { table } ); }