0
owncast/web/pages/update-server-config.tsx

166 lines
3.2 KiB
TypeScript
Raw Normal View History

2020-11-01 00:01:37 -07:00
/* eslint-disable react/prop-types */
2020-10-28 00:53:24 -07:00
import React, { useState, useEffect } from 'react';
2020-10-25 21:39:25 -07:00
import { Table, Typography, Input } from 'antd';
2020-11-01 00:01:37 -07:00
import { SERVER_CONFIG, fetchData, FETCH_INTERVAL } from '../utils/apis';
import { isEmptyObject } from '../utils/format';
2020-10-29 10:16:13 -07:00
import KeyValueTable from "./components/key-value-table";
2020-10-25 21:39:25 -07:00
const { Title } = Typography;
const { TextArea } = Input;
2020-10-22 17:16:28 -07:00
export const INITIAL_SERVER_CONFIG_STATE = {
streamKey: '',
yp: {
enabled: false,
},
videoSettings: {
videoQualityVariants: [
{
audioPassthrough: false,
videoBitrate: 0,
audioBitrate: 0,
framerate: 0,
},
],
}
};
2020-10-28 00:53:24 -07:00
function SocialHandles({ config }) {
if (!config) {
return null;
}
const columns = [
{
title: "Platform",
dataIndex: "platform",
key: "platform",
},
{
title: "URL",
dataIndex: "url",
key: "url",
2020-11-02 21:38:56 -08:00
render: (url) => <a href={url}>{url}</a>
2020-10-28 00:53:24 -07:00
},
];
2020-11-01 00:01:37 -07:00
if (!config.instanceDetails?.socialHandles) {
return null;
}
return (
<div>
<Title>Social Handles</Title>
<Table
pagination={false}
columns={columns}
dataSource={config.instanceDetails.socialHandles}
/>
</div>
);
2020-10-28 00:53:24 -07:00
}
function InstanceDetails({ config }) {
if (!config || isEmptyObject(config)) {
return null;
}
const { instanceDetails = {}, yp, streamKey, ffmpegPath, webServerPort } = config;
const data = [
{
name: "Server name",
value: instanceDetails.name,
},
{
name: "Title",
value: instanceDetails.title,
},
{
name: "Summary",
value: instanceDetails.summary,
},
{
name: "Logo",
2020-11-13 03:57:57 -08:00
value: instanceDetails.logo?.large,
2020-10-28 00:53:24 -07:00
},
{
name: "Tags",
2020-11-13 03:57:57 -08:00
value: instanceDetails.tags?.join(", "),
2020-10-28 00:53:24 -07:00
},
{
name: "NSFW",
2020-11-13 03:57:57 -08:00
value: instanceDetails.nsfw?.toString(),
2020-10-28 00:53:24 -07:00
},
{
name: "Shows in Owncast directory",
value: yp.enabled.toString(),
},
];
const configData = [
{
name: "Stream key",
value: streamKey,
},
{
name: "ffmpeg path",
value: ffmpegPath,
},
{
name: "Web server port",
value: webServerPort,
},
];
return (
<>
<KeyValueTable title="Server details" data={data} />
<KeyValueTable title="Server configuration" data={configData} />
</>
);
}
function PageContent({ config }) {
2020-11-01 00:01:37 -07:00
if (!config?.instanceDetails?.extraPageContent) {
2020-10-28 00:53:24 -07:00
return null;
}
return (
<div>
<Title>Page content</Title>
<TextArea
disabled rows={4}
value={config.instanceDetails.extraPageContent}
/>
</div>
);
}
2020-10-25 21:39:25 -07:00
export default function ServerConfig() {
const [config, setConfig] = useState(INITIAL_SERVER_CONFIG_STATE);
const getInfo = async () => {
try {
const result = await fetchData(SERVER_CONFIG);
console.log("SERVER_CONFIG", result)
2020-10-25 21:39:25 -07:00
setConfig({ ...result });
} catch (error) {
2020-10-25 21:39:25 -07:00
setConfig({ ...config, message: error.message });
}
};
2020-11-13 03:57:57 -08:00
useEffect(() => {
getInfo();
}, []);
return (
<div>
2020-10-28 00:53:24 -07:00
<InstanceDetails config={config} />
<SocialHandles config={config} />
<PageContent config={config} />
</div>
2020-10-28 00:53:24 -07:00
);
}
2020-10-25 21:39:25 -07:00