Skip to content

Commit ba71942

Browse files
committed
add:解决select可跳过次数限制,新增sha256加密token,限制取件码+ip+时间999s内取件
1 parent 7864d07 commit ba71942

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

core/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@ async def get_code(s: AsyncSession):
4747

4848

4949
async def get_token(ip, code):
50-
return hashlib.sha256(f"{ip}{code}{int(time.time()) / 1000}000{settings.SECRET_KEY}".encode()).hexdigest()
50+
return hashlib.sha256(f"{ip}{code}{int(time.time() / 1000)}000{settings.ADMIN_PASSWORD}".encode()).hexdigest()

main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ async def index(code: str, ip: str = Depends(error_ip_limit), s: AsyncSession =
130130
await s.execute(update(Codes).where(Codes.id == info.id).values(count=info.count - 1))
131131
await s.commit()
132132
if info.type != 'text':
133-
info.text = f'/select?code={info.code}&token={get_token(code, ip)}'
133+
info.text = f'/select?code={info.code}&token={await get_token(code, ip)}'
134134
return {
135135
'detail': f'取件成功,请立即下载,避免失效!',
136136
'data': {'type': info.type, 'text': info.text, 'name': info.name, 'code': info.code}
@@ -150,7 +150,7 @@ async def banner(request: Request):
150150
@app.get('/select')
151151
async def get_file(code: str, token: str, ip: str = Depends(error_ip_limit), s: AsyncSession = Depends(get_session)):
152152
# 验证token
153-
if token != get_token(code, ip):
153+
if token != await get_token(code, ip):
154154
error_ip_limit.add_ip(ip)
155155
raise HTTPException(status_code=403, detail="口令错误,或已过期,次数过多将被禁止访问")
156156
# 查出数据库记录

settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import uuid
22

33
from starlette.config import Config
4+
import configparser
45

56
# 配置文件.env,存放为data/.env
67
config = Config("data/.env")

0 commit comments

Comments
 (0)