init project

This commit is contained in:
zwt13703
2026-07-01 19:50:29 +08:00
commit 685d69ebdc
21 changed files with 1002 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
import os
from io import BytesIO
# 先实现本地文件存储,MinIO 作为选项
STORAGE_BASE = os.getenv("LOCAL_STORAGE_PATH", "./data/files")
def save_file(content: bytes, file_path: str) -> str:
"""保存文件到本地存储,返回完整路径"""
full_path = os.path.join(STORAGE_BASE, file_path)
os.makedirs(os.path.dirname(full_path), exist_ok=True)
with open(full_path, "wb") as f:
f.write(content)
return full_path
def read_file(file_path: str) -> bytes:
"""读取文件内容"""
full_path = os.path.join(STORAGE_BASE, file_path)
with open(full_path, "rb") as f:
return f.read()
def delete_file(file_path: str):
"""删除文件"""
full_path = os.path.join(STORAGE_BASE, file_path)
if os.path.exists(full_path):
os.remove(full_path)