feat:code style
This commit is contained in:
+1
-5
@@ -22,10 +22,8 @@ async def get_file_path_name(file: UploadFile) -> Tuple[str, str, str, str, str]
|
|||||||
filename = await sanitize_filename(unquote(file.filename))
|
filename = await sanitize_filename(unquote(file.filename))
|
||||||
# 使用 UUID 作为子目录名
|
# 使用 UUID 作为子目录名
|
||||||
base_path = f"share/data/{today.strftime('%Y/%m/%d')}/{file_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
|
path = f"{storage_path}/{base_path}" if storage_path else base_path
|
||||||
|
|
||||||
prefix, suffix = os.path.splitext(filename)
|
prefix, suffix = os.path.splitext(filename)
|
||||||
# 保持原始文件名
|
# 保持原始文件名
|
||||||
save_path = f"{path}/{filename}"
|
save_path = f"{path}/{filename}"
|
||||||
@@ -43,9 +41,7 @@ async def get_chunk_file_path_name(file_name: str, upload_id: str) -> Tuple[str,
|
|||||||
return path, suffix, prefix, file_name, save_path
|
return path, suffix, prefix, file_name, save_path
|
||||||
|
|
||||||
|
|
||||||
async def get_expire_info(
|
async def get_expire_info(expire_value: int, expire_style: str) -> Tuple[Optional[datetime.datetime], int, int, str]:
|
||||||
expire_value: int, expire_style: str
|
|
||||||
) -> Tuple[Optional[datetime.datetime], int, int, str]:
|
|
||||||
"""获取过期信息"""
|
"""获取过期信息"""
|
||||||
expired_count, used_count = -1, 0
|
expired_count, used_count = -1, 0
|
||||||
now = datetime.datetime.now()
|
now = datetime.datetime.now()
|
||||||
|
|||||||
+1
-7
@@ -64,18 +64,12 @@ async def share_file(
|
|||||||
ip: str = Depends(ip_limit["upload"]),
|
ip: str = Depends(ip_limit["upload"]),
|
||||||
):
|
):
|
||||||
await validate_file_size(file, settings.uploadSize)
|
await validate_file_size(file, settings.uploadSize)
|
||||||
|
|
||||||
if expire_style not in settings.expireStyle:
|
if expire_style not in settings.expireStyle:
|
||||||
raise HTTPException(status_code=400, detail="过期时间类型错误")
|
raise HTTPException(status_code=400, detail="过期时间类型错误")
|
||||||
|
expired_at, expired_count, used_count, code = await get_expire_info(expire_value, expire_style)
|
||||||
expired_at, expired_count, used_count, code = await get_expire_info(
|
|
||||||
expire_value, expire_style
|
|
||||||
)
|
|
||||||
path, suffix, prefix, uuid_file_name, save_path = await get_file_path_name(file)
|
path, suffix, prefix, uuid_file_name, save_path = await get_file_path_name(file)
|
||||||
|
|
||||||
file_storage: FileStorageInterface = storages[settings.file_storage]()
|
file_storage: FileStorageInterface = storages[settings.file_storage]()
|
||||||
await file_storage.save_file(file, save_path)
|
await file_storage.save_file(file, save_path)
|
||||||
|
|
||||||
await create_file_code(
|
await create_file_code(
|
||||||
code=code,
|
code=code,
|
||||||
prefix=prefix,
|
prefix=prefix,
|
||||||
|
|||||||
Reference in New Issue
Block a user