10BC0 fix: 修复一些已知问题 · TTB-Network/python-openbmclapi@084178c · GitHub
[go: up one dir, main page]

Skip to content

Commit 084178c

Browse files
committed
fix: 修复一些已知问题
1 parent 5739882 commit 084178c

File tree

11 files changed

+250
-45
lines changed

11 files changed

+250
-45
lines changed

assets/favicon.ico

425 Bytes
Binary file not shown.

assets/js/componts.js

Lines changed: 166 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ var cardTextStyled = false;
99
const CTMenuDefaultOptions = {
1010
icon: null,
1111
title: 'text:default',
12-
children: []
12+
children: [],
13+
defaultRoute: false
1314
}
1415
const CTMenuOptions = {
1516
width: '232px',
@@ -292,10 +293,11 @@ export class CTMenu extends CTElement {
292293
this._containers = [];
293294

294295
this._routed = false;
296+
this._defaultRouted = null;
295297
app.router.beforeHandler((event) => {
296298
if (this._routed) return;
297299
this._routed = true;
298-
var path = event.currentRoute;
300+
var path = event.currentRoute == "/" ? (this._defaultRouted ?? event.currentRoute) : event.currentRoute;
299301
var eidx = null;
300302
var cidx = null;
301303
this._containers.forEach((option, idx) => {
@@ -316,6 +318,20 @@ export class CTMenu extends CTElement {
316318
}
317319
add(options = CTMenuDefaultOptions) {
318320
let merged = Object.assign({}, CTMenuDefaultOptions, options)
321+
// find defaultRoute
322+
if (this._defaultRouted == null) {
323+
if (merged.defaultRoute) {
324+
console.log(merged.key)
325+
this._defaultRouted = merged.key;
326+
} else if (merged.children.length > 0) {
327+
for (let child of merged.children) {
328+
if (child.defaultRoute) {
329+
this._defaultRouted = merged.key + child.key;
330+
break;
331+
}
332+
}
333+
}
334+
}
319335
this._containers.push(
320336
merged
321337
)
@@ -414,7 +430,7 @@ export class CTMenu extends CTElement {
414430
var element = elements[idx];
415431
element.classes("active")
416432
if (!(idx in children)) {
417-
app.route(element.attr("link"))
433+
app.route(element.getattr("link"))
418434
return;
419435
}
420436
var subitem = children[idx];
@@ -562,7 +578,7 @@ export class CTFlex extends CTElement {
562578
}
563579
}
564580
function setTitle(element, title) {
565-
if (title == null || title instanceof CTElement || CTElement.isDOM(title)) {
581+
if (title == null || typeof title != "string" || title instanceof CTElement || CTElement.isDOM(title)) {
566582
return element;
567583
}
568584
let [type, text] = [title.slice(0, title.indexOf(":")), title.slice(title.indexOf(":") + 1)];
@@ -574,4 +590,150 @@ function setTitle(element, title) {
574590
element.text(title)
575591
}
576592
return element;
593+
}
594+
595+
export class CTEChart extends CTElement {
596+
constructor(tag = "div") {
597+
super(tag)
598+
this.instance = echarts.init(this.base);
599+
}
600+
setOption(option) {
601+
this.instance.setOption(option)
602+
}
603+
resize() {
604+
this.instance.resize()
605+
}
606+
}
607+
608+
export class CTTableObjects extends CTElement {
609+
constructor() {
610+
super("tr")
611+
}
612+
}
613+
614+
var tableOptions = {
615+
header: [],
616+
minWidth: "100%",
617+
}
618+
export class CTTable extends CTElement {
619+
constructor(
620+
options = tableOptions
621+
) {
622+
super("div").classes("ct-table-container")
623+
app.style.addStyles({
624+
".ct-table": {
625+
"width": "auto",
626+
"border-collapse": "separate",
627+
"white-space": "nowarp",
628+
"table-layout": "fixed",
629+
},
630+
".ct-table th, .ct-table td": {
631+
"padding": "8px",
632+
"text-align": "left"
633+
},
634+
".ct-table tr:hover": {
635+
"background-color": "var(--ct-table-tr-hover)"
636+
},
637+
".ct-table-container": {
638+
"width": "100%",
639+
"overflow": "auto"
640+
}
641+
})
642+
643+
// dark
644+
app.style.addThemes(
645+
"dark", {
646+
"ct-table-tr-hover": "#3f3f3f"
647+
}
648+
)
649+
650+
app.style.addThemes(
651+
"light", {
652+
"ct-table-tr-hover": "#efefef"
653+
}
654+
)
655+
656+
this.options = Object.assign({}, tableOptions, options)
657+
this.table = CTElement.create("table").classes("ct-table").style("min-width", this.options.minWidth || "100%")
658+
this.header = CTElement.create("thead").classes("ct-table-header")
659+
this.body = CTElement.create("tbody").classes("ct-table-body")
660+
661+
662+
this.bodyObjects = []
663+
664+
this.table.append(this.header, this.body)
665+
this.append(this.table)
666+
667+
this._renderTaskAll = null;
668+
this.observe = new ResizeObserver((entries) => {
669+
this.renderAll()
670+
})
671+
this.observe.observe(this.base)
672+
673+
this.renderAll()
674+
675+
}
676+
renderAll() {
677+
if (this._renderTaskAll != null) return;
678+
this._renderTaskAll = raf(() => {
679+
this._renderTaskAll = null;
680+
this.renderHeader()
681+
this.render()
682+
})
683+
}
684+
685+
renderHeader() {
686+
this.header.clear()
687+
var totalWidth = this.options.header.reduce((a, b) => a + b.width, 0)
688+
var width = this.boundingClientRect.width
689+
var tr = CTElement.create("tr")
690+
for (let th of this.options.header) {
691+
tr.append(setTitle(CTElement.create("th"), th.title).style("width", (th.width / totalWidth * width) + "px"))
692+
}
693+
this.header.append(tr)
694+
}
695+
696+
render() {
697+
if (this._renderTask != null) return;
698+
this._renderTask = raf(() => {
699+
this._renderTask = null;
700+
this.body.clear()
701+
for (let row of this.bodyObjects) {
702+
if (row.show) {
703+
this.body.append(row.tr)
704+
}
705+
}
706+
})
707+
}
708+
709+
setRows(rows) {
710+
while (rows > this.bodyObjects.length) {
711+
this.bodyObjects.push({
712+
show: true,
713+
tr: CTElement.create("tr"),
714+
})
715+
}
716+
while (rows < this.bodyObjects.length) {
717+
this.bodyObjects[this.bodyObjects.length - 1].show = false
718+
}
719+
this.render()
720+
return this
721+
}
722+
renderRow(id, handler) {
723+
var obj = this.bodyObjects[id]
724+
if (obj == null) return this;
725+
var headerLength = this.options.header.length
726+
if (obj.tr.children.length < headerLength) {
727+
for (let i = 0; i < headerLength; i++) {
728+
obj.tr.append(CTElement.create("td"))
729+
}
730+
}
731+
handler({
732+
obj: obj.tr,
733+
children: obj.tr.children,
734+
})
735+
this.render()
736+
return this
737+
}
738+
577739
}

assets/js/cttb.js

Lines changed: 52 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,15 @@ class CTI18N {
628628
return value || key;
629629
}
630630
}
631+
var tagRaves = {};
632+
export function tagRaf(tag, callback) {
633+
if (!(tag in tagRaves)) {
634+
tagRaves[tag] = requestAnimationFrame((...args) => {
635+
tagRaves[tag] = null;
636+
callback(...args)
637+
});
638+
}
639+
}
631640
export function raf(callback) {
632641
return requestAnimationFrame(callback);
633642
}
@@ -646,39 +655,62 @@ export function createRouter(
646655
return new CTRouter(prefix);
647656
}
648657
var observeOptions = {
649-
debouned: 0,
658+
debounced: 0,
650659
handler: null
651-
}
660+
};
661+
652662
export function observe(obj, options = observeOptions) {
653-
let merged = Object.assign({}, observeOptions, options);
654-
var pending = [];
655-
var task = null;
656-
return new Proxy(proxy, {
663+
// 合并默认选项和用户传入的选项
664+
const merged = {
665+
...observeOptions,
666+
...options
667+
};
668+
669+
let pending = [];
670+
let task = null;
671+
672+
return new Proxy(obj, {
657673
set(target, key, value) {
658-
if (merged.handler == null) return;
659674
target[key] = value;
660-
if (merged.debouned == 0) {
661-
handler({
675+
676+
if (merged.handler == null) return true;
677+
678+
if (merged.debounced === 0) {
679+
merged.handler({
662680
object: target,
663681
key: key,
664682
value: value
665-
})
683+
});
666684
} else {
667-
if (task != null) clearTimeout(task)
685+
if (task !== null) {
686+
clearTimeout(task);
687+
}
688+
668689
pending.push({
669690
key: key,
670691
value: value
671-
})
692+
});
693+
672694
task = setTimeout(() => {
673-
clearTimeout(task)
674-
let changes = pending.copyWithin(0, pending.length);
675-
pending = [];
676-
handler({
695+
merged.handler({
677696
object: target,
678-
changes
679-
})
680-
})
697+
changes: pending.slice()
698+
});
699+
700+
pending = [];
701+
task = null;
702+
}, merged.debounced);
681703
}
704+
705+
return true;
682706
}
683-
})
707+
});
708+
}
709+
export function executeTask(
710+
executor,
711+
time,
712+
handler, ...args
713+
) {
714+
setTimeout(handler, 0, ...args)
715+
executor(handler, time, ...args)
684716
}

core/cluster.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -538,15 +538,14 @@ async def _download_file(
538538
if hash.hexdigest() != file.hash or size != file.size:
539539
await anyio.sleep(50)
540540
raise Exception(f"hash mismatch, got {hash.hexdigest()} expected {file.hash}")
541-
541+
await self.upload_storage(file, tmp_file, size)
542+
self.update_success()
542543
except Exception as e:
543544
last_error = e
544545
self._pbar.update(-size)
545546
pbar.update(-size)
546547
self.update_failed()
547548
continue
548-
self.update_success()
549-
await self.upload_storage(file, tmp_file, size)
550549
return None
551550
if last_error is not None:
552551
raise last_error
@@ -576,6 +575,7 @@ async def upload_storage(
576575
retries += 1
577576
next = 10 * (retries + 1)
578577
logger.twarning("storage.retry_upload", name=storage.storage.name, times=retries, time=next)
578+
logger.traceback()
579579
await anyio.sleep(next)
580580

581581
async def get_configurations(self):

core/dashboard.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import fastapi
66
from fastapi.staticfiles import StaticFiles
77

8-
from .config import ROOT_PATH
8+
from .config import ROOT_PATH, DEBUG
99

1010

1111
class StreamNotice:
@@ -37,11 +37,11 @@ async def put(self, event: str, data: Any):
3737
async def setup(
3838
app: fastapi.FastAPI
3939
):
40-
# TODO: 面板
41-
return
40+
if not DEBUG:
41+
return
4242

4343
@app.get("/favicon.ico")
44-
def favicon():
44+
def _():
4545
return fastapi.responses.FileResponse(
4646
ROOT_PATH / "assets" / "favicon.ico",
4747
)

core/storage/abc.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from core import utils
77
from core.abc import BMCLAPIFile, ResponseFile, ResponseFileNotFound, ResponseFileMemory, ResponseFileLocal, ResponseFileRemote
88
from ..logger import logger
9+
from tianxiu2b2t import units
910

1011
class FileInfo:
1112
def __init__(
@@ -41,6 +42,7 @@ def __init__(
4142
name: str,
4243
path: str,
4344
weight: int,
45+
**kwargs
4446
):
4547
self._name = name
4648
self._path = CPath(path)
@@ -49,6 +51,15 @@ def __init__(
4951
self.online = False
5052
self.weight = weight
5153
self.current_weight = 0
54+
self._kwargs = kwargs
55+
56+
@property
57+
def cache_size(self):
58+
return units.parse_number_units(self._kwargs.get("cache_size", "inf"))
59+
60+
@property
61+
def cache_ttl(self):
62+
return units.parse_number_units(self._kwargs.get("cache_ttl", "10m"))
5263

5364
@abc.abstractmethod
5465
async def setup(

0 commit comments

Comments
 (0)
0