feat: 新增存储路径自定义,修复s3存储未删除文件#246
This commit is contained in:
+12
-5
@@ -13,12 +13,19 @@ from core.utils import get_random_num, get_random_string, max_save_times_desc
|
||||
async def get_file_path_name(file: UploadFile) -> Tuple[str, str, str, str, str]:
|
||||
"""获取文件路径和文件名"""
|
||||
today = datetime.datetime.now()
|
||||
path = f"share/data/{today.strftime('%Y/%m/%d')}"
|
||||
prefix, suffix = os.path.splitext(file.filename)
|
||||
storage_path = settings.storage_path.strip('/') # 移除开头和结尾的斜杠
|
||||
file_uuid = uuid.uuid4().hex
|
||||
uuid_file_name = f"{file_uuid}{suffix}"
|
||||
save_path = f"{path}/{uuid_file_name}"
|
||||
return path, suffix, prefix, uuid_file_name, save_path
|
||||
|
||||
# 使用 UUID 作为子目录名
|
||||
base_path = f"share/data/{today.strftime('%Y/%m/%d')}/{file_uuid}"
|
||||
|
||||
# 如果设置了存储路径,将其添加到基础路径中
|
||||
path = f"{storage_path}/{base_path}" if storage_path else base_path
|
||||
|
||||
prefix, suffix = os.path.splitext(file.filename)
|
||||
# 保持原始文件名
|
||||
save_path = f"{path}/{file.filename}"
|
||||
return path, suffix, prefix, file.filename, save_path
|
||||
|
||||
|
||||
async def get_expire_info(expire_value: int, expire_style: str) -> Tuple[Optional[datetime.datetime], int, int, str]:
|
||||
|
||||
Reference in New Issue
Block a user