/
index.tsx
130 lines (126 loc) · 4.42 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import React, { useState } from "react";
import {
Button,
Card,
Collapse,
Link,
Message,
Space,
Typography,
} from "@arco-design/web-react";
import IoC from "@App/app/ioc";
import { SystemConfig } from "@App/pkg/config/config";
import FileSystemFactory, { FileSystemType } from "@Pkg/filesystem/factory";
import FileSystemParams from "../FileSystemParams";
const CollapseItem = Collapse.Item;
const GMApiSetting: React.FC = () => {
const systemConfig = IoC.instance(SystemConfig) as SystemConfig;
const [status, setStatus] = useState(systemConfig.catFileStorage.status);
const [fileSystemType, setFilesystemType] = useState<FileSystemType>(
systemConfig.catFileStorage.filesystem
);
const [fileSystemParams, setFilesystemParam] = useState<{
[key: string]: any;
}>(systemConfig.catFileStorage.params[fileSystemType] || {});
return (
<Card title="GM Api" bordered={false}>
<Collapse bordered={false} defaultActiveKey={["storage"]}>
<CollapseItem header="Storage API" name="storage">
<Space direction="vertical">
<FileSystemParams
preNode={
<Typography.Text>
设置
<Link
target="_black"
href="https://github.com/scriptscat/scriptcat/blob/main/example/cat_file_storage.js"
>
CAT_fileStorage
</Link>
使用的文件系统
</Typography.Text>
}
actionButton={[
<Button
key="save"
type="primary"
onClick={async () => {
try {
await FileSystemFactory.create(
fileSystemType,
fileSystemParams
);
} catch (e) {
Message.error(`账号信息验证失败: ${e}`);
return;
}
const params = { ...systemConfig.catFileStorage.params };
params[fileSystemType] = fileSystemParams;
systemConfig.catFileStorage = {
status: "success",
filesystem: fileSystemType,
params,
};
setStatus("success");
Message.success("保存成功");
}}
>
保存
</Button>,
<Button
key="reset"
onClick={() => {
const config = systemConfig.catFileStorage;
config.status = "unset";
systemConfig.catFileStorage = config;
setStatus("unset");
}}
type="primary"
status="danger"
>
重置
</Button>,
<Button
key="open"
type="secondary"
onClick={async () => {
try {
let fs = await FileSystemFactory.create(
fileSystemType,
fileSystemParams
);
fs = await fs.openDir("ScriptCat/app");
window.open(await fs.getDirUrl(), "_black");
} catch (e) {
Message.error(`账号信息验证失败: ${e}`);
}
}}
>
打开目录
</Button>,
]}
fileSystemType={fileSystemType}
fileSystemParams={fileSystemParams}
onChangeFileSystemType={(type) => {
setFilesystemType(type);
}}
onChangeFileSystemParams={(params) => {
setFilesystemParam(params);
}}
/>
{status === "unset" && (
<Typography.Text type="secondary">未设置</Typography.Text>
)}
{status === "success" && (
<Typography.Text type="success">使用中</Typography.Text>
)}
{status === "error" && (
<Typography.Text type="error">储存错误</Typography.Text>
)}
</Space>
</CollapseItem>
</Collapse>
</Card>
);
};
export default GMApiSetting;