mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-19 15:33:12 +09:00
Implement save transfer
Add ability to move or copy saves between instances. For instances on the same slave the saves are transferred with filesystem operations, for instances on two different slaves the proxy stream interface is used to send the save via the master server.
This commit is contained in:
1 parent
2e1c1fd3c8
commit
38c249ec70
8 files changed
+405
-2
No files matched your search
@@ -1,5 +1,8 @@
|
||||
import React, { useContext, useState } from "react";
|
||||
import { Button, Form, Input, List, Modal, Popconfirm, Progress, Space, Table, Tooltip, Upload } from "antd";
|
||||
import {
|
||||
message, Button, Checkbox, Form, Input, List, Modal,
|
||||
Popconfirm, Progress, Select, Space, Table, Tooltip, Upload,
|
||||
} from "antd";
|
||||
import CaretLeftOutlined from "@ant-design/icons/CaretLeftOutlined";
|
||||
import LeftOutlined from "@ant-design/icons/LeftOutlined";
|
||||
|
||||
@@ -9,6 +12,7 @@ import { useAccount } from "../model/account";
|
||||
import ControlContext from "./ControlContext";
|
||||
import CreateSaveModal from "./CreateSaveModal";
|
||||
import SectionHeader from "./SectionHeader";
|
||||
import { useInstanceList } from "../model/instance";
|
||||
import { useSaves } from "../model/saves";
|
||||
import { notifyErrorHandler } from "../util/notify";
|
||||
|
||||
@@ -91,6 +95,90 @@ function CopyModal(props) {
|
||||
</>;
|
||||
}
|
||||
|
||||
function TransferModal(props) {
|
||||
let account = useAccount();
|
||||
let control = useContext(ControlContext);
|
||||
let [visible, setVisible] = useState(false);
|
||||
let [form] = Form.useForm();
|
||||
let [instanceList] = useInstanceList();
|
||||
|
||||
return <>
|
||||
<Button disabled={props.disabled} onClick={() => setVisible(true)}>Transfer</Button>
|
||||
<Modal
|
||||
title="Transfer save"
|
||||
okText="Transfer"
|
||||
visible={visible}
|
||||
onOk={() => form.submit()}
|
||||
onCancel={() => setVisible(false)}
|
||||
destroyOnClose
|
||||
>
|
||||
<Form
|
||||
form={form}
|
||||
labelCol={{ span: 6 }}
|
||||
wrapperCol={{ span: 18 }}
|
||||
initialValues={{ transferredName: props.save.name, copy: false }}
|
||||
onFinish={values => {
|
||||
setVisible(false);
|
||||
let hide = message.loading("Transferring save...", 0);
|
||||
libLink.messages.transferSave.send(control, {
|
||||
instance_id: props.instanceId,
|
||||
source_save: props.save.name,
|
||||
target_instance_id: values.targetInstanceId,
|
||||
target_save: values.transferredName || props.save.name,
|
||||
copy: values.copy,
|
||||
}).then(() => {
|
||||
message.success("Transfer complete");
|
||||
form.resetFields();
|
||||
}).catch(
|
||||
notifyErrorHandler("Error transfering save")
|
||||
).finally(() => hide());
|
||||
}}
|
||||
>
|
||||
<Form.Item
|
||||
name="targetInstanceId"
|
||||
label="Target Instance"
|
||||
rules={[{ required: true, message: "Target Instance is required" }]}
|
||||
>
|
||||
<Select
|
||||
autoFocus
|
||||
showSearch
|
||||
filterOption={(input, option) => option.title.toLowerCase().indexOf(input.toLowerCase()) >= 0}
|
||||
>
|
||||
{instanceList.filter(
|
||||
instance => instance["id"] !== props.instanceId
|
||||
).map((instance) => <Select.Option
|
||||
key={instance["id"]}
|
||||
value={instance["id"]}
|
||||
title={instance["name"]}
|
||||
disabled={["unassigned", "unknown"].includes(instance["status"])}
|
||||
>
|
||||
{instance["name"]}
|
||||
{instance["status"] === "unassigned" && " (unassigned)"}
|
||||
{instance["status"] === "unknown" && " (offline)"}
|
||||
</Select.Option>)}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
name="transferredName"
|
||||
label="Transferred name"
|
||||
disabled={!account.hasAnyPermission("core.instance.save.rename", "core.instance.save.copy")}
|
||||
>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
name="copy"
|
||||
valuePropName="checked"
|
||||
label="Copy"
|
||||
tooltip="Copy instead of moving the save to the new instance."
|
||||
disabled={!account.hasPermission("core.instance.save.copy")}
|
||||
>
|
||||
<Checkbox />
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
</>;
|
||||
}
|
||||
|
||||
function formatBytes(bytes) {
|
||||
if (bytes === 0) {
|
||||
return "0 Bytes";
|
||||
@@ -179,6 +267,9 @@ export default function SavesList(props) {
|
||||
);
|
||||
}}
|
||||
>Download</Button>}
|
||||
{account.hasPermission("core.instance.save.transfer") && <TransferModal
|
||||
disabled={slaveOffline} instanceId={props.instance.id} save={save}
|
||||
/>}
|
||||
{account.hasPermission("core.instance.save.delete") && <Popconfirm
|
||||
title="Permanently delete save?"
|
||||
okText="Delete"
|
||||
|
||||
Reference in new issue
Block a user