mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 14:22:55 +08:00
perf👌: 完善系统管理api
This commit is contained in:
parent
b656f89c8e
commit
72b0b011ee
@ -22,5 +22,5 @@ async def _(path: Optional[str] = None) -> Result:
|
|||||||
|
|
||||||
|
|
||||||
@router.get("/get_resources_size", dependencies=[authentication()], description="获取文件列表")
|
@router.get("/get_resources_size", dependencies=[authentication()], description="获取文件列表")
|
||||||
async def _(type: Optional[str] = None) -> Result:
|
async def _(full_path: Optional[str] = None) -> Result:
|
||||||
return Result.ok(await get_system_disk(type))
|
return Result.ok(await get_system_disk(full_path))
|
||||||
@ -19,17 +19,3 @@ class DirFile(BaseModel):
|
|||||||
"""文件夹或文件名称"""
|
"""文件夹或文件名称"""
|
||||||
parent: Optional[str] = None
|
parent: Optional[str] = None
|
||||||
"""父级"""
|
"""父级"""
|
||||||
|
|
||||||
class SystemFolderSize(BaseModel):
|
|
||||||
"""
|
|
||||||
资源文件占比
|
|
||||||
"""
|
|
||||||
|
|
||||||
font_dir_size: float
|
|
||||||
image_dir_size: float
|
|
||||||
text_dir_size: float
|
|
||||||
record_dir_size: float
|
|
||||||
temp_dir_size: float
|
|
||||||
data_dir_size: float
|
|
||||||
log_dir_size: float
|
|
||||||
check_time: datetime
|
|
||||||
@ -105,13 +105,13 @@ class SystemFolderSize(BaseModel):
|
|||||||
资源文件占比
|
资源文件占比
|
||||||
"""
|
"""
|
||||||
|
|
||||||
font_dir_size: float
|
name: str
|
||||||
image_dir_size: float
|
"""名称"""
|
||||||
text_dir_size: float
|
size: float
|
||||||
record_dir_size: float
|
"""大小"""
|
||||||
temp_dir_size: float
|
full_path: Optional[str]
|
||||||
data_dir_size: float
|
"""完整路径"""
|
||||||
log_dir_size: float
|
is_dir: bool
|
||||||
check_time: datetime
|
"""是否为文件夹"""
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, Dict, Optional, Union
|
from typing import Any, Dict, List, Optional, Union
|
||||||
|
|
||||||
import psutil
|
import psutil
|
||||||
import ujson as json
|
import ujson as json
|
||||||
@ -123,47 +123,48 @@ def get_system_status() -> SystemStatus:
|
|||||||
|
|
||||||
@run_sync
|
@run_sync
|
||||||
def get_system_disk(
|
def get_system_disk(
|
||||||
type_: Optional[str],
|
full_path: Optional[str],
|
||||||
) -> Union[SystemFolderSize, Dict[str, Union[float, datetime]]]:
|
) -> List[SystemFolderSize]:
|
||||||
"""
|
"""
|
||||||
说明:
|
说明:
|
||||||
获取资源文件大小等
|
获取资源文件大小等
|
||||||
"""
|
"""
|
||||||
if not type_:
|
base_path = Path(full_path) if full_path else Path()
|
||||||
disk = SystemFolderSize(
|
other_size = 0
|
||||||
font_dir_size=_get_dir_size(FONT_PATH) / 1024 / 1024,
|
data_list = []
|
||||||
image_dir_size=_get_dir_size(IMAGE_PATH) / 1024 / 1024,
|
for file in os.listdir(base_path):
|
||||||
text_dir_size=_get_dir_size(TEXT_PATH) / 1024 / 1024,
|
f = base_path / file
|
||||||
record_dir_size=_get_dir_size(RECORD_PATH) / 1024 / 1024,
|
if f.is_dir():
|
||||||
temp_dir_size=_get_dir_size(TEMP_PATH) / 1024 / 102,
|
size = _get_dir_size(f) / 1024 / 1024
|
||||||
data_dir_size=_get_dir_size(DATA_PATH) / 1024 / 1024,
|
data_list.append(SystemFolderSize(name=file, size=size, full_path=str(f), is_dir=True))
|
||||||
log_dir_size=_get_dir_size(LOG_PATH) / 1024 / 1024,
|
|
||||||
check_time=datetime.now().replace(microsecond=0),
|
|
||||||
)
|
|
||||||
return disk
|
|
||||||
else:
|
|
||||||
if type_ == "image":
|
|
||||||
dir_path = IMAGE_PATH
|
|
||||||
elif type_ == "font":
|
|
||||||
dir_path = FONT_PATH
|
|
||||||
elif type_ == "text":
|
|
||||||
dir_path = TEXT_PATH
|
|
||||||
elif type_ == "record":
|
|
||||||
dir_path = RECORD_PATH
|
|
||||||
elif type_ == "data":
|
|
||||||
dir_path = DATA_PATH
|
|
||||||
elif type_ == "temp":
|
|
||||||
dir_path = TEMP_PATH
|
|
||||||
else:
|
else:
|
||||||
dir_path = LOG_PATH
|
other_size += f.stat().st_size / 1024 / 1024
|
||||||
dir_map = {}
|
if other_size:
|
||||||
other_file_size = 0
|
data_list.append(SystemFolderSize(name='other_file', size=other_size, full_path=full_path, is_dir=False))
|
||||||
for file in os.listdir(dir_path):
|
return data_list
|
||||||
file = Path(dir_path / file)
|
# else:
|
||||||
if file.is_dir():
|
# if type_ == "image":
|
||||||
dir_map[file.name] = _get_dir_size(file) / 1024 / 1024
|
# dir_path = IMAGE_PATH
|
||||||
else:
|
# elif type_ == "font":
|
||||||
other_file_size += os.path.getsize(file) / 1024 / 1024
|
# dir_path = FONT_PATH
|
||||||
dir_map["其他文件"] = other_file_size
|
# elif type_ == "text":
|
||||||
dir_map["check_time"] = datetime.now().replace(microsecond=0)
|
# dir_path = TEXT_PATH
|
||||||
return dir_map
|
# elif type_ == "record":
|
||||||
|
# dir_path = RECORD_PATH
|
||||||
|
# elif type_ == "data":
|
||||||
|
# dir_path = DATA_PATH
|
||||||
|
# elif type_ == "temp":
|
||||||
|
# dir_path = TEMP_PATH
|
||||||
|
# else:
|
||||||
|
# dir_path = LOG_PATH
|
||||||
|
# dir_map = {}
|
||||||
|
# other_file_size = 0
|
||||||
|
# for file in os.listdir(dir_path):
|
||||||
|
# file = Path(dir_path / file)
|
||||||
|
# if file.is_dir():
|
||||||
|
# dir_map[file.name] = _get_dir_size(file) / 1024 / 1024
|
||||||
|
# else:
|
||||||
|
# other_file_size += os.path.getsize(file) / 1024 / 1024
|
||||||
|
# dir_map["其他文件"] = other_file_size
|
||||||
|
# dir_map["check_time"] = datetime.now().replace(microsecond=0)
|
||||||
|
# return dir_map
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user