优化:文件操作模块
This commit is contained in:
parent
0a1b4f1881
commit
4a9bf1fdc3
@ -73,8 +73,8 @@ class Cache:
|
|||||||
async def get_tab_name(self, tab_name: str, retry: int = 3):
|
async def get_tab_name(self, tab_name: str, retry: int = 3):
|
||||||
"""
|
"""
|
||||||
获取系统配置
|
获取系统配置
|
||||||
:params tab_name: 配置表标签名称
|
:param tab_name: 配置表标签名称
|
||||||
:params retry_num: 重试次数
|
:param retry_num: 重试次数
|
||||||
"""
|
"""
|
||||||
result = await self.rd.get(tab_name)
|
result = await self.rd.get(tab_name)
|
||||||
if not result and retry > 0:
|
if not result and retry > 0:
|
||||||
|
@ -18,7 +18,8 @@ class FileBase:
|
|||||||
|
|
||||||
IMAGE_ACCEPT = ["image/png", "image/jpeg", "image/gif", "image/x-icon"]
|
IMAGE_ACCEPT = ["image/png", "image/jpeg", "image/gif", "image/x-icon"]
|
||||||
VIDEO_ACCEPT = ["video/mp4", "video/mpeg"]
|
VIDEO_ACCEPT = ["video/mp4", "video/mpeg"]
|
||||||
ALL_ACCEPT = [*IMAGE_ACCEPT, *VIDEO_ACCEPT]
|
AUDIO_ACCEPT = ["audio/wav", "audio/mp3", "audio/m4a", "audio/wma", "audio/ogg", "audio/mpeg", "audio/x-wav"]
|
||||||
|
ALL_ACCEPT = [*IMAGE_ACCEPT, *VIDEO_ACCEPT, *AUDIO_ACCEPT]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def generate_path(cls, path: str, filename):
|
def generate_path(cls, path: str, filename):
|
||||||
@ -29,9 +30,9 @@ class FileBase:
|
|||||||
path = path[1:]
|
path = path[1:]
|
||||||
if path[-1] == "/":
|
if path[-1] == "/":
|
||||||
path = path[:-1]
|
path = path[:-1]
|
||||||
full_date = int(datetime.datetime.now().timestamp())
|
today = str(int((datetime.datetime.now().replace(hour=0, minute=0, second=0)).timestamp()))
|
||||||
_filename = str(int(datetime.datetime.now().timestamp())) + str(uuid.uuid4())[:8]
|
_filename = str(int(datetime.datetime.now().timestamp())) + str(uuid.uuid4())[:8]
|
||||||
return f"{path}/{full_date}/{_filename}{os.path.splitext(filename)[-1]}"
|
return f"{path}/{today}/{_filename}{os.path.splitext(filename)[-1]}"
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def validate_file(cls, file: UploadFile, max_size: int = None, mime_types: list = None) -> bool:
|
async def validate_file(cls, file: UploadFile, max_size: int = None, mime_types: list = None) -> bool:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user