Skip to content

Commit f1b684e

Browse files
committed
fix: 修复漏洞
1 parent d7e9638 commit f1b684e

File tree

4 files changed

+18
-21
lines changed

4 files changed

+18
-21
lines changed

core/classes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ async def getMissingFiles(files: FileList, pbar: tqdm) -> FileList:
4646

4747
@abstractmethod
4848
async def express(
49-
hash: str, request: web.Request, response: web.StreamResponse
50-
) -> Dict[str, Any]:
49+
hash: str, counters: dict
50+
) -> web.Response:
5151
pass
5252

5353
@abstractmethod

core/router.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from core.api import getStatus
55
from core.storages import AListStorage
66
from core.logger import logger
7-
from typing import Union
87
from aiohttp import web
98
import aiohttp
109
import random
@@ -31,12 +30,10 @@ async def _(
3130
if not checkSign(file_hash, self.secret, request.query):
3231
return web.Response(text="Invalid signature.", status=403)
3332

34-
response = None
35-
data = await random.choice(self.storages).express(
36-
file_hash, request, response
33+
response = await random.choice(self.storages).express(
34+
file_hash, self.counters
3735
)
38-
self.counters["bytes"] += data["bytes"]
39-
self.counters["hits"] += data["hits"]
36+
4037
self.connection -= 1
4138
logger.debug(response)
4239
return response

core/storages/alist.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,24 +118,24 @@ async def measure(self, size: int) -> str:
118118
logger.terror("storage.error.alist.measure", e=e)
119119
return ""
120120

121-
async def express(self, hash: str, request: web.Request, response) -> Dict[str, Any]:
121+
async def express(self, hash: str, counter: dict) -> web.Response:
122122
path = f"{self.path}/{hash[:2]}/{hash}"
123123
async with aiohttp.ClientSession(self.url, headers=self.headers) as session:
124124
res = await session.post("/api/fs/get", json={"path": path, "password": self.password})
125125
data = await res.json()
126126
if data["code"] != 200:
127127
response = web.HTTPNotFound()
128-
return {"bytes": 0, "hits": 0}
128+
return response
129129
try:
130130
response = web.HTTPFound(data["data"]["raw_url"])
131131
response.headers["x-bmclapi-hash"] = hash
132-
logger.debug(data)
133-
logger.debug(response)
134-
return {"bytes": data["data"]["size"], "hits": 1}
132+
counter["bytes"] += data["data"]["size"]
133+
counter["hits"] += 1
134+
return response
135135
except Exception as e:
136136
response = web.HTTPError(text=e)
137137
logger.debug(e)
138-
return {"bytes": 0, "hits": 0}
138+
return response
139139

140140
async def writeFile(self, file: FileInfo, content: io.BytesIO, delay: int, retry: int) -> bool:
141141
file_path = f"{self.path}/{file.hash[:2]}/{file.hash}"

core/storages/local.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,22 +84,22 @@ async def checkFile(file: FileInfo, pbar: tqdm) -> bool:
8484
return FileList(files=missing_files)
8585

8686
async def express(
87-
self, hash: str, request: web.Request, response
88-
) -> Dict[str, Any]:
87+
self, hash: str, counter: dict
88+
) -> web.Response:
8989
path = os.path.join(self.path, hash[:2], hash)
9090
if not os.path.exists(path):
9191
response = web.HTTPNotFound()
92-
await response.prepare(request)
93-
return {"bytes": 0, "hits": 0}
92+
response
9493
try:
9594
file_size = os.path.getsize(path)
9695
response = web.FileResponse(path, status=200)
9796
response.headers["x-bmclapi-hash"] = hash
98-
await response.prepare(request)
99-
return {"bytes": file_size, "hits": 1}
97+
counter["bytes"] += file_size
98+
counter["hits"] += 1
99+
return response
100100
except Exception as e:
101101
logger.debug(e)
102-
return {"bytes": 0, "hits": 0}
102+
return
103103

104104
async def recycleFiles(self, files: FileList) -> None:
105105
delete_files = []

0 commit comments

Comments
 (0)