Skip to content

Commit 9bfc1fe

Browse files
author
molanp
committed
feat(remote): 新增MCSM隐藏API
- 更新部分模型的注释 - 新增了查询节点列表的功能
2 parents 04f06e4 + f843417 commit 9bfc1fe

File tree

6 files changed

+72
-8
lines changed

6 files changed

+72
-8
lines changed

example/daemon.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@
66

77
# mcsm.login_with_apikey("apikey")
88

9-
daemonM = mcsm.daemon()
9+
daemon_object = mcsm.daemon()
10+
11+
# show Daemon list
12+
13+
print(daemon_object.show())
1014

1115
# 创建节点
12-
daemonId = daemonM.add(
16+
daemonId = daemon_object.add(
1317
{
1418
"ip": "localhost",
1519
"port": 24444,
@@ -19,4 +23,4 @@
1923
}
2024
)
2125
# 删除节点
22-
daemonM.delete(daemonId)
26+
daemon_object.delete(daemonId)

mcsmapi/apis/daemon.py

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,62 @@
11
from typing import Any
22
from mcsmapi.pool import ApiPool
33
from mcsmapi.request import send
4-
from mcsmapi.models.daemon import DaemonConfig
4+
from mcsmapi.models.daemon import DaemonConfig, DaemonModel
5+
from mcsmapi.models.daemon.instance import InstanceDetail
56

67

78
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+
- 测试地址示例:
56+
`http://localhost:23333/api/service/remote_service_instances?apikey=xxx&daemonId=xxx&page=0&page_size=10&status=3&instance_name=`
57+
"""
58+
raise RuntimeError("此方法尚未实现")
59+
860
def add(self, config: dict[str, Any]) -> str:
961
"""
1062
新增一个节点。

mcsmapi/apis/file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def show(
3838
"target": target,
3939
"page": page,
4040
"page_size": page_size,
41-
"file_name": file_name
41+
"file_name": file_name,
4242
},
4343
)
4444
return FileList(**result, daemonId=daemonId, uuid=uuid)

mcsmapi/models/daemon.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,13 @@ def deleteInstance(self, uuids: list[str], deleteFile=False) -> list[str]:
158158

159159

160160
class DaemonConfig(BaseModel):
161+
"""远程节点的ip"""
161162
ip: str = "localhost"
163+
"""远程节点的端口"""
162164
port: int = 24444
165+
"""远程节点的路径前缀"""
163166
prefix: str = ""
167+
"""远程节点的备注"""
164168
remarks: str = "New Daemon"
169+
"""远程节点的可用状态"""
165170
available: bool = True

mcsmapi/models/file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
class FileItem(BaseModel):
77
"""文件名称"""
8-
name: str = "New File"
8+
name: str = ""
99
"""文件大小(单位: byte)"""
1010
size: int = 0 # byte
1111
"""文件修改时间"""

mcsmapi/models/image.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33

44

55
class DockerConfig(BaseModel):
6+
"""容器名称"""
67
containerName: str = ""
7-
image: str = "mcsm-ubuntu:22.04"
8-
memory: int = 1024 # in MB
8+
"""镜像名称"""
9+
image: str = ""
10+
"""容器分配内存(单位: MB)"""
11+
memory: int = 0 # in MB
912
ports: List[str] = ["25565:25565/tcp"]
1013
extraVolumes: List[str] = []
1114
maxSpace: Optional[int] = None

0 commit comments

Comments
 (0)