Skip to content

Commit cf96071

Browse files
committed
feat: 新增管理员编辑记录,优化取件失败提示
1 parent ffe8906 commit cf96071

28 files changed

+210
-160
lines changed

apps/admin/schemas.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import datetime
2+
from typing import Optional
13
from pydantic import BaseModel
24

35

@@ -17,3 +19,12 @@ class DeleteItem(BaseModel):
1719

1820
class LoginData(BaseModel):
1921
password: str
22+
23+
24+
class UpdateFileData(BaseModel):
25+
id: int
26+
code: Optional[str] = None
27+
prefix: Optional[str] = None
28+
suffix: Optional[str] = None
29+
expired_at: Optional[datetime.datetime] = None
30+
expired_count: Optional[int] = None

apps/admin/views.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
get_config_service,
1313
get_local_file_service,
1414
)
15-
from apps.admin.schemas import IDData, ShareItem, DeleteItem, LoginData
15+
from apps.admin.schemas import IDData, ShareItem, DeleteItem, LoginData, UpdateFileData
1616
from core.response import APIResponse
1717
from apps.base.models import FileCodes, KeyValue
1818
from apps.admin.dependencies import create_token
@@ -146,3 +146,31 @@ async def share_local_file(
146146
):
147147
share_info = await file_service.share_local_file(item)
148148
return APIResponse(detail=share_info)
149+
150+
151+
@admin_api.patch("/file/update")
152+
async def update_file(
153+
data: UpdateFileData,
154+
admin: bool = Depends(admin_required),
155+
):
156+
file_code = await FileCodes.filter(id=data.id).first()
157+
if not file_code:
158+
raise HTTPException(status_code=404, detail="文件不存在")
159+
update_data = {}
160+
161+
if data.code is not None and data.code != file_code.code:
162+
# 判断code是否存在
163+
if await FileCodes.filter(code=data.code).first():
164+
raise HTTPException(status_code=400, detail="code已存在")
165+
update_data["code"] = data.code
166+
if data.prefix is not None and data.prefix != file_code.prefix:
167+
update_data["prefix"] = data.prefix
168+
if data.suffix is not None and data.suffix != file_code.suffix:
169+
update_data["suffix"] = data.suffix
170+
if data.expired_at is not None and data.expired_at != file_code.expired_at:
171+
update_data["expired_at"] = data.expired_at
172+
if data.expired_count is not None and data.expired_count != file_code.expired_count:
173+
update_data["expired_count"] = data.expired_count
174+
175+
await file_code.update_from_dict(update_data).save()
176+
return APIResponse(detail="更新成功")

themes/2024/assets/AdminLayout-DYrcxmPJ.js renamed to themes/2024/assets/AdminLayout-CVz0dqp2.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

themes/2024/assets/DashboardView-DGe7helP.js renamed to themes/2024/assets/DashboardView-MVM0q4H3.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.animate-modal-scale{animation:modal-scale .3s ease-out}@keyframes modal-scale{0%{transform:scale(.95);opacity:0}to{transform:scale(1);opacity:1}}input:focus{transform:scale(1.002)}

0 commit comments

Comments
 (0)