Skip to content

Commit fd270c7

Browse files
committed
fix: 修复 Alist 缓存日志输出的问题,更新版本至 1.13.1
1 parent b6b9802 commit fd270c7

File tree

4 files changed

+90
-60
lines changed

4 files changed

+90
-60
lines changed

assets/js/index.js

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,28 @@ $style.addAll({
143143
},
144144
})
145145

146+
class Menu extends Element {
147+
constructor() {
148+
super("div").classes("menu-side")
149+
$style.addAll({
150+
".menu-side": {
151+
152+
}
153+
})
154+
}
155+
toggle() {
156+
super.toggle("hidden")
157+
}
158+
}
159+
146160
async function load() {
147161
const $dom_body = new Element(document.body);
148162
const $main = createElement("main")
163+
const $menu = new Menu();
164+
const $wrapper = createElement("wrapper").append(
165+
$menu,
166+
$main
167+
)
149168

150169
const $app = createElement("div").classes("app")
151170

@@ -157,7 +176,10 @@ async function load() {
157176
const $theme_change = createElement("div").append(
158177
$theme[$configuration.get("theme") == "light" ? "moon" : "sun"]
159178
)
160-
const $header_content_left = createElement("div").classes("content", "padding-left").append(
179+
const $header_content_left = createElement("div").classes("content").append(
180+
SVGContainers.menu.addEventListener("click", () => {
181+
182+
}),
161183
createElement("h3").text($title)
162184
);
163185
const $header_content_right = createElement("div").classes("content").append(
@@ -218,10 +240,10 @@ async function load() {
218240
const observer = new ResizeObserver((..._) => {
219241
var header = calcElementHeight($header)
220242
var height = window.innerHeight - header
221-
$main.style("height", "auto")
222-
var main = calcElementHeight($main)
223-
var height = Math.max(height, main)
224-
$main.style("height", `${height}px`)
243+
$wrapper.style("height", "auto")
244+
var wrapper = calcElementHeight($wrapper)
245+
var height = Math.max(height, wrapper)
246+
$wrapper.style("height", `${height}px`)
225247
});
226248
observer.observe($app.origin, { childList: true, subtree: true });
227249

core/cluster.py

Lines changed: 59 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -295,40 +295,45 @@ def __init__(self, clusters: 'ClusterManager'):
295295
self.task = None
296296

297297
async def _get_filelist(self, cluster: 'Cluster'):
298-
async with aiohttp.ClientSession(
299-
config.const.base_url,
300-
headers={
301-
"User-Agent": USER_AGENT,
302-
"Authorization": f"Bearer {await cluster.get_token()}"
303-
}
304-
) as session:
305-
async with session.get(
306-
f"/openbmclapi/files",
307-
params={
308-
"lastModified": str(int(self.cluster_last_modified[cluster]))
298+
try:
299+
async with aiohttp.ClientSession(
300+
config.const.base_url,
301+
headers={
302+
"User-Agent": USER_AGENT,
303+
"Authorization": f"Bearer {await cluster.get_token()}"
309304
}
310-
) as resp:
311-
body = await resp.read()
312-
if utils.is_service_error(body):
313-
utils.raise_service_error(body)
314-
return []
315-
resp.raise_for_status()
316-
if resp.status == 204:
317-
return []
318-
stream = utils.FileStream(zstd.decompress(body))
319-
filelist = [
320-
File(
321-
path=stream.read_string(),
322-
hash=stream.read_string(),
323-
size=stream.read_long(),
324-
mtime=stream.read_long()
325-
)
326-
for _ in range(stream.read_long())
327-
]
328-
if filelist:
329-
mtime = max(filelist, key=lambda f: f.mtime).mtime
330-
self.cluster_last_modified[cluster] = max(mtime, self.cluster_last_modified[cluster])
331-
return filelist
305+
) as session:
306+
async with session.get(
307+
f"/openbmclapi/files",
308+
params={
309+
"lastModified": str(int(self.cluster_last_modified[cluster]))
310+
}
311+
) as resp:
312+
body = await resp.read()
313+
if utils.is_service_error(body):
314+
utils.raise_service_error(body)
315+
return []
316+
resp.raise_for_status()
317+
if resp.status == 204:
318+
return []
319+
stream = utils.FileStream(zstd.decompress(body))
320+
filelist = [
321+
File(
322+
path=stream.read_string(),
323+
hash=stream.read_string(),
324+
size=stream.read_long(),
325+
mtime=stream.read_long()
326+
)
327+
for _ in range(stream.read_long())
328+
]
329+
if filelist:
330+
mtime = max(filelist, key=lambda f: f.mtime).mtime
331+
self.cluster_last_modified[cluster] = max(mtime, self.cluster_last_modified[cluster])
332+
return filelist
333+
except:
334+
logger.ttraceback("cluster.error.fetch_filelist", cluster=cluster.id)
335+
return []
336+
332337

333338
async def fetch_filelist(self) -> set[File]:
334339
result_filelist = set().union(*await asyncio.gather(*(asyncio.create_task(self._get_filelist(cluster)) for cluster in self.clusters.clusters)))
@@ -503,23 +508,27 @@ async def _r(urls: tuple[URLResponse, ...]):
503508

504509

505510
async def _get_configuration(self, cluster: 'Cluster'):
506-
async with aiohttp.ClientSession(
507-
config.const.base_url,
508-
headers={
509-
"User-Agent": USER_AGENT,
510-
"Authorization": f"Bearer {await cluster.get_token()}"
511-
}
512-
) as session:
513-
async with session.get(
514-
f"/openbmclapi/configuration"
515-
) as resp:
516-
body = await resp.json()
517-
if utils.raise_service_error(body):
518-
return {}
519-
resp.raise_for_status()
520-
return {
521-
k: OpenBMCLAPIConfiguration(**v) for k, v in (body).items()
511+
try:
512+
async with aiohttp.ClientSession(
513+
config.const.base_url,
514+
headers={
515+
"User-Agent": USER_AGENT,
516+
"Authorization": f"Bearer {await cluster.get_token()}"
522517
}
518+
) as session:
519+
async with session.get(
520+
f"/openbmclapi/configuration"
521+
) as resp:
522+
body = await resp.json()
523+
if utils.raise_service_error(body):
524+
return {}
525+
resp.raise_for_status()
526+
return {
527+
k: OpenBMCLAPIConfiguration(**v) for k, v in (body).items()
528+
}
529+
except:
530+
logger.ttraceback("cluster.error.configuration", cluster=cluster.id)
531+
return {}
523532

524533
class ClusterManager:
525534
def __init__(self):
@@ -961,7 +970,7 @@ def __init__(self, hash: str, size: int, mtime: float, data: bytes) -> None:
961970

962971
ROOT = Path(__file__).parent.parent
963972

964-
API_VERSION = "1.13.0"
973+
API_VERSION = "1.13.1"
965974
USER_AGENT = f"openbmclapi/{API_VERSION} python-openbmclapi/{config.VERSION}"
966975
CHECK_FILE_CONTENT = "Python OpenBMCLAPI"
967976
CHECK_FILE_MD5 = hashlib.md5(CHECK_FILE_CONTENT.encode("utf-8")).hexdigest()

core/storages/__init__.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,7 @@ def __init__(self, path: str, width: int, url: str, username: Optional[str], pas
224224
self.link_cache_timeout = utils.parse_time(link_cache_expires).to_seconds if link_cache_expires is not None else None
225225
self.link_cache: defaultdict[str, AlistLink] = defaultdict(lambda: AlistLink())
226226
scheduler.run_repeat_later(self._check_token, 0, 3600)
227-
if self.link_cache_timeout is not None:
228-
logger.tinfo("storage.info.alist.link_cache", raw=link_cache_expires, time=units.format_count_datetime(self.link_cache_timeout))
229-
else:
230-
logger.tinfo("storage.info.alist.link_cache", raw=link_cache_expires, time="disabled")
227+
logger.tinfo("storage.info.alist.link_cache", url=self.url, path=self.path, raw=link_cache_expires, time="disabled" if self.link_cache_timeout is None else units.format_count_datetime(self.link_cache_timeout))
231228
self.session = aiohttp.ClientSession(
232229
self.url
233230
)

i18n/zh_cn.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,7 @@
4949
"cluster.info.enable.measure_storage": "已开启 存储 测速",
5050
"cluster.error.init_measure_file": "无法初始化 测速文件,存储 [${path} (${type})] 大小 [${size}] 哈希 [${hash}]",
5151
"storage.info.alist.link_cache": "Alist 存储 [${url}] [${path}] 链接缓存状态 [${time} (${raw})]",
52-
"cluster.error.get_file": "获取文件 ${hash} 出错,原因:"
52+
"cluster.error.get_file": "获取文件 ${hash} 出错,原因:",
53+
"cluster.error.fetch_filelist": "无法获取 [${id}] 文件列表,原因:",
54+
"cluster.error.configuration": "无法获取 [${id}] 下载配置,原因:"
5355
}

0 commit comments

Comments
 (0)