mcsmapi 0.1.6__py3-none-any.whl → 0.1.8b1__py3-none-any.whl

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.
@@ -1,291 +1,313 @@
1
- from typing import List, Dict, Optional
1
+ from enum import IntEnum
2
+ from typing import Any, TypedDict
2
3
  from pydantic import BaseModel
3
- from mcsmapi.models.file import FileList
4
4
  from mcsmapi.models.image import DockerConfig
5
5
 
6
6
 
7
+ class CRLFType(IntEnum):
8
+ """换行符"""
9
+
10
+ LF = 0
11
+ CR = 1
12
+ CRLF = 2
13
+
14
+
15
+ class Status(IntEnum):
16
+ """实例状态"""
17
+
18
+ BUSY = -1
19
+ STOP = 0
20
+ STOPPING = 1
21
+ STARTING = 2
22
+ RUNNING = 3
23
+
24
+
25
+ class batchOperationDetail(TypedDict):
26
+ """批量操作的实例信息"""
27
+
28
+ uuid: str
29
+ """实例UUID"""
30
+ daemonId: str
31
+ """节点UUID"""
32
+
33
+
7
34
  class TerminalOption(BaseModel):
8
35
  """终端选项"""
9
36
 
10
- """是否启用颜色输出"""
11
37
  haveColor: bool = False
12
- """是否使用伪终端 (PTY)"""
38
+ """是否启用前端颜色渲染"""
13
39
  pty: bool = True
40
+ """是否使用伪终端 (PTY)"""
41
+ ptyWindowCol: int = 164
42
+ """PTY 窗口列数"""
43
+ ptyWindowRow: int = 40
44
+ """PTY 窗口行数"""
14
45
 
15
46
 
16
47
  class EventTask(BaseModel):
17
48
  """事件任务"""
18
49
 
19
- """是否自动启动"""
20
50
  autoStart: bool = False
21
- """是否自动重启"""
51
+ """是否自动启动"""
22
52
  autoRestart: bool = True
23
- """是否忽略该任务"""
53
+ """是否自动重启"""
24
54
  ignore: bool = False
55
+ """是否忽略该任务"""
25
56
 
26
57
 
27
58
  class PingConfig(BaseModel):
28
- """服务器 Ping 配置"""
59
+ """服务器 Ping 配置(已弃用)"""
29
60
 
30
- """服务器 IP 地址"""
31
61
  ip: str = ""
32
- """服务器端口"""
62
+ """服务器 IP 地址"""
33
63
  port: int = 25565
34
- """Ping 类型 (1: 默认类型)"""
64
+ """服务器端口"""
35
65
  type: int = 1
66
+ """Ping 类型 (0: UDP, 1: TCP)"""
36
67
 
37
68
 
38
69
  class InstanceConfig(BaseModel):
39
70
  """实例配置信息"""
40
71
 
41
- """实例名称"""
42
72
  nickname: str = "New Name"
43
- """启动命令"""
73
+ """实例名称"""
44
74
  startCommand: str = "cmd.exe"
45
- """停止命令"""
75
+ """启动命令"""
46
76
  stopCommand: str = "^C"
47
- """工作目录"""
77
+ """停止命令"""
48
78
  cwd: str = ""
79
+ """工作目录"""
80
+ ie: str = "utf8"
49
81
  """输入编码"""
50
- ie: str = "gbk"
82
+ oe: str = "UTF-8"
51
83
  """输出编码"""
52
- oe: str = "gbk"
53
- """创建时间 (Unix 时间戳)"""
54
84
  createDatetime: int = 0
55
- """最后修改时间 (Unix 时间戳)"""
85
+ """创建时间 (Unix 时间戳)"""
56
86
  lastDatetime: int = 0
57
- """实例类型 (universal, minecraft 等)"""
87
+ """最后修改时间 (Unix 时间戳)"""
58
88
  type: str = "universal"
89
+ """实例类型 (universal, minecraft 等)"""
90
+ tag: list[str] = []
59
91
  """实例标签"""
60
- tag: List[str] = []
61
- """实例结束时间 (可选)"""
62
- endTime: Optional[int] = None
92
+ endTime: int | None = None
93
+ """实例到期时间"""
94
+ fileCode: str = "utf8"
63
95
  """文件编码"""
64
- fileCode: str = "gbk"
65
- """进程类型 (如 docker, local)"""
66
- processType: str = "docker"
67
- """更新命令"""
96
+ processType: str = "general"
97
+ """进程类型 (如 docker, general)"""
68
98
  updateCommand: str = "shutdown -s"
99
+ """更新命令"""
100
+ actionCommandList: list[str] = []
69
101
  """实例可执行的操作命令列表"""
70
- actionCommandList: List[str] = []
71
- """换行符 (0: LF, 1: CR, 2: CRLF)"""
72
- crlf: int = 2
102
+ crlf: CRLFType = CRLFType.CRLF
103
+ """换行符"""
104
+ docker: DockerConfig = DockerConfig()
73
105
  """Docker 相关配置"""
74
- docker: "DockerConfig" = DockerConfig()
106
+ enableRcon: bool = False
75
107
  """是否启用 RCON 远程控制"""
76
- enableRcon: bool = True
77
- """RCON 连接密码"""
78
108
  rconPassword: str = ""
79
- """RCON 端口"""
109
+ """RCON 连接密码"""
80
110
  rconPort: int = 2557
81
- """RCON IP 地址"""
111
+ """RCON 端口"""
82
112
  rconIp: str = ""
83
- """终端选项配置"""
113
+ """RCON IP 地址"""
84
114
  terminalOption: TerminalOption = TerminalOption()
85
- """事件任务配置"""
115
+ """终端选项配置"""
86
116
  eventTask: EventTask = EventTask()
87
- """服务器 Ping 监测配置"""
117
+ """事件任务配置"""
88
118
  pingConfig: PingConfig = PingConfig()
119
+ """服务器 Ping 监测配置(已弃用)"""
120
+ runAs: str = ""
121
+ """运行该实例的系统用户,为空则使用启动面板的系统用户"""
89
122
 
90
123
 
91
- class ProcessInfo(BaseModel):
124
+ class InstanceProcessInfo(BaseModel):
92
125
  """进程信息"""
93
126
 
127
+ cpu: int
94
128
  """CPU 使用率 (单位: %)"""
95
- cpu: int = 0
129
+ memory: int
96
130
  """进程占用内存 (单位: KB)"""
97
- memory: int = 0
131
+ ppid: int
98
132
  """父进程 ID"""
99
- ppid: int = 0
133
+ pid: int
100
134
  """进程 ID"""
101
- pid: int = 0
135
+ ctime: int
102
136
  """进程创建时间 (Unix 时间戳)"""
103
- ctime: int = 0
137
+ elapsed: int
104
138
  """进程运行时长 (单位: 秒)"""
105
- elapsed: int = 0
139
+ timestamp: int
106
140
  """时间戳"""
107
- timestamp: int = 0
108
141
 
109
142
 
110
143
  class InstanceInfo(BaseModel):
111
- """实例运行状态信息( 这些选项在新版中已不再支持设置,但仍在API中返回)"""
144
+ """实例运行状态信息(这些选项在新版中已不再支持设置,但仍在API中返回)"""
112
145
 
113
- """当前玩家数量 (-1 表示未知)"""
114
- currentPlayers: int = -1
115
- """文件锁状态 (0: 无锁)"""
146
+ currentPlayers: int
147
+ """当前玩家数量"""
116
148
  fileLock: int = 0
117
- """最大允许玩家数 (-1 表示未知)"""
149
+ """文件锁状态 (0: 无锁)"""
118
150
  maxPlayers: int = -1
119
- """是否启用 FRP 远程服务"""
151
+ """最大允许玩家数 (-1 表示未知)"""
120
152
  openFrpStatus: bool = False
153
+ """是否启用 FRP 远程服务"""
154
+ playersChart: list[dict] = []
121
155
  """玩家数量变化图表数据"""
122
- playersChart: List[Dict] = []
123
- """服务器版本"""
124
156
  version: str = ""
157
+ """服务器版本"""
125
158
 
126
159
 
127
160
  class InstanceDetail(BaseModel):
128
161
  """实例详细信息"""
129
162
 
163
+ config: InstanceConfig
130
164
  """实例的配置信息"""
131
- config: InstanceConfig = InstanceConfig()
165
+ info: InstanceInfo
132
166
  """实例的运行状态信息"""
133
- info: InstanceInfo = InstanceInfo()
134
- """所属的守护进程 (Daemon) ID"""
135
- daemonId: str = ""
136
- """实例唯一标识符 (UUID)"""
137
- instanceUuid: str = ""
167
+ daemonId: str
168
+ """所属的节点UUID"""
169
+ instanceUuid: str
170
+ """实例UUID"""
171
+ processInfo: InstanceProcessInfo
138
172
  """实例的进程信息"""
139
- processInfo: ProcessInfo = ProcessInfo()
140
- """实例的存储空间大小(始终为`0`)"""
141
- space: int = 0 # 在 MCSM 代码中,此项始终为 0,意义不明
173
+ started: int
142
174
  """实例的启动次数"""
143
- started: int = 0
144
- """实例状态 (-1: 忙碌, 0: 停止, 1: 停止中, 2: 启动中, 3: 运行中)"""
145
- status: int = 0
175
+ status: Status
176
+ """实例状态"""
146
177
 
147
- def start(self) -> str | bool:
178
+ def start(self):
148
179
  """
149
- 启动该实例。
180
+ 启动该实例
150
181
 
151
- **返回:**
152
- - str|bool: str|bool: 返回结果中的 "instanceUuid" 字段值,如果未找到该字段,则默认返回True。
182
+ :returns: 返回被操作的实例的UUID
153
183
  """
154
184
  from mcsmapi.apis.instance import Instance
155
185
 
156
- return Instance().start(self.daemonId, self.instanceUuid)
186
+ return Instance.start(self.daemonId, self.instanceUuid)
157
187
 
158
- def stop(self) -> str | bool:
188
+ def stop(self):
159
189
  """
160
- 停止该实例。
190
+ 停止该实例
161
191
 
162
- **返回:**
163
- - str|bool: 返回结果中的 "instanceUuid" 字段值,如果未找到该字段,则默认返回True。
192
+ :returns: 返回被操作的实例的UUID
164
193
  """
165
194
  from mcsmapi.apis.instance import Instance
166
195
 
167
- return Instance().stop(self.daemonId, self.instanceUuid)
196
+ return Instance.stop(self.daemonId, self.instanceUuid)
168
197
 
169
- def restart(self) -> str | bool:
198
+ def restart(self):
170
199
  """
171
- 重启该实例。
200
+ 重启该实例
172
201
 
173
- **返回:**
174
- - str|bool: 返回结果中的 "instanceUuid" 字段值,如果未找到该字段,则默认返回True。
202
+ :returns: 返回被操作的实例的UUID
175
203
  """
176
204
  from mcsmapi.apis.instance import Instance
177
205
 
178
- return Instance().restart(self.daemonId, self.instanceUuid)
206
+ return Instance.restart(self.daemonId, self.instanceUuid)
179
207
 
180
- def kill(self) -> str | bool:
208
+ def kill(self):
181
209
  """
182
- 强制关闭该实例。
210
+ 强制关闭该实例
183
211
 
184
- **返回:**
185
- - str|bool: 返回结果中的 "instanceUuid" 字段值,如果未找到该字段,则默认返回True。
212
+ :returns: 返回被操作的实例的UUID
186
213
  """
187
214
  from mcsmapi.apis.instance import Instance
188
215
 
189
- return Instance().kill(self.daemonId, self.instanceUuid)
216
+ return Instance.kill(self.daemonId, self.instanceUuid)
190
217
 
191
- def delete(self, deleteFile=False) -> str:
218
+ def delete(self, deleteFile=False):
192
219
  """
193
- 删除该实例。
220
+ 删除该实例
194
221
 
195
- **返回:**
196
- - str: 被删除的实例的uuid。
222
+ :returns: 被删除的实例的uuid
197
223
  """
198
224
  from mcsmapi.apis.instance import Instance
199
225
 
200
- return Instance().delete(self.daemonId, [self.instanceUuid], deleteFile)[0]
226
+ return Instance.delete(self.daemonId, [self.instanceUuid], deleteFile)[0]
201
227
 
202
- def update(self) -> bool:
228
+ def update(self):
203
229
  """
204
- 升级实例。
230
+ 升级实例
205
231
 
206
- **返回:**
207
- - bool: 返回操作结果,成功时返回True。
232
+ :returns: 操作成功返回True
208
233
  """
209
234
  from mcsmapi.apis.instance import Instance
210
235
 
211
- return Instance().update(self.daemonId, self.instanceUuid)
236
+ return Instance.update(self.daemonId, self.instanceUuid)
212
237
 
213
- def updateConfig(self, config: dict) -> str | bool:
238
+ def updateConfig(self, config: dict[str, Any]):
214
239
  """
215
- 更新该实例配置。
240
+ 更新该实例配置
216
241
 
217
- **参数:**
218
- - config (dict): 新的实例配置,以字典形式提供,缺失内容由使用原实例配置填充。
242
+ :params config: 新的实例配置,以字典形式提供,缺失内容由使用原实例配置填充
219
243
 
220
- **返回:**
221
- - str|bool: 更新成功后返回更新的实例UUID,如果未找到该字段,则默认返回True。
244
+ :returns: 更新成功后返回更新的实例UUID
222
245
  """
223
246
  from mcsmapi.apis.instance import Instance
224
247
 
225
- updated_config = self.config.dict()
248
+ updated_config = self.config.model_dump()
226
249
  updated_config.update(config)
227
250
 
228
- instance_config = InstanceConfig(**updated_config).dict()
251
+ instance_config = InstanceConfig(**updated_config).model_dump()
229
252
 
230
- return Instance().updateConfig(
231
- self.daemonId, self.instanceUuid, instance_config
232
- )
253
+ return Instance.updateConfig(self.daemonId, self.instanceUuid, instance_config)
233
254
 
234
- def reinstall(self, targetUrl: str, title: str = "", description: str = "") -> bool:
255
+ def reinstall(self, targetUrl: str, title: str = "", description: str = ""):
235
256
  """
236
- 重装实例。
257
+ 重装实例
237
258
 
238
- **参数:**
239
- - targetUrl (str): 重装文件的目标URL。
240
- - title (str): 重装文件的标题。
241
- - description (str, optional): 重装文件的描述,默认为空字符串。
259
+ :params targetUrl: 重装文件的目标URL
260
+ :params title: 重装文件的标题
261
+ :params description: 重装文件的描述,默认为空字符串
242
262
 
243
- **返回:**
244
- - bool: 返回操作结果,成功时返回True
263
+ :returns: 操作成功返回True
245
264
  """
246
265
  from mcsmapi.apis.instance import Instance
247
266
 
248
- return Instance().reinstall(
267
+ return Instance.reinstall(
249
268
  self.daemonId, self.instanceUuid, targetUrl, title, description
250
269
  )
251
270
 
252
- def files(self, target: str = "", page: int = 0, page_size: int = 100) -> FileList:
271
+ def files(
272
+ self, target: str = "", page: int = 0, page_size: int = 100, file_name: str = ""
273
+ ):
253
274
  """
254
- 获取实例的文件列表。
275
+ 获取实例的文件列表
255
276
 
256
- **参数:**
257
- - target (str, 可选): 用于文件过滤的目标路径。默认为空字符串,表示不按路径过滤
258
- - page (int, 可选): 指定分页的页码。默认为0。
259
- - page_size (int, 可选): 指定每页的文件数量。默认为100。
277
+ :params target: 用于文件过滤的目标路径默认为空字符串,表示不按路径过滤
278
+ :params page: 指定分页的页码
279
+ :params page_size: 指定每页的文件数量
280
+ :params file_name: 用于在文件列表中过滤出名称包含指定字符串的文件或文件夹
260
281
 
261
- **返回:**
262
- - FileList: 文件列表。
282
+ :returns: 文件列表
263
283
  """
264
284
  from mcsmapi.apis.file import File
265
285
 
266
- return File().show(self.daemonId, self.instanceUuid, target, page, page_size)
286
+ return File.show(
287
+ self.daemonId, self.instanceUuid, target, page, page_size, file_name
288
+ )
267
289
 
268
290
 
269
291
  class InstanceCreateResult(BaseModel):
270
292
  """实例创建结果"""
271
293
 
272
- """实例唯一标识符 (UUID)"""
273
294
  instanceUuid: str = ""
274
- """实例的配置信息"""
295
+ """实例UUID"""
275
296
  config: InstanceConfig = InstanceConfig()
297
+ """实例的配置信息"""
276
298
 
277
299
 
278
300
  class InstanceSearchList(BaseModel):
279
301
  """实例搜索列表"""
280
302
 
281
- """每页的实例数量"""
282
303
  pageSize: int = 0
283
- """最大页数"""
304
+ """每页的实例数量"""
284
305
  maxPage: int = 0
306
+ """最大页数"""
307
+ data: list[InstanceDetail] = []
285
308
  """实例详细信息列表"""
286
- data: List[InstanceDetail] = []
287
- """所属的守护进程 (Daemon) ID"""
288
309
  daemonId: str = ""
310
+ """所属的节点UUID"""
289
311
 
290
312
  def __init__(self, **data: str):
291
313
  """实例化对象,并在每个实例中填充 daemonId"""
@@ -297,7 +319,7 @@ class InstanceSearchList(BaseModel):
297
319
  class UserInstancesList(BaseModel):
298
320
  """用户实例列表"""
299
321
 
300
- """实例唯一标识符 (UUID)"""
301
322
  instanceUuid: str = ""
302
- """所属的守护进程 (Daemon) ID"""
323
+ """实例UUID"""
303
324
  daemonId: str = ""
325
+ """所属的节点UUID"""