Skip to content

Commit 24ad5e0

Browse files
author
lan-air
committed
重构index.html
1 parent 31f67fa commit 24ad5e0

File tree

5 files changed

+150
-131
lines changed

5 files changed

+150
-131
lines changed

main.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ async def admin():
7676
async def admin_post(s: AsyncSession = Depends(get_session)):
7777
query = select(Codes)
7878
codes = (await s.execute(query)).scalars().all()
79-
return {'msg': '查询成功', 'data': codes}
79+
return {'detail': '查询成功', 'data': codes}
8080

8181

8282
@app.delete(f'/{settings.ADMIN_ADDRESS}', dependencies=[Depends(admin_required)])
@@ -86,7 +86,7 @@ async def admin_delete(code: str, s: AsyncSession = Depends(get_session)):
8686
await storage.delete_file({'type': file.type, 'text': file.text})
8787
await s.delete(file)
8888
await s.commit()
89-
return {'msg': '删除成功'}
89+
return {'detail': '删除成功'}
9090

9191

9292
@app.get('/')
@@ -101,7 +101,7 @@ async def get_file(code: str, s: AsyncSession = Depends(get_session)):
101101
if not info:
102102
raise HTTPException(status_code=404, detail="口令不存在")
103103
if info.type == 'text':
104-
return {'msg': '查询成功', 'data': info.text}
104+
return {'detail': '查询成功', 'data': info.text}
105105
else:
106106
filepath = await storage.get_filepath(info.text)
107107
return FileResponse(filepath, filename=info.name)
@@ -112,21 +112,19 @@ async def index(code: str, ip: str = Depends(ip_limit), s: AsyncSession = Depend
112112
query = select(Codes).where(Codes.code == code)
113113
info = (await s.execute(query)).scalars().first()
114114
if not info:
115-
error_count = ip_limit.add_ip(ip)
116-
raise HTTPException(status_code=404, detail=f"取件码错误,错误{settings.ERROR_COUNT - error_count}次将被禁止10分钟")
115+
error_count = settings.ERROR_COUNT - ip_limit.add_ip(ip)
116+
raise HTTPException(status_code=404, detail=f"取件码错误,错误{error_count}次将被禁止10分钟")
117117
if info.exp_time < datetime.datetime.now() or info.count == 0:
118118
await storage.delete_file({'type': info.type, 'text': info.text})
119119
await s.delete(info)
120120
await s.commit()
121121
raise HTTPException(status_code=404, detail="取件码已过期,请联系寄件人")
122-
count = info.count - 1
123-
query = update(Codes).where(Codes.id == info.id).values(count=count)
124-
await s.execute(query)
122+
await s.execute(update(Codes).where(Codes.id == info.id).values(count=info.count - 1))
125123
await s.commit()
126124
if info.type != 'text':
127125
info.text = f'/select?code={code}'
128126
return {
129-
'msg': '取件成功,请点击"取"查看',
127+
'detail': '取件成功,请点击"取"查看',
130128
'data': {'type': info.type, 'text': info.text, 'name': info.name, 'code': info.code}
131129
}
132130

@@ -170,7 +168,7 @@ async def share(text: str = Form(default=None), style: str = Form(default='2'),
170168
s.add(info)
171169
await s.commit()
172170
return {
173-
'msg': '分享成功,请点击文件箱查看取件码',
171+
'detail': '分享成功,请点击文件箱查看取件码',
174172
'data': {'code': code, 'key': key, 'name': name, 'text': _text}
175173
}
176174

static/assert/favicon.ico

264 KB
Binary file not shown.

storage.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ async def save_file(self, file, file_bytes, key):
3131
return text
3232

3333
async def delete_file(self, file):
34-
filepath = self.DATA_ROOT / file['text'].lstrip(self.STATIC_URL + '/')
35-
await asyncio.to_thread(os.remove, filepath)
34+
# 是文件就删除
35+
if file['type'] != 'text':
36+
filepath = self.DATA_ROOT / file['text'].lstrip(self.STATIC_URL + '/')
37+
await asyncio.to_thread(os.remove, filepath)
3638

3739
async def delete_files(self, files):
3840
for file in files:

templates/admin.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@
66
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
77
<meta http-equiv="X-UA-Compatible" content="ie=edge">
88
<link rel="stylesheet" href="/static/assert/index.css">
9+
<link rel="shortcut icon" href="/static/assert/favicon.ico" type="image/x-icon"/>
910
<title>后台管理-{{title}}</title>
1011
<meta name="description" content="{{description}}"/>
1112
<meta name="keywords" content="{{keywords}}"/>
1213
<meta name="generator" content="FileCodeBox"/>
1314
<meta name="template" content="Lan"/>
15+
<script src="/static/assert/vue.min.js"></script>
16+
<script src="/static/assert/index.js"></script>
1417
</head>
1518
<body>
1619
<div id="app">
@@ -57,8 +60,6 @@
5760
</div>
5861

5962
</body>
60-
<script src="/static/assert/vue.min.js"></script>
61-
<script src="/static/assert/index.js"></script>
6263
<script src="/static/assert/axios.min.js"></script>
6364
<script>
6465
new Vue({
@@ -99,7 +100,7 @@
99100
axios.delete('?code=' + code, {'headers': {'pwd': this.pwd}}).then(res => {
100101
this.files = this.files.filter(item => item.code !== code)
101102
this.$message({
102-
message: res.data.msg,
103+
message: res.data.detail,
103104
type: 'success'
104105
});
105106
})

0 commit comments

Comments
 (0)