mcsmapi 0.1.5b1__tar.gz → 0.1.5b2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mcsmapi-0.1.5b1 → mcsmapi-0.1.5b2}/PKG-INFO +5 -1
- {mcsmapi-0.1.5b1 → mcsmapi-0.1.5b2}/README.md +4 -0
- mcsmapi-0.1.5b2/mcsmapi/apis/daemon.py +123 -0
- {mcsmapi-0.1.5b1 → mcsmapi-0.1.5b2}/mcsmapi/apis/file.py +5 -2
- {mcsmapi-0.1.5b1 → mcsmapi-0.1.5b2}/mcsmapi/models/daemon.py +48 -0
- mcsmapi-0.1.5b2/mcsmapi/models/file.py +228 -0
- mcsmapi-0.1.5b2/mcsmapi/models/image.py +207 -0
- {mcsmapi-0.1.5b1 → mcsmapi-0.1.5b2}/mcsmapi/models/instance.py +88 -6
- mcsmapi-0.1.5b2/mcsmapi/models/overview.py +112 -0
- {mcsmapi-0.1.5b1 → mcsmapi-0.1.5b2}/mcsmapi/models/user.py +36 -2
- {mcsmapi-0.1.5b1 → mcsmapi-0.1.5b2}/mcsmapi.egg-info/PKG-INFO +5 -1
- {mcsmapi-0.1.5b1 → mcsmapi-0.1.5b2}/pyproject.toml +1 -1
- mcsmapi-0.1.5b1/mcsmapi/apis/daemon.py +0 -70
- mcsmapi-0.1.5b1/mcsmapi/models/file.py +0 -108
- mcsmapi-0.1.5b1/mcsmapi/models/image.py +0 -112
- mcsmapi-0.1.5b1/mcsmapi/models/overview.py +0 -63
- {mcsmapi-0.1.5b1 → mcsmapi-0.1.5b2}/LICENSE +0 -0
- {mcsmapi-0.1.5b1 → mcsmapi-0.1.5b2}/mcsmapi/__init__.py +0 -0
- {mcsmapi-0.1.5b1 → mcsmapi-0.1.5b2}/mcsmapi/apis/__init__.py +0 -0
- {mcsmapi-0.1.5b1 → mcsmapi-0.1.5b2}/mcsmapi/apis/image.py +0 -0
- {mcsmapi-0.1.5b1 → mcsmapi-0.1.5b2}/mcsmapi/apis/instance.py +0 -0
- {mcsmapi-0.1.5b1 → mcsmapi-0.1.5b2}/mcsmapi/apis/overview.py +0 -0
- {mcsmapi-0.1.5b1 → mcsmapi-0.1.5b2}/mcsmapi/apis/user.py +0 -0
- {mcsmapi-0.1.5b1 → mcsmapi-0.1.5b2}/mcsmapi/exceptions.py +0 -0
- {mcsmapi-0.1.5b1 → mcsmapi-0.1.5b2}/mcsmapi/models/__init__.py +0 -0
- {mcsmapi-0.1.5b1 → mcsmapi-0.1.5b2}/mcsmapi/pool.py +0 -0
- {mcsmapi-0.1.5b1 → mcsmapi-0.1.5b2}/mcsmapi/request.py +0 -0
- {mcsmapi-0.1.5b1 → mcsmapi-0.1.5b2}/mcsmapi.egg-info/SOURCES.txt +0 -0
- {mcsmapi-0.1.5b1 → mcsmapi-0.1.5b2}/mcsmapi.egg-info/dependency_links.txt +0 -0
- {mcsmapi-0.1.5b1 → mcsmapi-0.1.5b2}/mcsmapi.egg-info/requires.txt +0 -0
- {mcsmapi-0.1.5b1 → mcsmapi-0.1.5b2}/mcsmapi.egg-info/top_level.txt +0 -0
- {mcsmapi-0.1.5b1 → mcsmapi-0.1.5b2}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: mcsmapi
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.5b2
|
4
4
|
Summary: Shortcut the pypi package of MCSM./快捷操作MCSM的pypi包
|
5
5
|
Author-email: molanp <molanpp@outlook.com>
|
6
6
|
License-Expression: MIT
|
@@ -17,6 +17,7 @@ Dynamic: license-file
|
|
17
17
|

|
18
18
|

|
19
19
|

|
20
|
+
[](https://deepwiki.com/molanp/mcsmapi)
|
20
21
|
|
21
22
|
English|[Chinese Simplified](README_zh-cn.md)
|
22
23
|
|
@@ -41,6 +42,9 @@ You can install `mcsmapi` using `pip`:
|
|
41
42
|
pip install mcsmapi
|
42
43
|
```
|
43
44
|
|
45
|
+
If you need the latest build files (untested), please visit
|
46
|
+
[Actions](https://github.com/molanp/mcsmapi/actions)
|
47
|
+
|
44
48
|
## Supported Features
|
45
49
|
|
46
50
|
- [x] Dashboard data (`Overview`)
|
@@ -3,6 +3,7 @@
|
|
3
3
|

|
4
4
|

|
5
5
|

|
6
|
+
[](https://deepwiki.com/molanp/mcsmapi)
|
6
7
|
|
7
8
|
English|[Chinese Simplified](README_zh-cn.md)
|
8
9
|
|
@@ -27,6 +28,9 @@ You can install `mcsmapi` using `pip`:
|
|
27
28
|
pip install mcsmapi
|
28
29
|
```
|
29
30
|
|
31
|
+
If you need the latest build files (untested), please visit
|
32
|
+
[Actions](https://github.com/molanp/mcsmapi/actions)
|
33
|
+
|
30
34
|
## Supported Features
|
31
35
|
|
32
36
|
- [x] Dashboard data (`Overview`)
|
@@ -0,0 +1,123 @@
|
|
1
|
+
from typing import Any
|
2
|
+
from mcsmapi.pool import ApiPool
|
3
|
+
from mcsmapi.request import send
|
4
|
+
from mcsmapi.models.daemon import DaemonConfig, DaemonModel
|
5
|
+
from mcsmapi.models.daemon.instance import InstanceDetail
|
6
|
+
|
7
|
+
|
8
|
+
class Daemon:
|
9
|
+
def show(self) -> list[DaemonConfig]:
|
10
|
+
"""
|
11
|
+
获取全部节点配置信息
|
12
|
+
|
13
|
+
返回:
|
14
|
+
- List[DaemonConfig]: 节点的配置信息列表
|
15
|
+
"""
|
16
|
+
daemons = send(
|
17
|
+
"GET",
|
18
|
+
f"{ApiPool.SERVICE}/remote_services_list",
|
19
|
+
)
|
20
|
+
return [DaemonConfig(**daemon) for daemon in daemons]
|
21
|
+
|
22
|
+
def system(self) -> list[DaemonModel]:
|
23
|
+
"""
|
24
|
+
获取全部节点的系统信息
|
25
|
+
|
26
|
+
返回:
|
27
|
+
- List[DaemonModel]: 节点系统信息列表
|
28
|
+
"""
|
29
|
+
daemons = send(
|
30
|
+
"GET",
|
31
|
+
f"{ApiPool.SERVICE}/remote_services_system",
|
32
|
+
)
|
33
|
+
return [DaemonModel(**daemon) for daemon in daemons]
|
34
|
+
|
35
|
+
def instances(self, daemonId: str, page: int = 0, page_size: int = 10, instance_name: str = "", status: int = 0, tag: list[str] | None = None) -> list[InstanceDetail]:
|
36
|
+
"""
|
37
|
+
查询指定节点下的实例详细信息
|
38
|
+
|
39
|
+
参数:
|
40
|
+
- `daemonId` (str): 要查询的守护进程(Daemon)的唯一标识符。
|
41
|
+
- `page` (int, 默认=0): 分页查询的页码(从 0 开始)。
|
42
|
+
- `page_size` (int, 默认=10): 每页返回的实例数量。
|
43
|
+
- `instance_name` (str, 默认=""): 过滤指定名称的实例。
|
44
|
+
- `status` (int, 默认=0): 过滤指定状态的实例,如运行中、已停止等。
|
45
|
+
- `tag` (List[str] | None, 默认=None): 根据标签筛选实例(可选参数)。
|
46
|
+
|
47
|
+
返回:
|
48
|
+
- `List[InstanceDetail]`: 包含实例详细信息的列表。
|
49
|
+
|
50
|
+
注意:
|
51
|
+
- 此方法尚未实现 (`raise RuntimeError`),因为 MCSM 官方文档未提供足够的信息。
|
52
|
+
- 由于根据 MCSM 源代码的测试无法获取有效数据,目前无法完成该功能的开发。
|
53
|
+
- 如果你有具体的实现思路,请在 issue 中提出
|
54
|
+
- 可供参考 MCSM 源码: [daemon_router.ts 第 32 行](https://github.com/MCSManager/MCSManager/blob/master/panel%2Fsrc%2Fapp%2Frouters%2Fdaemon_router.ts#L32-L32)
|
55
|
+
- 模型定义代码: https://github.com/MCSManager/MCSManager/blob/master/frontend%2Fsrc%2Fservices%2Fapis%2Findex.ts#L86-L86
|
56
|
+
- 测试地址示例:
|
57
|
+
`http://localhost:23333/api/service/remote_service_instances?apikey=xxx&daemonId=xxx&page=0&page_size=10&status=3&instance_name=`
|
58
|
+
"""
|
59
|
+
raise RuntimeError("此方法尚未实现")
|
60
|
+
|
61
|
+
def add(self, config: dict[str, Any]) -> str:
|
62
|
+
"""
|
63
|
+
新增一个节点。
|
64
|
+
|
65
|
+
参数:
|
66
|
+
- config (dict): 节点的配置信息,以字典形式提供,缺失内容由DaemonConfig模型补全。
|
67
|
+
|
68
|
+
返回:
|
69
|
+
- str: 新增节点的ID
|
70
|
+
"""
|
71
|
+
return send(
|
72
|
+
"POST",
|
73
|
+
f"{ApiPool.SERVICE}/remote_service",
|
74
|
+
data=DaemonConfig(**config).dict(),
|
75
|
+
)
|
76
|
+
|
77
|
+
def delete(self, daemonId: str) -> bool:
|
78
|
+
"""
|
79
|
+
删除一个节点。
|
80
|
+
|
81
|
+
参数:
|
82
|
+
- daemonId (str): 节点的唯一标识符。
|
83
|
+
|
84
|
+
返回:
|
85
|
+
- bool: 删除成功后返回True
|
86
|
+
"""
|
87
|
+
return send(
|
88
|
+
"DELETE", f"{ApiPool.SERVICE}/remote_service", params={"uuid": daemonId}
|
89
|
+
)
|
90
|
+
|
91
|
+
def link(self, daemonId: str) -> bool:
|
92
|
+
"""
|
93
|
+
连接一个节点。
|
94
|
+
|
95
|
+
参数:
|
96
|
+
- daemonId (str): 节点的唯一标识符。
|
97
|
+
|
98
|
+
返回:
|
99
|
+
- bool: 连接成功后返回True
|
100
|
+
"""
|
101
|
+
return send(
|
102
|
+
"GET", f"{ApiPool.SERVICE}/link_remote_service", params={"uuid": daemonId}
|
103
|
+
)
|
104
|
+
|
105
|
+
def update(self, daemonId: str, config: dict[str, Any]) -> bool:
|
106
|
+
"""
|
107
|
+
更新一个节点的配置。
|
108
|
+
|
109
|
+
**不建议直接使用此函数,建议调用overview()后在remote属性内使用updateConfig方法按需更新**
|
110
|
+
|
111
|
+
参数:
|
112
|
+
- daemonId (str): 节点的唯一标识符。
|
113
|
+
- config (dict): 节点的配置信息,以字典形式提供,缺失内容由DaemonConfig模型补全。
|
114
|
+
|
115
|
+
返回:
|
116
|
+
- bool: 更新成功后返回True
|
117
|
+
"""
|
118
|
+
return send(
|
119
|
+
"PUT",
|
120
|
+
f"{ApiPool.SERVICE}/remote_service",
|
121
|
+
params={"uuid": daemonId},
|
122
|
+
data=DaemonConfig(**config).dict(),
|
123
|
+
)
|
@@ -13,6 +13,7 @@ class File:
|
|
13
13
|
target: str = "",
|
14
14
|
page: int = 0,
|
15
15
|
page_size: int = 100,
|
16
|
+
file_name: str = ""
|
16
17
|
) -> FileList:
|
17
18
|
"""
|
18
19
|
获取文件列表
|
@@ -23,6 +24,7 @@ class File:
|
|
23
24
|
- target (str, 可选): 用于文件过滤的目标路径。默认为空字符串,表示不按路径过滤。
|
24
25
|
- page (int, 可选): 指定分页的页码。默认为0。
|
25
26
|
- page_size (int, 可选): 指定每页的文件数量。默认为100。
|
27
|
+
- file_name (str, 可选): 用于在文件列表中过滤出名称包含指定字符串的文件或文件夹
|
26
28
|
|
27
29
|
**返回:**
|
28
30
|
- FileList: 包含文件列表信息和分页详情的FileList模型。
|
@@ -36,6 +38,7 @@ class File:
|
|
36
38
|
"target": target,
|
37
39
|
"page": page,
|
38
40
|
"page_size": page_size,
|
41
|
+
"file_name": file_name,
|
39
42
|
},
|
40
43
|
)
|
41
44
|
return FileList(**result, daemonId=daemonId, uuid=uuid)
|
@@ -223,8 +226,8 @@ class File:
|
|
223
226
|
**参数:**
|
224
227
|
- daemonId (str): 守护进程的唯一标识符。
|
225
228
|
- uuid (str): 实例的唯一标识符。
|
226
|
-
- source (str):
|
227
|
-
- targets (list):
|
229
|
+
- source (str): 需要压缩的文件路径。
|
230
|
+
- targets (list): 要压缩到的目标文件的路径。
|
228
231
|
|
229
232
|
**返回:**
|
230
233
|
- bool: 压缩成功后返回True。
|
@@ -4,48 +4,89 @@ from mcsmapi.models.instance import InstanceCreateResult
|
|
4
4
|
|
5
5
|
|
6
6
|
class CpuMemChart(BaseModel):
|
7
|
+
"""节点资源使用率信息"""
|
8
|
+
|
9
|
+
"""cpu使用率"""
|
7
10
|
cpu: float = 0
|
11
|
+
"""内存使用率"""
|
8
12
|
mem: float = 0
|
9
13
|
|
10
14
|
|
11
15
|
class ProcessInfo(BaseModel):
|
16
|
+
"""节点进程详细信息"""
|
17
|
+
|
18
|
+
"""远程节点使用的cpu资源(单位: byte)"""
|
12
19
|
cpu: int = 0
|
20
|
+
"""远程节点使用的内存资源(单位: byte)"""
|
13
21
|
memory: int = 0
|
22
|
+
"""远程节点的工作路径"""
|
14
23
|
cwd: str = ""
|
15
24
|
|
16
25
|
|
17
26
|
class InstanceInfo(BaseModel):
|
27
|
+
"""实例统计信息"""
|
28
|
+
|
29
|
+
"""运行中实例数量"""
|
18
30
|
running: int = 0
|
31
|
+
"""全部实例数量"""
|
19
32
|
total: int = 0
|
20
33
|
|
21
34
|
|
22
35
|
class SystemInfo(BaseModel):
|
36
|
+
"""节点系统信息"""
|
37
|
+
|
38
|
+
"""系统类型"""
|
23
39
|
type: str = ""
|
40
|
+
"""主机名"""
|
24
41
|
hostname: str = ""
|
42
|
+
"""平台架构"""
|
25
43
|
platform: str = ""
|
44
|
+
"""系统版本"""
|
26
45
|
release: str = ""
|
46
|
+
"""系统运行时间(单位: sec)"""
|
27
47
|
uptime: float = 0
|
48
|
+
"""远程节点运行路径"""
|
28
49
|
cwd: str = ""
|
50
|
+
"""系统负载平均值(仅适用于 Linux 和 macOS),表示过去 **1 分钟、5 分钟、15 分钟** 内的 CPU 负载情况"""
|
29
51
|
loadavg: List[float] = []
|
52
|
+
"""可用内存(单位: byte)"""
|
30
53
|
freemem: int = 0
|
54
|
+
"""cpu使用率"""
|
31
55
|
cpuUsage: float = 0
|
56
|
+
"""内存使用率"""
|
32
57
|
memUsage: float = 0
|
58
|
+
"""内存总量(单位: byte)"""
|
33
59
|
totalmem: int = 0
|
60
|
+
"""未知,在MCSM代码中始终为0"""
|
34
61
|
processCpu: int = 0
|
62
|
+
"""未知,在MCSM代码中始终为0"""
|
35
63
|
processMem: int = 0
|
36
64
|
|
37
65
|
|
38
66
|
class DaemonModel(BaseModel):
|
67
|
+
"""节点详细信息"""
|
68
|
+
|
69
|
+
"""远程节点版本"""
|
39
70
|
version: str = ""
|
71
|
+
"""远程节点的基本信息"""
|
40
72
|
process: ProcessInfo = ProcessInfo()
|
73
|
+
"""远程节点实例基本信息"""
|
41
74
|
instance: InstanceInfo = InstanceInfo()
|
75
|
+
"""远程节点系统信息"""
|
42
76
|
system: SystemInfo = SystemInfo()
|
77
|
+
"""cpu和内存使用趋势"""
|
43
78
|
cpuMemChart: List[CpuMemChart] = []
|
79
|
+
"""远程节点的uuid"""
|
44
80
|
uuid: str = ""
|
81
|
+
"""远程节点的ip"""
|
45
82
|
ip: str = ""
|
83
|
+
"""远程节点的端口"""
|
46
84
|
port: int = 24444
|
85
|
+
"""远程节点的路径前缀"""
|
47
86
|
prefix: str = ""
|
87
|
+
"""远程节点的可用状态"""
|
48
88
|
available: bool = False
|
89
|
+
"""远程节点的备注"""
|
49
90
|
remarks: str = ""
|
50
91
|
|
51
92
|
def delete(self) -> bool:
|
@@ -127,8 +168,15 @@ class DaemonModel(BaseModel):
|
|
127
168
|
|
128
169
|
|
129
170
|
class DaemonConfig(BaseModel):
|
171
|
+
"""节点配置信息"""
|
172
|
+
|
173
|
+
"""远程节点的ip"""
|
130
174
|
ip: str = "localhost"
|
175
|
+
"""远程节点的端口"""
|
131
176
|
port: int = 24444
|
177
|
+
"""远程节点的路径前缀"""
|
132
178
|
prefix: str = ""
|
179
|
+
"""远程节点的备注"""
|
133
180
|
remarks: str = "New Daemon"
|
181
|
+
"""远程节点的可用状态"""
|
134
182
|
available: bool = True
|
@@ -0,0 +1,228 @@
|
|
1
|
+
from pydantic import BaseModel
|
2
|
+
from typing import List
|
3
|
+
import os
|
4
|
+
|
5
|
+
|
6
|
+
class FileItem(BaseModel):
|
7
|
+
"""文件信息"""
|
8
|
+
|
9
|
+
"""文件名称"""
|
10
|
+
name: str = ""
|
11
|
+
"""文件大小(单位: byte)"""
|
12
|
+
size: int = 0 # byte
|
13
|
+
"""文件修改时间"""
|
14
|
+
time: str = ""
|
15
|
+
"""文件操作权限(仅适用于Linux)"""
|
16
|
+
mode: int = 777 # Linux file permission
|
17
|
+
"""文件类型,`0`为文件夹,`1`为文件"""
|
18
|
+
type: int = 0 # 0 = Folder, 1 = File
|
19
|
+
"""远程节点uuid"""
|
20
|
+
daemonId: str = ""
|
21
|
+
"""实例的uiid"""
|
22
|
+
uuid: str = ""
|
23
|
+
"""文件所在路径"""
|
24
|
+
target: str = ""
|
25
|
+
"""当前文件列表过滤条件"""
|
26
|
+
file_name: str = ""
|
27
|
+
|
28
|
+
def rename(self, newName: str) -> bool:
|
29
|
+
"""
|
30
|
+
重命名该文件或文件夹。
|
31
|
+
|
32
|
+
**参数:**
|
33
|
+
- new_name (str): 源文件或文件夹的新名字。
|
34
|
+
|
35
|
+
**返回:**
|
36
|
+
- bool: 重命名成功后返回True。
|
37
|
+
"""
|
38
|
+
from mcsmapi.apis.file import File
|
39
|
+
|
40
|
+
return File().rename(
|
41
|
+
self.daemonId, self.uuid, os.path.join(self.target, self.name), newName
|
42
|
+
)
|
43
|
+
|
44
|
+
def delete(self) -> bool:
|
45
|
+
"""
|
46
|
+
删除该文件或文件夹。
|
47
|
+
|
48
|
+
**返回:**
|
49
|
+
- bool: 重命名成功后返回True。
|
50
|
+
"""
|
51
|
+
from mcsmapi.apis.file import File
|
52
|
+
|
53
|
+
return File().delete(
|
54
|
+
self.daemonId, self.uuid, [os.path.join(self.target, self.name)]
|
55
|
+
)
|
56
|
+
|
57
|
+
def copy(self, target: str) -> bool:
|
58
|
+
from mcsmapi.apis.file import File
|
59
|
+
|
60
|
+
return File().copyOne(
|
61
|
+
self.daemonId, self.uuid, os.path.join(self.target, self.name), target
|
62
|
+
)
|
63
|
+
|
64
|
+
def move(self, target: str) -> bool:
|
65
|
+
"""
|
66
|
+
移动该文件或文件夹到目标路径。
|
67
|
+
|
68
|
+
**参数:**
|
69
|
+
- target (str): 目标文件或文件夹的路径。
|
70
|
+
|
71
|
+
**返回:**
|
72
|
+
- bool: 移动成功后返回True。
|
73
|
+
"""
|
74
|
+
from mcsmapi.apis.file import File
|
75
|
+
|
76
|
+
return File().moveOne(
|
77
|
+
self.daemonId, self.uuid, os.path.join(self.target, self.name), target
|
78
|
+
)
|
79
|
+
|
80
|
+
def content(self):
|
81
|
+
"""
|
82
|
+
获取文件内容。
|
83
|
+
**返回:**
|
84
|
+
- str | bytes: 文件内容。
|
85
|
+
"""
|
86
|
+
from mcsmapi.apis.file import File
|
87
|
+
|
88
|
+
return File().content(
|
89
|
+
self.daemonId, self.uuid, os.path.join(self.target, self.name)
|
90
|
+
)
|
91
|
+
|
92
|
+
def zip(self, targets: list[str]) -> bool:
|
93
|
+
"""
|
94
|
+
压缩多个文件或文件夹到指定位置。
|
95
|
+
|
96
|
+
**参数:**
|
97
|
+
- targets (list): 要压缩到的目标文件的路径。
|
98
|
+
|
99
|
+
**返回:**
|
100
|
+
- bool: 压缩成功后返回True。
|
101
|
+
"""
|
102
|
+
from mcsmapi.apis.file import File
|
103
|
+
|
104
|
+
return File().zip(
|
105
|
+
self.daemonId, self.uuid, os.path.join(self.target, self.name), targets
|
106
|
+
)
|
107
|
+
|
108
|
+
def unzip(self, target: str, code: str = "utf-8") -> bool:
|
109
|
+
"""
|
110
|
+
解压缩该 zip 文件到目标位置。
|
111
|
+
|
112
|
+
**参数:**
|
113
|
+
- target (str): 解压到的目标路径。
|
114
|
+
- code (str, optional): 压缩文件的编码方式,默认为"utf-8"。
|
115
|
+
可选值: utf-8, gbk, big5
|
116
|
+
|
117
|
+
**返回:**
|
118
|
+
- bool: 解压成功后返回True。
|
119
|
+
"""
|
120
|
+
from mcsmapi.apis.file import File
|
121
|
+
|
122
|
+
return File().unzip(
|
123
|
+
self.daemonId, self.uuid, os.path.join(self.target, self.name), target, code
|
124
|
+
)
|
125
|
+
|
126
|
+
def update(self, text: str) -> bool:
|
127
|
+
"""
|
128
|
+
更新该文件内容。
|
129
|
+
**参数:**
|
130
|
+
- text (str): 文件内容。
|
131
|
+
**返回:**
|
132
|
+
- bool: 更新成功后返回True。
|
133
|
+
"""
|
134
|
+
from mcsmapi.apis.file import File
|
135
|
+
|
136
|
+
return File().update(
|
137
|
+
self.daemonId, self.uuid, os.path.join(self.target, self.name), text
|
138
|
+
)
|
139
|
+
|
140
|
+
def download(self) -> str:
|
141
|
+
"""
|
142
|
+
下载该文件。
|
143
|
+
**返回:**
|
144
|
+
- str: 文件下载的URL。
|
145
|
+
"""
|
146
|
+
from mcsmapi.apis.file import File
|
147
|
+
|
148
|
+
return File().download(
|
149
|
+
self.daemonId, self.uuid, os.path.join(self.target, self.name)
|
150
|
+
)
|
151
|
+
|
152
|
+
|
153
|
+
class FileList(BaseModel):
|
154
|
+
"""文件列表"""
|
155
|
+
|
156
|
+
"""文件信息列表"""
|
157
|
+
items: List[FileItem]
|
158
|
+
"""当前页数"""
|
159
|
+
page: int = 0
|
160
|
+
"""文件列表单页大小"""
|
161
|
+
pageSize: int = 100
|
162
|
+
"""总页数"""
|
163
|
+
total: int = 0
|
164
|
+
"""当前路径在远程节点的绝对路径"""
|
165
|
+
absolutePath: str = "\\"
|
166
|
+
"""远程节点uuid"""
|
167
|
+
daemonId: str = ""
|
168
|
+
"""实例uuid"""
|
169
|
+
uuid: str = ""
|
170
|
+
"""文件(名称或目录)路径"""
|
171
|
+
target: str = ""
|
172
|
+
|
173
|
+
def __init__(self, **data: str):
|
174
|
+
super().__init__(**data)
|
175
|
+
for item in self.items:
|
176
|
+
item.daemonId = self.daemonId
|
177
|
+
item.uuid = self.uuid
|
178
|
+
item.target = self.target
|
179
|
+
|
180
|
+
async def upload(self, file: bytes, upload_dir: str) -> bool:
|
181
|
+
"""
|
182
|
+
上传文件到实例。
|
183
|
+
|
184
|
+
**参数:**
|
185
|
+
- file (bytes): 要上传的文件内容。
|
186
|
+
- upload_dir (str): 上传文件的目标目录(包含文件名)。
|
187
|
+
|
188
|
+
**返回:**
|
189
|
+
- bool: 返回操作结果,成功时返回True。
|
190
|
+
"""
|
191
|
+
from mcsmapi.apis.file import File
|
192
|
+
|
193
|
+
return await File().upload(self.daemonId, self.uuid, file, upload_dir)
|
194
|
+
|
195
|
+
def createFile(self, target: str) -> bool:
|
196
|
+
"""
|
197
|
+
创建文件。
|
198
|
+
|
199
|
+
**参数:**
|
200
|
+
- target (str): 目标文件的路径,包含文件名。
|
201
|
+
|
202
|
+
**返回:**
|
203
|
+
- bool: 创建成功后返回True。
|
204
|
+
"""
|
205
|
+
from mcsmapi.apis.file import File
|
206
|
+
|
207
|
+
return File().createFile(self.daemonId, self.uuid, target)
|
208
|
+
|
209
|
+
def createFloder(self, target: str) -> bool:
|
210
|
+
"""
|
211
|
+
创建文件夹
|
212
|
+
|
213
|
+
**参数:**
|
214
|
+
- target (str): 目标文件夹的路径。
|
215
|
+
|
216
|
+
**返回:**
|
217
|
+
- bool: 创建成功后返回True。
|
218
|
+
"""
|
219
|
+
from mcsmapi.apis.file import File
|
220
|
+
|
221
|
+
return File().createFloder(self.daemonId, self.uuid, target)
|
222
|
+
|
223
|
+
|
224
|
+
class CommonConfig(BaseModel):
|
225
|
+
"""文件下载密码"""
|
226
|
+
password: str = ""
|
227
|
+
"""文件下载地址"""
|
228
|
+
addr: str = ""
|