🐛 永久封存恢复前的旧取件码
This commit is contained in:
1 parent
56a86c59cf
commit
d75044e884
7 files changed
+92
-10
No files matched your search
@@ -0,0 +1,20 @@
|
||||
from tortoise import connections
|
||||
|
||||
|
||||
async def migrate():
|
||||
conn = connections.get("default")
|
||||
await conn.execute_script(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS share_code_reservations (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
code VARCHAR(255) NOT NULL UNIQUE,
|
||||
file_code_id INT NULL,
|
||||
reason VARCHAR(32) NOT NULL DEFAULT 'retired',
|
||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS idx_share_code_reservations_code
|
||||
ON share_code_reservations(code);
|
||||
CREATE INDEX IF NOT EXISTS idx_share_code_reservations_file_code_id
|
||||
ON share_code_reservations(file_code_id);
|
||||
"""
|
||||
)
|
||||
@@ -46,6 +46,19 @@ class FileCodes(models.Model):
|
||||
return f"{self.file_path}/{self.uuid_file_name}"
|
||||
|
||||
|
||||
class ShareCodeReservations(models.Model):
|
||||
"""已退役取件码的永久封存登记,防止恢复文件后旧码被重新分配。"""
|
||||
|
||||
id = fields.IntField(pk=True)
|
||||
code = fields.CharField(max_length=255, unique=True, index=True)
|
||||
file_code_id = fields.IntField(null=True, index=True)
|
||||
reason = fields.CharField(max_length=32, default="retired")
|
||||
created_at = fields.DatetimeField(auto_now_add=True)
|
||||
|
||||
class Meta:
|
||||
table = "share_code_reservations"
|
||||
|
||||
|
||||
class UploadChunk(models.Model):
|
||||
id = fields.IntField(pk=True)
|
||||
upload_id = fields.CharField(max_length=36, index=True)
|
||||
|
||||
+4
-2
@@ -8,7 +8,7 @@ from fastapi import UploadFile, HTTPException
|
||||
from typing import Optional, Tuple
|
||||
|
||||
from apps.base.dependencies import IPRateLimit
|
||||
from apps.base.models import FileCodes
|
||||
from apps.base.models import FileCodes, ShareCodeReservations
|
||||
from core.settings import settings
|
||||
from core.utils import (
|
||||
get_random_num,
|
||||
@@ -122,7 +122,9 @@ async def get_random_code(style: str | None = None) -> str:
|
||||
if code_style == "number"
|
||||
else await get_random_string(CODE_LENGTH)
|
||||
)
|
||||
if not await FileCodes.filter(code=code).exists():
|
||||
if not await FileCodes.filter(code=code).exists() and not await ShareCodeReservations.filter(
|
||||
code=code
|
||||
).exists():
|
||||
return str(code)
|
||||
raise HTTPException(status_code=503, detail="取件码生成暂时繁忙,请重试")
|
||||
|
||||
|
||||
Reference in new issue
Block a user