This commit is contained in:
2025-11-02 19:17:20 +08:00
parent ebf784146e
commit e71b69db5f
2575 changed files with 1242294 additions and 95 deletions

View File

@@ -338,14 +338,15 @@ class MiaoStarsBasicApi:
r = self.request("GET", url)
# 转换响应格式以保持向后兼容
if isinstance(r, dict) and "used" in r:
if isinstance(r, dict) and r.get("code") == 0 and isinstance(r.get("data"), dict):
data = r.get("data", {})
return {
"code": 0,
"data": {
"base": r.get("total", 0) - r.get("extra", 0),
"pack": r.get("extra", 0),
"used": r.get("used", 0),
"total": r.get("total", 0),
"base": data.get("total", 0) - data.get("storage_pack_total", 0),
"pack": data.get("storage_pack_total", 0),
"used": data.get("used", 0),
"total": data.get("total", 0),
"packs": []
}
}
@@ -589,6 +590,49 @@ class MiaoStarsBasicApi:
else:
return {"code": -1, "msg": r.get("error", "文件内容更新失败")}
def renameFile(self, fileUri, newName, fileType="file"):
"""重命名文件 (Cloudreve V4 API)"""
url = "/file/rename"
# 确保传入的是正确格式的URI
if not fileUri.startswith("cloudreve://"):
logger.error(f"无效的URI格式: {fileUri}必须以cloudreve://开头")
return {"code": -1, "msg": "无效的URI格式"}
# 验证新名称不为空
if not newName or not newName.strip():
logger.error("新文件名不能为空")
return {"code": -1, "msg": "NewName cannot be empty"}
# 根据文件类型设置正确的type值
type_value = "file" if fileType == "file" else "dir"
# 构建重命名请求数据符合Cloudreve V4 API规范
data = {
"type": type_value,
"uri": fileUri,
"new_name": newName.strip()
}
# 添加详细日志,记录完整的请求数据
logger.debug(f"重命名文件请求数据 - URI: {fileUri}, 新名称: {newName.strip()}, 类型: {type_value}, 完整数据: {data}")
r = self.request("POST", url, json=data)
# 记录响应
logger.debug(f"重命名文件响应: {r}")
# 转换响应格式
if isinstance(r, dict):
if r.get("code") == 0:
return {"code": 0, "msg": "重命名成功"}
else:
error_msg = r.get("msg", r.get("error", "重命名失败"))
return {"code": -1, "msg": error_msg}
logger.error(f"重命名响应格式不正确: {r}")
return {"code": -1, "msg": "重命名失败,响应格式不正确"}
def getFileUrl(self, fileUri, redirect=False):
"""获取文件临时下载URL (Cloudreve V4 API)"""
url = "/file/url"