From 7036c1fc02469bda2b51a007d53403bff1847912 Mon Sep 17 00:00:00 2001 From: ktianc Date: Sat, 2 Mar 2024 19:53:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=82=E6=AD=A5=E4=B8=8A=E4=BC=A0=E4=BF=9D?= =?UTF-8?q?=E5=AD=98=E6=96=87=E4=BB=B6=E5=88=B0=E6=9C=AC=E5=9C=B0=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kinit-api/utils/file/file_manage.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/kinit-api/utils/file/file_manage.py b/kinit-api/utils/file/file_manage.py index 83043de..6b49096 100644 --- a/kinit-api/utils/file/file_manage.py +++ b/kinit-api/utils/file/file_manage.py @@ -63,19 +63,21 @@ class FileManage(FileBase): async def async_save_local(self) -> dict: """ 保存文件到本地 - :return: + :return: 示例: + { + 'local_path': 'D:\\project\\kinit_dev\\kinit-api\\static\\system\\20240301\\1709303205HuYB3mrC.png', + 'remote_path': '/media/system/20240301/1709303205HuYB3mrC.png' + } """ - path = self.path + path = AsyncPath(self.path) if sys.platform == "win32": - path = self.path.replace("/", "\\") - save_path = AsyncPath(STATIC_ROOT) / path - if not await save_path.parent.exists(): - await save_path.parent.mkdir(parents=True, exist_ok=True) - await save_path.write_bytes(await self.file.read()) - remote_path = path.replace(STATIC_ROOT, '').replace("\\", '/') + path = AsyncPath(self.path.replace("/", "\\")) + if not await path.parent.exists(): + await path.parent.mkdir(parents=True, exist_ok=True) + await path.write_bytes(await self.file.read()) return { - "local_path": path, - "remote_path": f"{STATIC_URL}/{remote_path}" + "local_path": str(path), + "remote_path": STATIC_URL + str(path).replace(STATIC_ROOT, '').replace("\\", '/') } @classmethod