Skip to content

Commit 09aa3eb

Browse files
committed
feat: 支持 webdav 提供直链访问
1 parent 4a56922 commit 09aa3eb

File tree

6 files changed

+172
-134
lines changed

6 files changed

+172
-134
lines changed

core/cluster.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@
1414
import pyzstd as zstd
1515
import aiohttp
1616
from tqdm import tqdm
17+
1718
from . import web
1819
from . import utils, logger, config, scheduler, units, storages, i18n
1920
from .storages import File as SFile
2021
import socketio
2122
import urllib.parse as urlparse
2223
from . import database as db
2324
from .config import USER_AGENT, API_VERSION
25+
from .utils import WrapperTQDM
2426

2527
from cryptography import x509
2628
from cryptography.hazmat.backends import default_backend
@@ -123,19 +125,19 @@ async def get_missing_files(self, files: set[File]) -> set[File | Any]:
123125
function = self._check_exists
124126

125127
await self.available()
126-
with tqdm(
128+
with WrapperTQDM(tqdm(
127129
total=len(self.available_storages) * 256,
128130
desc="List Files",
129131
unit="dir",
130132
unit_scale=True
131-
) as pbar:
133+
)) as pbar:
132134
await asyncio.gather(*(self.get_storage_filelist(storage, pbar) for storage in self.available_storages))
133-
with tqdm(
135+
with WrapperTQDM(tqdm(
134136
total=len(files) * len(self.available_storages),
135137
desc="Checking files",
136138
unit="file",
137139
unit_scale=True,
138-
) as pbar:
140+
)) as pbar:
139141
missing_files = set()
140142
waiting_files: asyncio.Queue[File] = asyncio.Queue()
141143

@@ -145,14 +147,14 @@ async def get_missing_files(self, files: set[File]) -> set[File | Any]:
145147
await asyncio.gather(*(self._get_missing_file_storage(function, missing_files, waiting_files, storage, pbar) for storage in self.available_storages))
146148
return missing_files
147149

148-
async def get_storage_filelist(self, storage: storages.iStorage, pbar: tqdm):
150+
async def get_storage_filelist(self, storage: storages.iStorage, pbar: WrapperTQDM):
149151
result = await storage.list_files(pbar)
150152
for files in result.values():
151153
for file in files:
152154
self.cache_filelist[storage][file.hash] = file
153155
return result
154156

155-
async def _get_missing_file_storage(self, function: Callable[..., Coroutine[Any, Any, bool]], missing_files: set[File], files: asyncio.Queue[File], storage: storages.iStorage, pbar: tqdm):
157+
async def _get_missing_file_storage(self, function: Callable[..., Coroutine[Any, Any, bool]], missing_files: set[File], files: asyncio.Queue[File], storage: storages.iStorage, pbar: WrapperTQDM):
156158
while not files.empty():
157159
file = await files.get()
158160
if await function(file, storage):
@@ -290,13 +292,13 @@ def __init__(self, total: int = 0, size: int = 0):
290292
self.pbar = None
291293

292294
def __enter__(self):
293-
self.pbar = tqdm(
295+
self.pbar = WrapperTQDM(tqdm(
294296
total=self.total_size,
295297
unit="b",
296298
unit_scale=True,
297299
unit_divisor=1024,
298300
desc=i18n.locale.t("cluster.processbar.download_files")
299-
)
301+
))
300302
self.downloaded_files = 0
301303
self.failed_files = 0
302304
return self
@@ -1151,6 +1153,7 @@ async def _(request: aweb.Request):
11511153
elif isinstance(storage, storages.WebDavStorage):
11521154
file = await storage.get_file(MEASURES_HASH[size])
11531155
if file.url:
1156+
logger.debug("Requested measure url:", file.url)
11541157
return aweb.HTTPFound(file.url)
11551158
elif file.size >= 0:
11561159
return aweb.Response(

core/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def rank_clusters_url(self):
170170

171171
const = Const()
172172

173-
VERSION = "3.3.7"
173+
VERSION = "3.3.8"
174174
API_VERSION = "1.13.1"
175175
USER_AGENT = f"openbmclapi/{API_VERSION} python-openbmclapi/{VERSION}"
176176
PYTHON_VERSION = ".".join(map(str, (sys.version_info.major, sys.version_info.minor, sys.version_info.micro)))

core/dashboard.py

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -232,37 +232,6 @@ async def _(request: web.Request):
232232
except:
233233
return web.json_response([])
234234

235-
@route.get("/api/system_info")
236-
async def _(request: web.Request):
237-
return web.json_response(counter.get_json())
238-
239-
@route.get("/api/count")
240-
async def _(request: web.Request):
241-
# statistics of the cluster hits and bytes
242-
session = db.SESSION.get_session()
243-
current_hour = db.get_hour()
244-
hour_of_day = (current_hour // 24) * 24
245-
next_hour = hour_of_day + 24
246-
q = session.query(db.ClusterStatisticsTable).filter(
247-
db.ClusterStatisticsTable.hour >= hour_of_day,
248-
db.ClusterStatisticsTable.hour < next_hour
249-
).all()
250-
return web.json_response({
251-
"hits": sum([int(item.hits) for item in q]), # type: ignore
252-
"bytes": sum([int(item.bytes) for item in q]) # type: ignore
253-
})
254-
255-
256-
@route.get("/api/openbmclapi/rank")
257-
async def _(request: web.Request):
258-
async with aiohttp.ClientSession(
259-
"bd.bangbang93.com"
260-
) as session:
261-
async with session.get("/openbmclapi/metric/rank") as resp:
262-
return web.json_response(
263-
await resp.json(),
264-
)
265-
266235
route.static("/assets", "./assets")
267236

268237
class JSONEncoder(json.JSONEncoder):
@@ -282,7 +251,6 @@ async def websocket_process_api(resp: web.WebSocketResponse, data: Any):
282251
return
283252
await resp.send_json(res, dumps=json_dumps)
284253

285-
286254
async def process_api(
287255
event: Optional[str],
288256
req_data: Any,

0 commit comments

Comments
 (0)