mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-23 16:23:12 +09:00
Merge pull request #1261 from bbassie/fix/webui-nits-1260
Small web interface button and label changes
This commit is contained in:
20 files changed
+488
-392
No files matched your search
@@ -126,6 +126,14 @@ This should be a full URL ending with a /.
|
|||||||
Defaults to null meaning assume localhost.
|
Defaults to null meaning assume localhost.
|
||||||
|
|
||||||
|
|
||||||
|
### controller.favicon_url
|
||||||
|
|
||||||
|
URL of the icon shown in the browser tab.
|
||||||
|
A relative URL is relative to the web interface root, so `static/icon.png` loads `icon.png` from the `static` folder in the controller's working directory.
|
||||||
|
|
||||||
|
Defaults to null meaning use the Clusterio logo.
|
||||||
|
|
||||||
|
|
||||||
### controller.static_url
|
### controller.static_url
|
||||||
|
|
||||||
Used to override where static assets such as the web bundle is loaded from.
|
Used to override where static assets such as the web bundle is loaded from.
|
||||||
|
|||||||
@@ -48,6 +48,11 @@ const logSizeGauge = new Gauge(
|
|||||||
|
|
||||||
type InstanceId = { instanceId: number };
|
type InstanceId = { instanceId: number };
|
||||||
|
|
||||||
|
const htmlEscapes: Record<string, string> = { "&": "&", "<": "<", ">": ">", "\"": """, "'": "'" };
|
||||||
|
function escapeHtml(text: string) {
|
||||||
|
return text.replace(/[&<>"']/g, char => htmlEscapes[char]);
|
||||||
|
}
|
||||||
|
|
||||||
type ControllerDebugEvents = {
|
type ControllerDebugEvents = {
|
||||||
"message": [ { direction: "in" | "out", content: string } ],
|
"message": [ { direction: "in" | "out", content: string } ],
|
||||||
};
|
};
|
||||||
@@ -1720,8 +1725,16 @@ export default class Controller {
|
|||||||
path.join(import.meta.dirname, "..", "..", "..", "web", "index.html"),
|
path.join(import.meta.dirname, "..", "..", "..", "web", "index.html"),
|
||||||
"utf8",
|
"utf8",
|
||||||
).then(async (content) => {
|
).then(async (content) => {
|
||||||
|
const config: lib.ControllerConfig = res.app.locals.controller.config;
|
||||||
|
let faviconUrl = config.get("controller.favicon_url");
|
||||||
|
// Relative to the web root rather than the page
|
||||||
|
if (faviconUrl && !/^([a-z][a-z0-9+.-]*:|\/)/i.test(faviconUrl)) {
|
||||||
|
faviconUrl = webRoot + faviconUrl;
|
||||||
|
}
|
||||||
|
const favicon = faviconUrl ? `<link rel="icon" href="${escapeHtml(faviconUrl)}" />` : "";
|
||||||
content = content
|
content = content
|
||||||
.replace(/__CLUSTER_NAME__/g, res.app.locals.controller.config.get("controller.name"))
|
.replace(/__CLUSTER_NAME__/g, () => escapeHtml(config.get("controller.name")))
|
||||||
|
.replace(/__FAVICON__/g, () => favicon)
|
||||||
.replace(/__WEB_ROOT__/g, webRoot)
|
.replace(/__WEB_ROOT__/g, webRoot)
|
||||||
.replace(/__STATIC_ROOT__/g, staticRoot)
|
.replace(/__STATIC_ROOT__/g, staticRoot)
|
||||||
.replace(/__IMPORT_MAP__/g, () => importMap)
|
.replace(/__IMPORT_MAP__/g, () => importMap)
|
||||||
|
|||||||
@@ -4,7 +4,9 @@
|
|||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
<meta name="theme-color" content="#2a2a2a" />
|
<meta name="theme-color" content="#2a2a2a" />
|
||||||
|
<meta name="application-name" content="__CLUSTER_NAME__" />
|
||||||
<title>__CLUSTER_NAME__</title>
|
<title>__CLUSTER_NAME__</title>
|
||||||
|
__FAVICON__
|
||||||
<script type="importmap">__IMPORT_MAP__</script>
|
<script type="importmap">__IMPORT_MAP__</script>
|
||||||
<style>
|
<style>
|
||||||
html {
|
html {
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ export interface ControllerConfigFields {
|
|||||||
"controller.bind_address": string | null;
|
"controller.bind_address": string | null;
|
||||||
"controller.trusted_proxies": string | null;
|
"controller.trusted_proxies": string | null;
|
||||||
"controller.public_url": string | null;
|
"controller.public_url": string | null;
|
||||||
|
"controller.favicon_url": string | null;
|
||||||
"controller.static_url": string | null;
|
"controller.static_url": string | null;
|
||||||
"controller.grafana_url": string | null;
|
"controller.grafana_url": string | null;
|
||||||
"controller.tls_certificate": string | null;
|
"controller.tls_certificate": string | null;
|
||||||
@@ -177,6 +178,12 @@ export class ControllerConfig extends classes.Config<ControllerConfigFields> {
|
|||||||
optional: true,
|
optional: true,
|
||||||
// TODO extendedValidation, valid url including the protocol
|
// TODO extendedValidation, valid url including the protocol
|
||||||
},
|
},
|
||||||
|
"controller.favicon_url": {
|
||||||
|
title: "Favicon URL",
|
||||||
|
description: "URL of the icon shown in the browser tab, defaults to the Clusterio logo.",
|
||||||
|
type: "string",
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
"controller.static_url": {
|
"controller.static_url": {
|
||||||
title: "Static URL",
|
title: "Static URL",
|
||||||
description: "Override the URL to where static assets are hosted (must have a path consisting of /static/)",
|
description: "Override the URL to where static assets are hosted (must have a path consisting of /static/)",
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import { loadedPluginSetKey } from "./util/pluginSet";
|
|||||||
import { pageActionsFromHooks } from "./util/plugin_actions";
|
import { pageActionsFromHooks } from "./util/plugin_actions";
|
||||||
import * as WebPlugin from "./BaseWebPlugin";
|
import * as WebPlugin from "./BaseWebPlugin";
|
||||||
import { pages } from "./pages";
|
import { pages } from "./pages";
|
||||||
|
import logo from "./images/logo.png";
|
||||||
|
|
||||||
const { ConsoleTransport, WebConsoleFormat, logger } = lib;
|
const { ConsoleTransport, WebConsoleFormat, logger } = lib;
|
||||||
|
|
||||||
@@ -190,6 +191,13 @@ async function pagesFromHooks(control: Control) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default async function bootstrap() {
|
export default async function bootstrap() {
|
||||||
|
// The controller adds a link when controller.favicon_url is set
|
||||||
|
if (!document.querySelector("link[rel=icon]")) {
|
||||||
|
const icon = document.createElement("link");
|
||||||
|
icon.rel = "icon";
|
||||||
|
icon.href = logo;
|
||||||
|
document.head.appendChild(icon);
|
||||||
|
}
|
||||||
logger.add(new ConsoleTransport({
|
logger.add(new ConsoleTransport({
|
||||||
level: "verbose",
|
level: "verbose",
|
||||||
format: new WebConsoleFormat(),
|
format: new WebConsoleFormat(),
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import React, {useContext, useState} from "react";
|
import React, { useContext, useEffect, useState } from "react";
|
||||||
import { Descriptions, Flex, Modal, Popconfirm, Space, Tooltip, Typography } from "antd";
|
import { Descriptions, Flex, Modal, Popconfirm, Space, Tooltip, Typography } from "antd";
|
||||||
import { ExclamationCircleOutlined } from "@ant-design/icons";
|
import { ExclamationCircleOutlined } from "@ant-design/icons";
|
||||||
|
|
||||||
@@ -108,12 +108,49 @@ function ControllerControlButton({ canRestart, restartRequired }: ControllerCont
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function formatListen(config: lib.ControllerConfig) {
|
||||||
|
let address = config.get("controller.bind_address") || "*";
|
||||||
|
if (address.includes(":")) {
|
||||||
|
address = `[${address}]`;
|
||||||
|
}
|
||||||
|
const listen = [];
|
||||||
|
for (const protocol of ["http", "https"] as const) {
|
||||||
|
const port = config.get(`controller.${protocol}_port`);
|
||||||
|
if (port) {
|
||||||
|
listen.push(`${protocol}://${address}:${port}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return listen.join(", ");
|
||||||
|
}
|
||||||
|
|
||||||
|
function useControllerConfig() {
|
||||||
|
const account = useAccount();
|
||||||
|
const control = useContext(ControlContext);
|
||||||
|
const [config, setConfig] = useState<lib.ControllerConfig>();
|
||||||
|
const canConfig = account.hasPermission("core.controller.get_config");
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!canConfig) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
let canceled = false;
|
||||||
|
control.send(new lib.ControllerConfigGetRequest()).then(serialized => {
|
||||||
|
if (!canceled) {
|
||||||
|
setConfig(lib.ControllerConfig.fromJSON(serialized, "control"));
|
||||||
|
}
|
||||||
|
}).catch(notifyErrorHandler("Error loading controller config"));
|
||||||
|
return () => { canceled = true; };
|
||||||
|
}, [control, canConfig]);
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
export default function ControllerPage() {
|
export default function ControllerPage() {
|
||||||
const account = useAccount();
|
const account = useAccount();
|
||||||
const [systems] = useSystems();
|
const [systems] = useSystems();
|
||||||
const system = systems.get("controller");
|
const system = systems.get("controller");
|
||||||
const [maxLevel, setMaxLevel] = useState<keyof typeof lib.levels>("info");
|
const [maxLevel, setMaxLevel] = useState<keyof typeof lib.levels>("info");
|
||||||
const canShowNpm = hasNpmButtonPermission(true);
|
const canShowNpm = hasNpmButtonPermission(true);
|
||||||
|
const config = useControllerConfig();
|
||||||
|
|
||||||
return <PageLayout nav={[{ name: "Controller" }]}>
|
return <PageLayout nav={[{ name: "Controller" }]}>
|
||||||
<PageHeader
|
<PageHeader
|
||||||
@@ -138,7 +175,8 @@ export default function ControllerPage() {
|
|||||||
<Descriptions.Item label="Process Uptime">
|
<Descriptions.Item label="Process Uptime">
|
||||||
<MetricRelativeDate timeMs={system?.processStartedAtMs}/>
|
<MetricRelativeDate timeMs={system?.processStartedAtMs}/>
|
||||||
</Descriptions.Item>
|
</Descriptions.Item>
|
||||||
<Descriptions.Item label="Hostname" span={2}>{system?.hostname}</Descriptions.Item>
|
<Descriptions.Item label="Hostname" span={config ? 1 : 2}>{system?.hostname}</Descriptions.Item>
|
||||||
|
{config && <Descriptions.Item label="Bind Address">{formatListen(config)}</Descriptions.Item>}
|
||||||
<Descriptions.Item label="CPU Model" span={2}>{system?.cpuModel}</Descriptions.Item>
|
<Descriptions.Item label="CPU Model" span={2}>{system?.cpuModel}</Descriptions.Item>
|
||||||
<Descriptions.Item label="CPU Usage"><MetricCpuRatio system={system} /></Descriptions.Item>
|
<Descriptions.Item label="CPU Usage"><MetricCpuRatio system={system} /></Descriptions.Item>
|
||||||
<Descriptions.Item label="Cores"><MetricCpuUsed system={system} /></Descriptions.Item>
|
<Descriptions.Item label="Cores"><MetricCpuUsed system={system} /></Descriptions.Item>
|
||||||
@@ -146,6 +184,9 @@ export default function ControllerPage() {
|
|||||||
<Descriptions.Item label="Memory"><MetricMemoryUsed system={system} /></Descriptions.Item>
|
<Descriptions.Item label="Memory"><MetricMemoryUsed system={system} /></Descriptions.Item>
|
||||||
<Descriptions.Item label="Disk Usage"><MetricDiskRatio system={system} /></Descriptions.Item>
|
<Descriptions.Item label="Disk Usage"><MetricDiskRatio system={system} /></Descriptions.Item>
|
||||||
<Descriptions.Item label="Disk"><MetricDiskUsed system={system} /></Descriptions.Item>
|
<Descriptions.Item label="Disk"><MetricDiskUsed system={system} /></Descriptions.Item>
|
||||||
|
{config && <Descriptions.Item label="Public URL">
|
||||||
|
{config.get("controller.public_url") || <em>Not set</em>}
|
||||||
|
</Descriptions.Item>}
|
||||||
</Descriptions>
|
</Descriptions>
|
||||||
{account.hasPermission("core.log.follow") && <>
|
{account.hasPermission("core.log.follow") && <>
|
||||||
<Flex justify="space-between" align="baseline">
|
<Flex justify="space-between" align="baseline">
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ export default function CreateSaveModal(props: CreateSaveModalProps) {
|
|||||||
setOpen(true);
|
setOpen(true);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Create save
|
Create
|
||||||
</Button>
|
</Button>
|
||||||
<Modal
|
<Modal
|
||||||
title="Create Save"
|
title="Create Save"
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import React from "react";
|
||||||
|
|
||||||
|
/** Label and control laid out on one line */
|
||||||
|
export default function FieldRow(props: { label: React.ReactNode, children: React.ReactNode }) {
|
||||||
|
return <div style={{ marginBottom: 16, display: "flex", alignItems: "center", gap: 12 }}>
|
||||||
|
<label style={{ width: 110, flexShrink: 0 }}>{props.label}</label>
|
||||||
|
{props.children}
|
||||||
|
</div>;
|
||||||
|
}
|
||||||
@@ -11,6 +11,8 @@ import VariableDropdownButton, { VariableDropdownButtonProps } from "./VariableD
|
|||||||
type InstanceControlButtonProps = Omit<VariableDropdownButtonProps, "actions"> & {
|
type InstanceControlButtonProps = Omit<VariableDropdownButtonProps, "actions"> & {
|
||||||
instance: lib.InstanceDetails;
|
instance: lib.InstanceDetails;
|
||||||
onFinish?: () => void;
|
onFinish?: () => void;
|
||||||
|
/** Added to the dropdown before Kill */
|
||||||
|
extraActions?: VariableDropdownButtonProps["actions"];
|
||||||
};
|
};
|
||||||
|
|
||||||
export const InstanceControlButtonPermissions = [
|
export const InstanceControlButtonPermissions = [
|
||||||
@@ -23,8 +25,9 @@ export default function InstanceControlButton(props: InstanceControlButtonProps)
|
|||||||
const [switching, setSwitching] = useState<boolean>(false);
|
const [switching, setSwitching] = useState<boolean>(false);
|
||||||
const [popconfirm, setPopconfirm] = useState<string | null>(null);
|
const [popconfirm, setPopconfirm] = useState<string | null>(null);
|
||||||
|
|
||||||
const instanceId = props.instance.id;
|
const { instance, onFinish, extraActions, ...buttonProps } = props;
|
||||||
const instanceStatus = props.instance.status;
|
const instanceId = instance.id;
|
||||||
|
const instanceStatus = instance.status;
|
||||||
// While starting or stopping the button shows the action in progress as loading.
|
// While starting or stopping the button shows the action in progress as loading.
|
||||||
const showStart = ["stopped", "starting"].includes(instanceStatus);
|
const showStart = ["stopped", "starting"].includes(instanceStatus);
|
||||||
const showStop = ["running", "stopping"].includes(instanceStatus);
|
const showStop = ["running", "stopping"].includes(instanceStatus);
|
||||||
@@ -32,8 +35,8 @@ export default function InstanceControlButton(props: InstanceControlButtonProps)
|
|||||||
|
|
||||||
function actionFinish() {
|
function actionFinish() {
|
||||||
setSwitching(false);
|
setSwitching(false);
|
||||||
if (props.onFinish) {
|
if (onFinish) {
|
||||||
props.onFinish();
|
onFinish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,6 +91,8 @@ export default function InstanceControlButton(props: InstanceControlButtonProps)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
actions.push(...extraActions ?? []);
|
||||||
|
|
||||||
if (account.hasPermission("core.instance.kill")) {
|
if (account.hasPermission("core.instance.kill")) {
|
||||||
actions.push({
|
actions.push({
|
||||||
key: "kill",
|
key: "kill",
|
||||||
@@ -100,7 +105,7 @@ export default function InstanceControlButton(props: InstanceControlButtonProps)
|
|||||||
|
|
||||||
return <div style={{ position: "relative", display: "inline-block" }}>
|
return <div style={{ position: "relative", display: "inline-block" }}>
|
||||||
<VariableDropdownButton
|
<VariableDropdownButton
|
||||||
{...props}
|
{...buttonProps}
|
||||||
type="primary"
|
type="primary"
|
||||||
actions={actions}
|
actions={actions}
|
||||||
loading={switching || transitioning}
|
loading={switching || transitioning}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ import SavesList from "./SavesList";
|
|||||||
import OnlinePlayersList from "./OnlinePlayersList";
|
import OnlinePlayersList from "./OnlinePlayersList";
|
||||||
import { notifyErrorHandler } from "../util/notify";
|
import { notifyErrorHandler } from "../util/notify";
|
||||||
import { useInstance, useInstances } from "../model/instance";
|
import { useInstance, useInstances } from "../model/instance";
|
||||||
import { CreateInstanceButton } from "./InstancesPage";
|
import { CreateInstanceButton, CreateInstanceModal } from "./InstancesPage";
|
||||||
import { useHost } from "../model/host";
|
import { useHost } from "../model/host";
|
||||||
import InstanceStatusTag from "./InstanceStatusTag";
|
import InstanceStatusTag from "./InstanceStatusTag";
|
||||||
import Link from "./Link";
|
import Link from "./Link";
|
||||||
@@ -146,6 +146,7 @@ function InstanceButtons(props: { instance: lib.InstanceDetails }) {
|
|||||||
let control = useContext(ControlContext);
|
let control = useContext(ControlContext);
|
||||||
let navigate = useNavigate();
|
let navigate = useNavigate();
|
||||||
let [exportingData, setExportingData] = useState(false);
|
let [exportingData, setExportingData] = useState(false);
|
||||||
|
const [modal, setModal] = useState<"scenario" | "template">();
|
||||||
let instance = props.instance;
|
let instance = props.instance;
|
||||||
let instanceId = instance.id!;
|
let instanceId = instance.id!;
|
||||||
let [host] = useHost(instance.assignedHost);
|
let [host] = useHost(instance.assignedHost);
|
||||||
@@ -154,6 +155,9 @@ function InstanceButtons(props: { instance: lib.InstanceDetails }) {
|
|||||||
const pluginActions = usePluginActions("InstanceViewPage", { instance });
|
const pluginActions = usePluginActions("InstanceViewPage", { instance });
|
||||||
|
|
||||||
let instanceButtonMenuItems: MenuItem[] = [];
|
let instanceButtonMenuItems: MenuItem[] = [];
|
||||||
|
if (canCreate) {
|
||||||
|
instanceButtonMenuItems.push({ key: "template", label: "Create template" });
|
||||||
|
}
|
||||||
if (account.hasPermission("core.instance.export_data")) {
|
if (account.hasPermission("core.instance.export_data")) {
|
||||||
instanceButtonMenuItems.push({
|
instanceButtonMenuItems.push({
|
||||||
disabled: exportingData || instance.status !== "stopped",
|
disabled: exportingData || instance.status !== "stopped",
|
||||||
@@ -199,7 +203,9 @@ function InstanceButtons(props: { instance: lib.InstanceDetails }) {
|
|||||||
let instanceButtonsMenuProps: MenuProps = {
|
let instanceButtonsMenuProps: MenuProps = {
|
||||||
items: instanceButtonMenuItems,
|
items: instanceButtonMenuItems,
|
||||||
onClick: ({ key }: { key: string }) => {
|
onClick: ({ key }: { key: string }) => {
|
||||||
if (key === "export") {
|
if (key === "template") {
|
||||||
|
setModal("template");
|
||||||
|
} else if (key === "export") {
|
||||||
setExportingData(true);
|
setExportingData(true);
|
||||||
control.sendTo(
|
control.sendTo(
|
||||||
{ instanceId },
|
{ instanceId },
|
||||||
@@ -240,10 +246,19 @@ function InstanceButtons(props: { instance: lib.InstanceDetails }) {
|
|||||||
</Space>;
|
</Space>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const canLoadScenario = account.hasPermission("core.instance.load_scenario");
|
||||||
return <Space wrap>
|
return <Space wrap>
|
||||||
{
|
{
|
||||||
account.hasAnyPermission(...InstanceControlButtonPermissions)
|
account.hasAnyPermission(...InstanceControlButtonPermissions, "core.instance.load_scenario")
|
||||||
&& <InstanceControlButton instance={instance} />
|
&& <InstanceControlButton
|
||||||
|
instance={instance}
|
||||||
|
extraActions={canLoadScenario ? [{
|
||||||
|
key: "scenario",
|
||||||
|
label: "Load scenario",
|
||||||
|
disabled: instance.status !== "stopped",
|
||||||
|
onClick: () => setModal("scenario"),
|
||||||
|
}] : []}
|
||||||
|
/>
|
||||||
}
|
}
|
||||||
<Button
|
<Button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
@@ -256,17 +271,21 @@ function InstanceButtons(props: { instance: lib.InstanceDetails }) {
|
|||||||
>
|
>
|
||||||
Connect via Steam
|
Connect via Steam
|
||||||
</Button>
|
</Button>
|
||||||
{account.hasPermission("core.instance.load_scenario") && <LoadScenarioModal instance={instance} />}
|
|
||||||
{canCreate && <CreateInstanceButton
|
|
||||||
instances={instances}
|
|
||||||
initial={{ instanceClone: instanceId, asTemplate: true, linkSource: true }}
|
|
||||||
buttonText="Create template"
|
|
||||||
buttonType="default"
|
|
||||||
/>}
|
|
||||||
{instanceButtonMenuItems.length > 0
|
{instanceButtonMenuItems.length > 0
|
||||||
&& <Dropdown placement="bottomRight" trigger={["click"]} menu={instanceButtonsMenuProps}>
|
&& <Dropdown placement="bottomRight" trigger={["click"]} menu={instanceButtonsMenuProps}>
|
||||||
<Button>More <DownOutlined /></Button>
|
<Button>More <DownOutlined /></Button>
|
||||||
</Dropdown>}
|
</Dropdown>}
|
||||||
|
{canLoadScenario && <LoadScenarioModal
|
||||||
|
instance={instance}
|
||||||
|
open={modal === "scenario"}
|
||||||
|
onClose={() => setModal(undefined)}
|
||||||
|
/>}
|
||||||
|
{canCreate && <CreateInstanceModal
|
||||||
|
instances={instances}
|
||||||
|
initial={{ instanceClone: instanceId, asTemplate: true, linkSource: true }}
|
||||||
|
open={modal === "template"}
|
||||||
|
onClose={() => setModal(undefined)}
|
||||||
|
/>}
|
||||||
</Space>;
|
</Space>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -97,10 +97,28 @@ export function CreateInstanceButton({ buttonText = "Create", buttonType = "prim
|
|||||||
buttonType?: "primary" | "default";
|
buttonType?: "primary" | "default";
|
||||||
buttonSize?: "small";
|
buttonSize?: "small";
|
||||||
}) {
|
}) {
|
||||||
|
const [open, setOpen] = useState(false);
|
||||||
|
return <>
|
||||||
|
<Button type={buttonType} size={props.buttonSize} onClick={() => setOpen(true)}>{buttonText}</Button>
|
||||||
|
<CreateInstanceModal
|
||||||
|
instances={props.instances}
|
||||||
|
initial={props.initial}
|
||||||
|
open={open}
|
||||||
|
onClose={() => setOpen(false)}
|
||||||
|
/>
|
||||||
|
</>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function CreateInstanceModal(props: {
|
||||||
|
instances: ReturnType<typeof useInstances>[0];
|
||||||
|
initial?: CreateInstanceInitial;
|
||||||
|
open: boolean;
|
||||||
|
onClose: () => void;
|
||||||
|
}) {
|
||||||
|
const { open } = props;
|
||||||
let control = useContext(ControlContext);
|
let control = useContext(ControlContext);
|
||||||
let account = useAccount();
|
let account = useAccount();
|
||||||
let navigate = useNavigate();
|
let navigate = useNavigate();
|
||||||
let [open, setOpen] = useState(false);
|
|
||||||
let [creating, setCreating] = useState(false);
|
let [creating, setCreating] = useState(false);
|
||||||
let [form] = Form.useForm();
|
let [form] = Form.useForm();
|
||||||
let [hosts] = useHosts();
|
let [hosts] = useHosts();
|
||||||
@@ -190,100 +208,91 @@ export function CreateInstanceButton({ buttonText = "Create", buttonType = "prim
|
|||||||
} finally {
|
} finally {
|
||||||
setCreating(false);
|
setCreating(false);
|
||||||
if (created) {
|
if (created) {
|
||||||
setOpen(false);
|
props.onClose();
|
||||||
navigate(`/instances/${instanceId}/view`);
|
navigate(`/instances/${instanceId}/view`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return <>
|
return <Modal
|
||||||
<Button
|
title={asTemplate ? "Create Template" : "Create Instance"}
|
||||||
type={buttonType}
|
okText="Create"
|
||||||
size={props.buttonSize}
|
open={open}
|
||||||
onClick={() => {
|
confirmLoading={creating}
|
||||||
setOpen(true);
|
onOk={() => { createInstance().catch(notifyErrorHandler("Error creating instance")); }}
|
||||||
|
onCancel={props.onClose}
|
||||||
|
destroyOnHidden
|
||||||
|
>
|
||||||
|
<Form
|
||||||
|
form={form}
|
||||||
|
initialValues={{
|
||||||
|
host: "null", instanceClone: -1, saveMode: "none", startAfter: false,
|
||||||
|
template: null, asTemplate: false, linkSource: true, ...props.initial,
|
||||||
}}
|
}}
|
||||||
>{buttonText}</Button>
|
|
||||||
<Modal
|
|
||||||
title={asTemplate ? "Create Template" : "Create Instance"}
|
|
||||||
okText="Create"
|
|
||||||
open={open}
|
|
||||||
confirmLoading={creating}
|
|
||||||
onOk={() => { createInstance().catch(notifyErrorHandler("Error creating instance")); }}
|
|
||||||
onCancel={() => { setOpen(false); }}
|
|
||||||
destroyOnHidden
|
|
||||||
>
|
>
|
||||||
<Form
|
<Form.Item name="instanceName" label="Name">
|
||||||
form={form}
|
<Input />
|
||||||
initialValues={{
|
</Form.Item>
|
||||||
host: "null", instanceClone: -1, saveMode: "none", startAfter: false,
|
<Tooltip title="Templates hold shared config for other instances and cannot be started">
|
||||||
template: null, asTemplate: false, linkSource: true, ...props.initial,
|
<Form.Item name="asTemplate" valuePropName="checked">
|
||||||
}}
|
<Checkbox>Create as template</Checkbox>
|
||||||
|
</Form.Item>
|
||||||
|
</Tooltip>
|
||||||
|
{canAssign && !asTemplate && <Form.Item name="host" label="Host">
|
||||||
|
<Select showSearch optionFilterProp="name">
|
||||||
|
<Select.Option value={"null"}>
|
||||||
|
<Typography.Text italic>Unassigned</Typography.Text>
|
||||||
|
</Select.Option>
|
||||||
|
{[...hosts.values()].sort((a, b) => strcmp(a.name, b.name)).map(h => <Select.Option
|
||||||
|
key={h.id}
|
||||||
|
value={h.id}
|
||||||
|
name={h.name}
|
||||||
|
disabled={!h.connected}
|
||||||
|
>
|
||||||
|
{h.name}
|
||||||
|
{!h.connected && " (offline)"}
|
||||||
|
</Select.Option>)}
|
||||||
|
</Select>
|
||||||
|
</Form.Item>}
|
||||||
|
<ConfigSourceFields
|
||||||
|
instances={props.instances}
|
||||||
|
templateId={templateId}
|
||||||
|
source={source}
|
||||||
|
asTemplate={asTemplate}
|
||||||
|
/>
|
||||||
|
{copySettings && <Tooltip
|
||||||
|
title="Name of the server as shown in the in-game server browser"
|
||||||
>
|
>
|
||||||
<Form.Item name="instanceName" label="Name">
|
<Form.Item name="serverName" label="Server Name">
|
||||||
<Input />
|
<Input />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Tooltip title="Templates hold shared config for other instances and cannot be started">
|
</Tooltip>}
|
||||||
<Form.Item name="asTemplate" valuePropName="checked">
|
{source && hostId !== undefined && <Form.Item name="saveMode" label="Copy Save">
|
||||||
<Checkbox>Create as template</Checkbox>
|
<Select
|
||||||
</Form.Item>
|
options={[
|
||||||
</Tooltip>
|
{ value: "none", label: "None" },
|
||||||
{canAssign && !asTemplate && <Form.Item name="host" label="Host">
|
{
|
||||||
<Select showSearch optionFilterProp="name">
|
value: "copy",
|
||||||
<Select.Option value={"null"}>
|
label: activeSave ? `Copy ${activeSave.name}` : "Copy active save",
|
||||||
<Typography.Text italic>Unassigned</Typography.Text>
|
disabled: !activeSave,
|
||||||
</Select.Option>
|
},
|
||||||
{[...hosts.values()].sort((a, b) => strcmp(a.name, b.name)).map(h => <Select.Option
|
{
|
||||||
key={h.id}
|
value: "save_and_copy",
|
||||||
value={h.id}
|
label: "Save the running game and copy it",
|
||||||
name={h.name}
|
disabled: !sourceRunning || !activeSave,
|
||||||
disabled={!h.connected}
|
},
|
||||||
>
|
]}
|
||||||
{h.name}
|
|
||||||
{!h.connected && " (offline)"}
|
|
||||||
</Select.Option>)}
|
|
||||||
</Select>
|
|
||||||
</Form.Item>}
|
|
||||||
<ConfigSourceFields
|
|
||||||
instances={props.instances}
|
|
||||||
templateId={templateId}
|
|
||||||
source={source}
|
|
||||||
asTemplate={asTemplate}
|
|
||||||
/>
|
/>
|
||||||
{copySettings && <Tooltip
|
</Form.Item>}
|
||||||
title="Name of the server as shown in the in-game server browser"
|
{hostId !== undefined && <Form.Item
|
||||||
>
|
name="startAfter"
|
||||||
<Form.Item name="serverName" label="Server Name">
|
valuePropName="checked"
|
||||||
<Input />
|
extra={saveMode === "none" ? "A new save is created if none is copied" : undefined}
|
||||||
</Form.Item>
|
>
|
||||||
</Tooltip>}
|
<Checkbox>Start after creation</Checkbox>
|
||||||
{source && hostId !== undefined && <Form.Item name="saveMode" label="Copy Save">
|
</Form.Item>}
|
||||||
<Select
|
</Form>
|
||||||
options={[
|
</Modal>;
|
||||||
{ value: "none", label: "None" },
|
|
||||||
{
|
|
||||||
value: "copy",
|
|
||||||
label: activeSave ? `Copy ${activeSave.name}` : "Copy active save",
|
|
||||||
disabled: !activeSave,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: "save_and_copy",
|
|
||||||
label: "Save the running game and copy it",
|
|
||||||
disabled: !sourceRunning || !activeSave,
|
|
||||||
},
|
|
||||||
]}
|
|
||||||
/>
|
|
||||||
</Form.Item>}
|
|
||||||
{hostId !== undefined && <Form.Item
|
|
||||||
name="startAfter"
|
|
||||||
valuePropName="checked"
|
|
||||||
extra={saveMode === "none" ? "A new save is created if none is copied" : undefined}
|
|
||||||
>
|
|
||||||
<Checkbox>Start after creation</Checkbox>
|
|
||||||
</Form.Item>}
|
|
||||||
</Form>
|
|
||||||
</Modal>
|
|
||||||
</>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function TemplateList(props: { instances: ReturnType<typeof useInstances>[0] }) {
|
function TemplateList(props: { instances: ReturnType<typeof useInstances>[0] }) {
|
||||||
|
|||||||
@@ -8,9 +8,10 @@ import { notifyErrorHandler } from "../util/notify";
|
|||||||
|
|
||||||
type LoadScenarioModalProps = {
|
type LoadScenarioModalProps = {
|
||||||
instance: lib.InstanceDetails;
|
instance: lib.InstanceDetails;
|
||||||
|
open: boolean;
|
||||||
|
onClose: () => void;
|
||||||
};
|
};
|
||||||
export default function LoadScenarioModal(props: LoadScenarioModalProps) {
|
export default function LoadScenarioModal(props: LoadScenarioModalProps) {
|
||||||
let [open, setOpen] = useState(false);
|
|
||||||
let [loadingScenario, setLoadingScenario] = useState(false);
|
let [loadingScenario, setLoadingScenario] = useState(false);
|
||||||
let [form] = Form.useForm();
|
let [form] = Form.useForm();
|
||||||
let control = useContext(ControlContext);
|
let control = useContext(ControlContext);
|
||||||
@@ -57,7 +58,7 @@ export default function LoadScenarioModal(props: LoadScenarioModalProps) {
|
|||||||
{ instanceId: props.instance.id },
|
{ instanceId: props.instance.id },
|
||||||
new lib.InstanceLoadScenarioRequest(scenario, seed, mapGenSettings, mapSettings),
|
new lib.InstanceLoadScenarioRequest(scenario, seed, mapGenSettings, mapSettings),
|
||||||
).then(() => {
|
).then(() => {
|
||||||
setOpen(false);
|
props.onClose();
|
||||||
}).catch(
|
}).catch(
|
||||||
notifyErrorHandler("Error loading scenario")
|
notifyErrorHandler("Error loading scenario")
|
||||||
).finally(() => {
|
).finally(() => {
|
||||||
@@ -81,58 +82,43 @@ export default function LoadScenarioModal(props: LoadScenarioModalProps) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleCancel() {
|
return <Modal
|
||||||
setOpen(false);
|
title="Load Scenario"
|
||||||
}
|
width={560}
|
||||||
|
okText="Load"
|
||||||
return <>
|
open={props.open}
|
||||||
<Button
|
confirmLoading={loadingScenario}
|
||||||
loading={loadingScenario}
|
onOk={loadScenario}
|
||||||
disabled={props.instance.status !== "stopped"}
|
onCancel={props.onClose}
|
||||||
onClick={() => {
|
destroyOnHidden
|
||||||
setOpen(true);
|
>
|
||||||
}}
|
<Form form={form} layout="vertical">
|
||||||
>
|
<Form.Item name="scenario" label="Scenario">
|
||||||
Load scenario
|
<Input placeholder="base/freeplay" />
|
||||||
</Button>
|
</Form.Item>
|
||||||
<Modal
|
<Form.Item name="seed" label="Seed">
|
||||||
title="Load Scenario"
|
<Input type="number" />
|
||||||
width={560}
|
</Form.Item>
|
||||||
okText="Load"
|
<Form.Item name="exchangeString" label="Map Exchange String">
|
||||||
open={open}
|
<Input.TextArea allowClear={true} autoSize={{ minRows: 3 }} />
|
||||||
confirmLoading={loadingScenario}
|
</Form.Item>
|
||||||
onOk={loadScenario}
|
<div style={{ textAlign: "right", marginTop: -8 }}>
|
||||||
onCancel={handleCancel}
|
<Button onClick={() => convertExchangeString()}>Convert to settings</Button>
|
||||||
destroyOnHidden
|
</div>
|
||||||
>
|
<Form.Item
|
||||||
<Form form={form} layout="vertical">
|
name="mapGenSettings"
|
||||||
<Form.Item name="scenario" label="Scenario">
|
label="Map Gen Settings"
|
||||||
<Input placeholder="base/freeplay" />
|
tooltip="JSON data to pass to Factorio with --map-gen-settings, overrides Map Exchange String"
|
||||||
</Form.Item>
|
>
|
||||||
<Form.Item name="seed" label="Seed">
|
<Input.TextArea allowClear={true} autoSize={{ minRows: 1 }} />
|
||||||
<Input type="number" />
|
</Form.Item>
|
||||||
</Form.Item>
|
<Form.Item
|
||||||
<Form.Item name="exchangeString" label="Map Exchange String">
|
name="mapSettings"
|
||||||
<Input.TextArea allowClear={true} autoSize={{ minRows: 3 }} />
|
label="Map Settings"
|
||||||
</Form.Item>
|
tooltip="JSON data to pass to Factorio with --map-settings, overrides Map Exchange String"
|
||||||
<div style={{ textAlign: "right", marginTop: -8 }}>
|
>
|
||||||
<Button onClick={() => convertExchangeString()}>Convert to settings</Button>
|
<Input.TextArea allowClear={true} autoSize={{ minRows: 1 }} />
|
||||||
</div>
|
</Form.Item>
|
||||||
<Form.Item
|
</Form>
|
||||||
name="mapGenSettings"
|
</Modal>;
|
||||||
label="Map Gen Settings"
|
|
||||||
tooltip="JSON data to pass to Factorio with --map-gen-settings, overrides Map Exchange String"
|
|
||||||
>
|
|
||||||
<Input.TextArea allowClear={true} autoSize={{ minRows: 1 }} />
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item
|
|
||||||
name="mapSettings"
|
|
||||||
label="Map Settings"
|
|
||||||
tooltip="JSON data to pass to Factorio with --map-settings, overrides Map Exchange String"
|
|
||||||
>
|
|
||||||
<Input.TextArea allowClear={true} autoSize={{ minRows: 1 }} />
|
|
||||||
</Form.Item>
|
|
||||||
</Form>
|
|
||||||
</Modal>
|
|
||||||
</>;
|
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import { Collapse } from "antd";
|
import { Collapse, ConfigProvider } from "antd";
|
||||||
|
|
||||||
import { useUsers } from "../model/user";
|
import { useUsers } from "../model/user";
|
||||||
import UsersTable from "./UsersTable";
|
import UsersTable from "./UsersTable";
|
||||||
@@ -24,12 +24,15 @@ export default function OnlinePlayersList({ instanceId }: OnlinePlayersListProps
|
|||||||
items={[{
|
items={[{
|
||||||
key: "players",
|
key: "players",
|
||||||
label: `Online Players (${onlineCount})`,
|
label: `Online Players (${onlineCount})`,
|
||||||
children: <UsersTable instanceId={instanceId} onlyOnline size="small" pagination={{
|
styles: { body: { padding: 0 } },
|
||||||
defaultPageSize: 10,
|
children: <ConfigProvider theme={{ components: { Table: { headerBorderRadius: 0 } } }}>
|
||||||
showSizeChanger: true,
|
<UsersTable instanceId={instanceId} onlyOnline size="small" pagination={{
|
||||||
pageSizeOptions: ["10", "20", "50", "100", "200"],
|
defaultPageSize: 10,
|
||||||
showTotal: (total: number) => `${total} Users`,
|
showSizeChanger: true,
|
||||||
}} />,
|
pageSizeOptions: ["10", "20", "50", "100", "200"],
|
||||||
|
showTotal: (total: number) => `${total} Users`,
|
||||||
|
}} />
|
||||||
|
</ConfigProvider>,
|
||||||
}]}
|
}]}
|
||||||
/>;
|
/>;
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import React from "react";
|
import React, { useEffect } from "react";
|
||||||
import { Layout, Breadcrumb } from "antd";
|
import { Layout, Breadcrumb } from "antd";
|
||||||
import Link from "./Link";
|
import Link from "./Link";
|
||||||
|
|
||||||
@@ -11,7 +11,19 @@ type PageLayoutProps = {
|
|||||||
}[];
|
}[];
|
||||||
children?: any;
|
children?: any;
|
||||||
};
|
};
|
||||||
|
function clusterName() {
|
||||||
|
const meta = document.querySelector<HTMLMetaElement>("meta[name=application-name]");
|
||||||
|
return meta?.content || "Clusterio";
|
||||||
|
}
|
||||||
|
|
||||||
export default function PageLayout(props: PageLayoutProps) {
|
export default function PageLayout(props: PageLayoutProps) {
|
||||||
|
const page = props.nav.at(-1)?.name;
|
||||||
|
useEffect(() => {
|
||||||
|
const name = clusterName();
|
||||||
|
document.title = page ? `${page} - ${name}` : name;
|
||||||
|
return () => { document.title = name; };
|
||||||
|
}, [page]);
|
||||||
|
|
||||||
return <>
|
return <>
|
||||||
<Breadcrumb
|
<Breadcrumb
|
||||||
className="site-breadcrumb"
|
className="site-breadcrumb"
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import { useRole } from "../model/roles";
|
|||||||
import { useAccount } from "../model/account";
|
import { useAccount } from "../model/account";
|
||||||
import ControlContext from "./ControlContext";
|
import ControlContext from "./ControlContext";
|
||||||
import PageHeader from "./PageHeader";
|
import PageHeader from "./PageHeader";
|
||||||
|
import UnsavedChangesBar from "./UnsavedChangesBar";
|
||||||
|
import FieldRow from "./FieldRow";
|
||||||
import PageLayout from "./PageLayout";
|
import PageLayout from "./PageLayout";
|
||||||
import PluginExtra from "./PluginExtra";
|
import PluginExtra from "./PluginExtra";
|
||||||
import ResourceNotes from "./ResourceNotes";
|
import ResourceNotes from "./ResourceNotes";
|
||||||
@@ -292,46 +294,15 @@ export default function RoleViewPage() {
|
|||||||
</Space>}
|
</Space>}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{edited && (
|
{edited && <UnsavedChangesBar onRevert={revertChanges} onApply={applyChanges} />}
|
||||||
<div style={{
|
|
||||||
position: "fixed",
|
|
||||||
bottom: 24,
|
|
||||||
left: "50%",
|
|
||||||
transform: "translateX(-50%)",
|
|
||||||
background: "#2a1912",
|
|
||||||
borderRadius: 8,
|
|
||||||
boxShadow: "0 8px 24px rgba(0,0,0,0.12)",
|
|
||||||
padding: "10px 14px",
|
|
||||||
display: "flex",
|
|
||||||
alignItems: "center",
|
|
||||||
gap: 12,
|
|
||||||
zIndex: 1000,
|
|
||||||
}}>
|
|
||||||
<span style={{ color: "#FFF" }}>
|
|
||||||
You have unsaved changes
|
|
||||||
</span>
|
|
||||||
|
|
||||||
<Space>
|
<FieldRow label="Name">
|
||||||
<Button onClick={revertChanges}>
|
|
||||||
Revert
|
|
||||||
</Button>
|
|
||||||
|
|
||||||
<Button type="primary" onClick={applyChanges}>
|
|
||||||
Apply
|
|
||||||
</Button>
|
|
||||||
</Space>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<div style={{ marginBottom: 16, display: "flex", alignItems: "center", gap: 12 }}>
|
|
||||||
<label style={{ width: 110, flexShrink: 0 }}>Name</label>
|
|
||||||
<Input value={name} disabled={!canUpdate} onChange={e => setNameEdit(e.target.value)} />
|
<Input value={name} disabled={!canUpdate} onChange={e => setNameEdit(e.target.value)} />
|
||||||
</div>
|
</FieldRow>
|
||||||
|
|
||||||
<div style={{ marginBottom: 16, display: "flex", alignItems: "center", gap: 12 }}>
|
<FieldRow label="Description">
|
||||||
<label style={{ width: 110, flexShrink: 0 }}>Description</label>
|
|
||||||
<Input value={description} disabled={!canUpdate} onChange={e => setDescriptionEdit(e.target.value)} />
|
<Input value={description} disabled={!canUpdate} onChange={e => setDescriptionEdit(e.target.value)} />
|
||||||
</div>
|
</FieldRow>
|
||||||
|
|
||||||
<ResourceNotes resourceType="role" resourceId={roleId} />
|
<ResourceNotes resourceType="role" resourceId={roleId} />
|
||||||
|
|
||||||
|
|||||||
@@ -69,16 +69,16 @@ function RenameModal(props: ModalProps) {
|
|||||||
</>;
|
</>;
|
||||||
}
|
}
|
||||||
|
|
||||||
function CopyModal(props: ModalProps) {
|
function DuplicateModal(props: ModalProps) {
|
||||||
let control = useContext(ControlContext);
|
let control = useContext(ControlContext);
|
||||||
let [open, setOpen] = useState(false);
|
let [open, setOpen] = useState(false);
|
||||||
let [form] = Form.useForm();
|
let [form] = Form.useForm();
|
||||||
|
|
||||||
return <>
|
return <>
|
||||||
<Button disabled={props.disabled} onClick={() => setOpen(true)}>Copy</Button>
|
<Button disabled={props.disabled} onClick={() => setOpen(true)}>Duplicate</Button>
|
||||||
<Modal
|
<Modal
|
||||||
title="Copy save"
|
title="Duplicate save"
|
||||||
okText="Copy"
|
okText="Duplicate"
|
||||||
open={open}
|
open={open}
|
||||||
onOk={() => form.submit()}
|
onOk={() => form.submit()}
|
||||||
onCancel={() => setOpen(false)}
|
onCancel={() => setOpen(false)}
|
||||||
@@ -93,7 +93,7 @@ function CopyModal(props: ModalProps) {
|
|||||||
).then(() => {
|
).then(() => {
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
form.resetFields();
|
form.resetFields();
|
||||||
}).catch(notifyErrorHandler("Error copying save"));
|
}).catch(notifyErrorHandler("Error duplicating save"));
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Form.Item
|
<Form.Item
|
||||||
@@ -383,11 +383,11 @@ export default function SavesList(props: { instance: lib.InstanceDetails }) {
|
|||||||
() => { setStarting(false); }
|
() => { setStarting(false); }
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
>Load save</Button>}
|
>Load</Button>}
|
||||||
{account.hasPermission("core.instance.save.rename") && <RenameModal
|
{account.hasPermission("core.instance.save.rename") && <RenameModal
|
||||||
disabled={hostOffline} instanceId={props.instance.id!} save={save}
|
disabled={hostOffline} instanceId={props.instance.id!} save={save}
|
||||||
/>}
|
/>}
|
||||||
{account.hasPermission("core.instance.save.copy") && <CopyModal
|
{account.hasPermission("core.instance.save.copy") && <DuplicateModal
|
||||||
disabled={hostOffline} instanceId={props.instance.id!} save={save}
|
disabled={hostOffline} instanceId={props.instance.id!} save={save}
|
||||||
/>}
|
/>}
|
||||||
{account.hasPermission("core.instance.save.download") && <Button
|
{account.hasPermission("core.instance.save.download") && <Button
|
||||||
@@ -444,9 +444,7 @@ export default function SavesList(props: { instance: lib.InstanceDetails }) {
|
|||||||
onDone={setSelectedNames}
|
onDone={setSelectedNames}
|
||||||
/>}
|
/>}
|
||||||
{account.hasPermission("core.instance.save.upload") && <Upload {...uploadProps} >
|
{account.hasPermission("core.instance.save.upload") && <Upload {...uploadProps} >
|
||||||
<UploadButton disabled={hostOffline}>
|
<UploadButton disabled={hostOffline} icon={null} />
|
||||||
Upload save
|
|
||||||
</UploadButton>
|
|
||||||
</Upload>}
|
</Upload>}
|
||||||
{account.hasPermission("core.instance.save.create") && <CreateSaveModal instance={props.instance} />}
|
{account.hasPermission("core.instance.save.create") && <CreateSaveModal instance={props.instance} />}
|
||||||
</Space>} />
|
</Space>} />
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
import React from "react";
|
||||||
|
import { Button, Space } from "antd";
|
||||||
|
|
||||||
|
type UnsavedChangesBarProps = {
|
||||||
|
onRevert: () => void;
|
||||||
|
onApply: () => void;
|
||||||
|
applying?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Floating bar shown while a page has edits that are not applied yet */
|
||||||
|
export default function UnsavedChangesBar(props: UnsavedChangesBarProps) {
|
||||||
|
return <div style={{
|
||||||
|
position: "fixed",
|
||||||
|
bottom: 24,
|
||||||
|
left: "50%",
|
||||||
|
transform: "translateX(-50%)",
|
||||||
|
background: "#2a1912",
|
||||||
|
borderRadius: 8,
|
||||||
|
boxShadow: "0 8px 24px rgba(0,0,0,0.12)",
|
||||||
|
padding: "10px 14px",
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
gap: 12,
|
||||||
|
zIndex: 1000,
|
||||||
|
}}>
|
||||||
|
<span style={{ color: "#FFF" }}>
|
||||||
|
You have unsaved changes
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<Space>
|
||||||
|
<Button onClick={props.onRevert}>
|
||||||
|
Revert
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Button type="primary" loading={props.applying} onClick={props.onApply}>
|
||||||
|
Apply
|
||||||
|
</Button>
|
||||||
|
</Space>
|
||||||
|
</div>;
|
||||||
|
}
|
||||||
@@ -7,6 +7,8 @@ import { DraggingContext } from "../model/is_dragging";
|
|||||||
export default function UploadButton(props: React.ComponentProps<typeof Button>) {
|
export default function UploadButton(props: React.ComponentProps<typeof Button>) {
|
||||||
const isDroppingFile = useContext(DraggingContext);
|
const isDroppingFile = useContext(DraggingContext);
|
||||||
const borderColor = props.disabled ? "gray" : "rgb(22, 119, 255)";
|
const borderColor = props.disabled ? "gray" : "rgb(22, 119, 255)";
|
||||||
|
// Pass icon={null} for no icon
|
||||||
|
const icon = props.icon === undefined ? <UploadOutlined /> : props.icon;
|
||||||
return <Button
|
return <Button
|
||||||
className={`dropzone ${props.disabled ? "disabled" : "enabled"}`}
|
className={`dropzone ${props.disabled ? "disabled" : "enabled"}`}
|
||||||
{...props}
|
{...props}
|
||||||
@@ -15,7 +17,7 @@ export default function UploadButton(props: React.ComponentProps<typeof Button>)
|
|||||||
// Distinct border when dropping file
|
// Distinct border when dropping file
|
||||||
border: isDroppingFile ? `dashed 2px ${borderColor}` : undefined,
|
border: isDroppingFile ? `dashed 2px ${borderColor}` : undefined,
|
||||||
}}
|
}}
|
||||||
icon={isDroppingFile ? <InboxOutlined /> : props.icon || <UploadOutlined />}
|
icon={isDroppingFile ? <InboxOutlined /> : icon}
|
||||||
>
|
>
|
||||||
{props.children || "Upload"}
|
{props.children || "Upload"}
|
||||||
</Button>;
|
</Button>;
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
import React, { useEffect, useContext, useState } from "react";
|
import React, { useEffect, useContext, useState } from "react";
|
||||||
import { useNavigate, useParams } from "react-router-dom";
|
import { useNavigate, useParams } from "react-router-dom";
|
||||||
import {
|
import {
|
||||||
Button, Col, Descriptions, Dropdown, Form, Input, Popconfirm,
|
Button, Descriptions, Dropdown, Input, Popconfirm, Table, Tag, Select, Space, Switch,
|
||||||
Row, Table, Tag, Select, Space, Switch,
|
|
||||||
} from "antd";
|
} from "antd";
|
||||||
import DeleteOutlined from "@ant-design/icons/DeleteOutlined";
|
import DeleteOutlined from "@ant-design/icons/DeleteOutlined";
|
||||||
import DownOutlined from "@ant-design/icons/DownOutlined";
|
import DownOutlined from "@ant-design/icons/DownOutlined";
|
||||||
@@ -14,12 +13,14 @@ import useTableQueryState from "../util/useTableQueryState";
|
|||||||
import { useAccount } from "../model/account";
|
import { useAccount } from "../model/account";
|
||||||
import { useInstances } from "../model/instance";
|
import { useInstances } from "../model/instance";
|
||||||
import ControlContext from "./ControlContext";
|
import ControlContext from "./ControlContext";
|
||||||
|
import FieldRow from "./FieldRow";
|
||||||
import PageHeader from "./PageHeader";
|
import PageHeader from "./PageHeader";
|
||||||
import PageLayout from "./PageLayout";
|
import PageLayout from "./PageLayout";
|
||||||
import PluginExtra from "./PluginExtra";
|
import PluginExtra from "./PluginExtra";
|
||||||
import SectionHeader from "./SectionHeader";
|
import SectionHeader from "./SectionHeader";
|
||||||
import ResourceNotes from "./ResourceNotes";
|
import ResourceNotes from "./ResourceNotes";
|
||||||
import ResourceState from "./ResourceState";
|
import ResourceState from "./ResourceState";
|
||||||
|
import UnsavedChangesBar from "./UnsavedChangesBar";
|
||||||
import useRowNavigation from "../util/useRowNavigation";
|
import useRowNavigation from "../util/useRowNavigation";
|
||||||
import useResourceState from "../util/useResourceState";
|
import useResourceState from "../util/useResourceState";
|
||||||
import usePluginActions from "../util/usePluginActions";
|
import usePluginActions from "../util/usePluginActions";
|
||||||
@@ -30,6 +31,10 @@ import { formatFirstSeen, formatLastSeen, sortFirstSeen, sortLastSeen, useUser }
|
|||||||
|
|
||||||
const strcmp = new Intl.Collator(undefined, { numeric: true, sensitivity: "base" }).compare;
|
const strcmp = new Intl.Collator(undefined, { numeric: true, sensitivity: "base" }).compare;
|
||||||
|
|
||||||
|
function sameIds(ids: number[], set: Set<number>) {
|
||||||
|
return ids.length === set.size && ids.every(id => set.has(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function UserPluginActions(props: { user: lib.UserDetails }) {
|
function UserPluginActions(props: { user: lib.UserDetails }) {
|
||||||
const pluginActions = usePluginActions("UserViewPage", { user: props.user });
|
const pluginActions = usePluginActions("UserViewPage", { user: props.user });
|
||||||
@@ -57,66 +62,66 @@ export default function UserViewPage() {
|
|||||||
const [user, synced, error] = useUser(userName);
|
const [user, synced, error] = useUser(userName);
|
||||||
const state = useResourceState(user, synced, error, userName);
|
const state = useResourceState(user, synced, error, userName);
|
||||||
let [roles, rolesSynced] = useRoles();
|
let [roles, rolesSynced] = useRoles();
|
||||||
let [form] = Form.useForm();
|
|
||||||
const statsTable = useTableQueryState<[number, lib.PlayerStats]>({
|
const statsTable = useTableQueryState<[number, lib.PlayerStats]>({
|
||||||
namespace: "stats", defaultSortKey: "instance",
|
namespace: "stats", defaultSortKey: "instance",
|
||||||
});
|
});
|
||||||
let [rolesDirty, setRolesDirty] = useState<boolean>(false);
|
// Local edits on top of the live user
|
||||||
let [banReasonDirty, setBanReasonDirty] = useState<boolean>(false);
|
const [rolesEdit, setRolesEdit] = useState<number[]>();
|
||||||
let [applyingRoles, setApplyingRoles] = useState<boolean>(false);
|
const [bannedEdit, setBannedEdit] = useState<boolean>();
|
||||||
let [rolesError, setRolesError] = useState<string|undefined>();
|
const [banReasonEdit, setBanReasonEdit] = useState<string>();
|
||||||
|
const [applying, setApplying] = useState(false);
|
||||||
|
const canUpdateRoles = account.hasPermission("core.user.update_roles");
|
||||||
|
const canBan = account.hasPermission("core.user.set_banned");
|
||||||
|
const canSetAdmin = account.hasPermission("core.user.set_admin");
|
||||||
|
const canSetWhitelisted = account.hasPermission("core.user.set_whitelisted");
|
||||||
|
|
||||||
|
// Drop edits that now match the user, and roles deleted since
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (
|
if (!user) {
|
||||||
account.hasPermission("core.user.set_banned")
|
|
||||||
&& !banReasonDirty
|
|
||||||
&& user
|
|
||||||
&& user.banReason !== form.getFieldValue("banReason")
|
|
||||||
) {
|
|
||||||
form.setFieldsValue({ "banReason": user.banReason });
|
|
||||||
}
|
|
||||||
}, [account, form, user, banReasonDirty]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!user || !account.hasPermission("core.user.update_roles")) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const current: number[] = form.getFieldValue("roles") ?? [];
|
setRolesEdit(prev => {
|
||||||
// Keep local edits, but drop roles deleted since
|
const next = prev?.filter(id => !rolesSynced || roles.has(id));
|
||||||
const next = rolesDirty
|
return next && sameIds(next, user.roleIds) ? undefined : next;
|
||||||
? current.filter(id => !rolesSynced || roles.has(id))
|
});
|
||||||
: [...user.roleIds];
|
setBannedEdit(prev => (prev === user.isBanned ? undefined : prev));
|
||||||
if (next.length !== current.length || next.some((id, i) => id !== current[i])) {
|
setBanReasonEdit(prev => (prev === user.banReason ? undefined : prev));
|
||||||
form.setFieldsValue({ "roles": next });
|
}, [user, roles, rolesSynced]);
|
||||||
}
|
|
||||||
}, [account, form, user, roles, rolesSynced, rolesDirty]);
|
useEffect(() => {
|
||||||
|
setRolesEdit(undefined);
|
||||||
|
setBannedEdit(undefined);
|
||||||
|
setBanReasonEdit(undefined);
|
||||||
|
}, [userName]);
|
||||||
|
|
||||||
let nav = [{ name: "Users", path: "/users" }, { name: userName }];
|
let nav = [{ name: "Users", path: "/users" }, { name: userName }];
|
||||||
if (!user) {
|
if (!user) {
|
||||||
return <ResourceState state={state} type="User" id={userName} nav={nav} listPath="/users" error={error} />;
|
return <ResourceState state={state} type="User" id={userName} nav={nav} listPath="/users" error={error} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
let roleSelector = <Form.Item
|
const roleIds = rolesEdit ?? [...user.roleIds];
|
||||||
noStyle
|
const banned = bannedEdit ?? user.isBanned;
|
||||||
name="roles"
|
const banReason = banned ? banReasonEdit ?? user.banReason : "";
|
||||||
initialValue={[...user.roleIds]}
|
const rolesChanged = rolesEdit !== undefined && !sameIds(rolesEdit, user.roleIds);
|
||||||
rules={[
|
const banChanged = banned !== user.isBanned || banReason !== user.banReason;
|
||||||
{ validator: () => (rolesError ? Promise.reject(rolesError) : Promise.resolve()) },
|
|
||||||
]}
|
function revertChanges() {
|
||||||
>
|
setRolesEdit(undefined);
|
||||||
<Select
|
setBannedEdit(undefined);
|
||||||
onChange={() => setRolesDirty(true)}
|
setBanReasonEdit(undefined);
|
||||||
loading={!roles}
|
}
|
||||||
mode="multiple"
|
|
||||||
optionFilterProp="name"
|
async function applyChanges() {
|
||||||
>
|
if (rolesChanged) {
|
||||||
{[...roles.values()].map(r => <Select.Option
|
await control.send(new lib.UserUpdateRolesRequest(userName, roleIds));
|
||||||
key={r.id}
|
setRolesEdit(undefined);
|
||||||
value={r.id}
|
}
|
||||||
name={r.name}
|
if (banChanged) {
|
||||||
>{r.name}</Select.Option>)}
|
await control.send(new lib.UserSetBannedRequest(userName, false, banned, banReason));
|
||||||
</Select>
|
setBannedEdit(undefined);
|
||||||
</Form.Item>;
|
setBanReasonEdit(undefined);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function instanceName(id: number) {
|
function instanceName(id: number) {
|
||||||
return instances.get(id)?.name ?? String(id);
|
return instances.get(id)?.name ?? String(id);
|
||||||
@@ -182,134 +187,64 @@ export default function UserViewPage() {
|
|||||||
<UserPluginActions user={user} />
|
<UserPluginActions user={user} />
|
||||||
</Space>}
|
</Space>}
|
||||||
/>
|
/>
|
||||||
<Form
|
{(rolesChanged || banChanged) && <UnsavedChangesBar
|
||||||
form={form}
|
applying={applying}
|
||||||
labelCol={{
|
onRevert={revertChanges}
|
||||||
sm: { span: 6 },
|
onApply={() => {
|
||||||
md: { span: 6 },
|
setApplying(true);
|
||||||
lg: { span: 4 },
|
applyChanges()
|
||||||
xl: { span: 3 },
|
.catch(notifyErrorHandler("Error applying changes"))
|
||||||
xxl: { span: 2 },
|
.finally(() => setApplying(false));
|
||||||
}}
|
}}
|
||||||
wrapperCol={{
|
/>}
|
||||||
sm: { span: 18 },
|
<FieldRow label="Roles">
|
||||||
md: { span: 18 },
|
<Select
|
||||||
lg: { span: 20 },
|
style={{ width: "100%" }}
|
||||||
xl: { span: 21 },
|
mode="multiple"
|
||||||
xxl: { span: 22 },
|
disabled={!canUpdateRoles}
|
||||||
}}
|
value={roleIds}
|
||||||
>
|
onChange={setRolesEdit}
|
||||||
<Form.Item
|
optionFilterProp="label"
|
||||||
label="Roles"
|
options={[...roles.values()].map(r => ({ value: r.id, label: r.name }))}
|
||||||
>
|
/>
|
||||||
<Row gutter={[8, 8]}>
|
</FieldRow>
|
||||||
<Col flex="auto">
|
{(canSetAdmin || canSetWhitelisted || canBan) && <FieldRow label="Status">
|
||||||
{account.hasPermission("core.user.update_roles")
|
<Space size="large" wrap>
|
||||||
? roleSelector
|
{canSetAdmin && <label><Space>
|
||||||
: [...user.roleIds!].map(id => <Tag key={id}>{
|
In-game Admin
|
||||||
roles?.get(id)?.name ?? id
|
<Switch
|
||||||
}</Tag>)
|
checked={user.isAdmin}
|
||||||
}
|
onClick={() => {
|
||||||
</Col>
|
control.send(
|
||||||
{account.hasPermission("core.user.update_roles") && <Col flex="0 0 auto">
|
new lib.UserSetAdminRequest(userName, false, !user.isAdmin)
|
||||||
<Button
|
).catch(notifyErrorHandler("Error toggling user admin status"));
|
||||||
type={"primary"}
|
}}
|
||||||
disabled={!rolesDirty}
|
/>
|
||||||
loading={applyingRoles}
|
</Space></label>}
|
||||||
onClick={() => {
|
{canSetWhitelisted && <label><Space>
|
||||||
let newRoles = form.getFieldValue("roles");
|
Whitelisted
|
||||||
setApplyingRoles(true);
|
<Switch
|
||||||
control.send(
|
checked={user.isWhitelisted}
|
||||||
new lib.UserUpdateRolesRequest(userName, newRoles)
|
onClick={() => {
|
||||||
).then(() => {
|
control.send(
|
||||||
setRolesDirty(false);
|
new lib.UserSetWhitelistedRequest(userName, false, !user.isWhitelisted)
|
||||||
setRolesError(undefined);
|
).catch(notifyErrorHandler("Error toggling user whitelisted status"));
|
||||||
}).catch(err => {
|
}}
|
||||||
setRolesError(err.message);
|
/>
|
||||||
return form.validateFields();
|
</Space></label>}
|
||||||
}).finally(() => {
|
{canBan && <label><Space>
|
||||||
setApplyingRoles(false);
|
Banned
|
||||||
});
|
<Switch checked={banned} onClick={() => setBannedEdit(!banned)} />
|
||||||
}}
|
</Space></label>}
|
||||||
>Apply</Button>
|
</Space>
|
||||||
</Col>}
|
</FieldRow>}
|
||||||
</Row>
|
{banned && <FieldRow label="Ban reason">
|
||||||
</Form.Item>
|
<Input
|
||||||
{account.hasPermission("core.user.set_admin") && <Form.Item label="In-game Admin">
|
value={banReason}
|
||||||
<Switch
|
disabled={!canBan}
|
||||||
checked={user.isAdmin}
|
onChange={e => setBanReasonEdit(e.target.value)}
|
||||||
onClick={() => {
|
/>
|
||||||
control.send(
|
</FieldRow>}
|
||||||
new lib.UserSetAdminRequest(userName, false, !user.isAdmin)
|
|
||||||
).catch(notifyErrorHandler("Error toggling user admin status"));
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</Form.Item>}
|
|
||||||
{account.hasPermission("core.user.set_whitelisted") && <Form.Item label="Whitelisted">
|
|
||||||
<Switch
|
|
||||||
checked={user.isWhitelisted}
|
|
||||||
onClick={() => {
|
|
||||||
control.send(
|
|
||||||
new lib.UserSetWhitelistedRequest(userName, false, !user.isWhitelisted)
|
|
||||||
).catch(notifyErrorHandler("Error toggling user whitelisted status"));
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</Form.Item>}
|
|
||||||
{account.hasPermission("core.user.set_banned")
|
|
||||||
? <Form.Item label="Ban reason">
|
|
||||||
<Row gutter={[8, 8]} justify={"end"}>
|
|
||||||
<Col flex="auto" style={{ minWidth: "20em" }}>
|
|
||||||
<Form.Item noStyle name="banReason" initialValue={user.banReason}>
|
|
||||||
<Input
|
|
||||||
onChange={e => {
|
|
||||||
setBanReasonDirty(e.target.value !== user.banReason);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</Form.Item>
|
|
||||||
</Col>
|
|
||||||
<Col flex="0 0 auto">
|
|
||||||
{user.isBanned
|
|
||||||
? <Space>
|
|
||||||
<Button
|
|
||||||
type={banReasonDirty ? "primary" : "default"}
|
|
||||||
onClick={() => {
|
|
||||||
control.send(
|
|
||||||
new lib.UserSetBannedRequest(
|
|
||||||
userName, false, true, form.getFieldValue("banReason")
|
|
||||||
)
|
|
||||||
).then(() => {
|
|
||||||
setBanReasonDirty(false);
|
|
||||||
}).catch(notifyErrorHandler("Error updating ban"));
|
|
||||||
}}
|
|
||||||
>Update</Button>
|
|
||||||
<Button
|
|
||||||
onClick={() => {
|
|
||||||
control.send(
|
|
||||||
new lib.UserSetBannedRequest(userName, false, false, "")
|
|
||||||
).catch(notifyErrorHandler("Error unbanning user"));
|
|
||||||
}}
|
|
||||||
>Unban</Button>
|
|
||||||
</Space>
|
|
||||||
: <Button
|
|
||||||
type={banReasonDirty ? "primary" : "default"}
|
|
||||||
onClick={() => {
|
|
||||||
control.send(
|
|
||||||
new lib.UserSetBannedRequest(
|
|
||||||
userName, false, true, form.getFieldValue("banReason")
|
|
||||||
)
|
|
||||||
).then(() => {
|
|
||||||
setBanReasonDirty(false);
|
|
||||||
}).catch(notifyErrorHandler("Error banning user"));
|
|
||||||
}}
|
|
||||||
>Ban</Button>
|
|
||||||
}
|
|
||||||
</Col>
|
|
||||||
</Row>
|
|
||||||
</Form.Item>
|
|
||||||
: user.isBanned
|
|
||||||
&& <Form.Item label="Ban reason">{user.banReason}</Form.Item>
|
|
||||||
}
|
|
||||||
</Form>
|
|
||||||
<ResourceNotes resourceType="user" resourceId={user.id} />
|
<ResourceNotes resourceType="user" resourceId={user.id} />
|
||||||
<SectionHeader title="Player stats" />
|
<SectionHeader title="Player stats" />
|
||||||
<Descriptions size="small" bordered column={{ xs: 1, sm: 2, md: 2, lg: 2, xl: 2, xxl: 2 }}>
|
<Descriptions size="small" bordered column={{ xs: 1, sm: 2, md: 2, lg: 2, xl: 2, xxl: 2 }}>
|
||||||
|
|||||||
@@ -369,9 +369,10 @@ describe("controller/src/Controller", function() {
|
|||||||
|
|
||||||
describe(".serveWeb()", function() {
|
describe(".serveWeb()", function() {
|
||||||
let server, port;
|
let server, port;
|
||||||
|
const config = new Map([["controller.name", "Test Cluster"], ["controller.favicon_url", null]]);
|
||||||
before(async function() {
|
before(async function() {
|
||||||
const app = express();
|
const app = express();
|
||||||
app.locals.controller = { config: { get: () => "Test Cluster" } };
|
app.locals.controller = { config: { get: field => config.get(field) } };
|
||||||
app.locals.webBundle = {
|
app.locals.webBundle = {
|
||||||
main: "static/main.abc.js",
|
main: "static/main.abc.js",
|
||||||
imports: { "react": "static/shared-react.abc.js" },
|
imports: { "react": "static/shared-react.abc.js" },
|
||||||
@@ -405,6 +406,33 @@ describe("controller/src/Controller", function() {
|
|||||||
assert(html.includes("src=\"../../../static/main.abc.js\""));
|
assert(html.includes("src=\"../../../static/main.abc.js\""));
|
||||||
assert(html.includes("new URL(\"../../../static/\", document.location)"));
|
assert(html.includes("new URL(\"../../../static/\", document.location)"));
|
||||||
});
|
});
|
||||||
|
it("should escape the cluster name", async function() {
|
||||||
|
config.set("controller.name", "A&B \"<x>\"");
|
||||||
|
try {
|
||||||
|
const html = await (await fetch(`http://localhost:${port}/`)).text();
|
||||||
|
assert(html.includes("<title>A&B "<x>"</title>"));
|
||||||
|
assert(html.includes('<meta name="application-name" content="A&B "<x>"" />'));
|
||||||
|
} finally {
|
||||||
|
config.set("controller.name", "Test Cluster");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
it("should link favicon_url relative to the web root", async function() {
|
||||||
|
let html = await (await fetch(`http://localhost:${port}/`)).text();
|
||||||
|
assert(!html.includes("rel=\"icon\""));
|
||||||
|
try {
|
||||||
|
config.set("controller.favicon_url", "static/icon.png");
|
||||||
|
html = await (await fetch(`http://localhost:${port}/instances/1/view`)).text();
|
||||||
|
assert(html.includes('<link rel="icon" href="../../static/icon.png" />'));
|
||||||
|
config.set("controller.favicon_url", "https://example.com/icon.png?a=1&b=2");
|
||||||
|
html = await (await fetch(`http://localhost:${port}/instances/1/view`)).text();
|
||||||
|
assert(html.includes('<link rel="icon" href="https://example.com/icon.png?a=1&b=2" />'));
|
||||||
|
config.set("controller.favicon_url", "/icon.png");
|
||||||
|
html = await (await fetch(`http://localhost:${port}/instances/1/view`)).text();
|
||||||
|
assert(html.includes('<link rel="icon" href="/icon.png" />'));
|
||||||
|
} finally {
|
||||||
|
config.set("controller.favicon_url", null);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
describe(".parseTrustedProxies()", function() {
|
describe(".parseTrustedProxies()", function() {
|
||||||
it("should parse addresses", function() {
|
it("should parse addresses", function() {
|
||||||
|
|||||||
Reference in new issue
Block a user