✨ 新增回收站审计与八位取件码
This commit is contained in:
1 parent
c25c495657
commit
4ee06e2d29
15 files changed
+534
-132
No files matched your search
+10
-3
@@ -96,6 +96,11 @@ async def get_expire_info(
|
||||
return expired_at, expired_count, used_count, code
|
||||
|
||||
|
||||
CODE_ALPHABET = "ABCDEFGHJKMNPQRSTUVWXYZ23456789"
|
||||
CODE_LENGTH = 8
|
||||
CODE_MAX_ATTEMPTS = 50
|
||||
|
||||
|
||||
def get_code_generate_type() -> str:
|
||||
code_generate_type = getattr(settings, "code_generate_type", "secret")
|
||||
if code_generate_type in {"secret", "string"}:
|
||||
@@ -104,20 +109,22 @@ def get_code_generate_type() -> str:
|
||||
|
||||
|
||||
async def get_random_code(style: str | None = None) -> str:
|
||||
"""生成新的 8 位取件码,并避开所有仍保留的历史审计记录。"""
|
||||
code_style = style or get_code_generate_type()
|
||||
if code_style == "num":
|
||||
code_style = "number"
|
||||
if code_style == "string":
|
||||
code_style = "secret"
|
||||
|
||||
while True:
|
||||
for _ in range(CODE_MAX_ATTEMPTS):
|
||||
code = (
|
||||
await get_random_num()
|
||||
await get_random_num(CODE_LENGTH)
|
||||
if code_style == "number"
|
||||
else await get_random_string()
|
||||
else await get_random_string(CODE_LENGTH)
|
||||
)
|
||||
if not await FileCodes.filter(code=code).exists():
|
||||
return str(code)
|
||||
raise HTTPException(status_code=503, detail="取件码生成暂时繁忙,请重试")
|
||||
|
||||
|
||||
async def calculate_file_hash(file: UploadFile, chunk_size=1024 * 1024) -> str:
|
||||
|
||||
Reference in new issue
Block a user