Skip to content

Commit 3a1c7f9

Browse files
authored
Merge pull request #26 from TTB-Network/dev/storage
Dev/storage
2 parents 73b7289 + 49f5c85 commit 3a1c7f9

File tree

8 files changed

+305
-106
lines changed

8 files changed

+305
-106
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v1.10.1-708e4ab
1+
v1.10.1-708e4ab

bmclapi_dashboard/static/js/index.min.js

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const langs = {
44
"zh_cn": {
55
"dashboard": "数据统计",
6+
"version": "版本信息",
67
"measure": "宽带测试",
78
"authentication.fetching": "获取账户信息中",
89
"authentication.login": "登陆",
@@ -238,6 +239,21 @@
238239
".root .left .copyright": [
239240
"position: fixed;",
240241
"bottom: 2px",
242+
"width: 184px",
243+
"box-sizing: border-sizing",
244+
"display: flex",
245+
"justify-content: center",
246+
"flex-direction: column",
247+
"align-items: center"
248+
],
249+
".root .left .box": [
250+
"box-sizing: border-sizing",
251+
"border-radius: 8px",
252+
"padding-left: 8px",
253+
"padding-right: 8px",
254+
"background: white",
255+
"margin-bottom: 4px",
256+
"margin-top: 4px"
241257
],
242258
".qps .icon": [
243259
"width: 14px",
@@ -471,14 +487,15 @@
471487
display_left()
472488
update_left()
473489
}
474-
header.append(ttb.createElement("h3").append(ttb.createElement("a").setText(document.title).setAttribute("href", (() => {
490+
const github = (() => {
475491
for (child of document.head.children) {
476492
if (child.getAttribute("github")) return "//github.com/" + child.getAttribute("github")
477493
}
478494
return ""
479-
})())))
495+
})();
496+
header.append(ttb.createElement("h3").append(ttb.createElement("a").setText(document.title).setAttribute("href", github)))
480497
left_copyright.append(
481-
ttb.createElement("p").append(ttb.createElement("a").setAttribute("href", "//github.com/TTB-Network").setText("TTB Network"), " - ", ttb.VERSION)
498+
ttb.createElement("a").class("box").setAttribute("href", "//github.com/TTB-Network").setText("TTB Network")
482499
)
483500
left_arrow.event("click", () => {
484501
left.toggle("hide")
@@ -841,7 +858,7 @@
841858
onopen() {
842859
if (this._isws) ttb.createNotication("info", "", ttb.createElement("h4").setText("实时隧道已开启"))
843860
this.send("uptime")
844-
this.send("storage")
861+
this.send("version")
845862
this.send("status")
846863
this._timer_qps?.block();
847864
this._timer?.block()
@@ -1099,6 +1116,13 @@
10991116
})
11001117

11011118
}
1119+
if (type == "version") {
1120+
if (data.cur != data.latest) {
1121+
ttb.createNotication("info", "", ttb.createElement("h4").setText("有新的版本更新"), ttb.createElement("p").setText(data.latest))
1122+
}
1123+
version.version = data
1124+
version._update()
1125+
}
11021126
root_handler("_ws_message", type, data)
11031127
}
11041128
_deserializeData(input) {
@@ -1362,19 +1386,50 @@
13621386
page.push(...this._page)
13631387
}
13641388
}
1389+
class Version {
1390+
constructor() {
1391+
this.version = {
1392+
"cur": "Unknown",
1393+
"latest": "Unknown"
1394+
}
1395+
this._page = [
1396+
ttb.createElement("div").class("panel").append(
1397+
ttb.createElement("p").class("title").setText("当前节点版本"),
1398+
ttb.createElement("p").class("value").setText("-"),
1399+
ttb.createElement("p").class("title").setText("最新版本"),
1400+
ttb.createElement("p").class("value").setText("-"),
1401+
ttb.createElement("button").class("button").setText("查看详情").setAttribute("href").event('click', () => {
1402+
if (this.version.cur == this.version.latest) return
1403+
window.location.href = github + "/releases/" + this.version.latest
1404+
})
1405+
)
1406+
]
1407+
this._update()
1408+
}
1409+
_update() {
1410+
this._page[0].getChildrens()[1].setText(this.version.cur)
1411+
this._page[0].getChildrens()[3].setText(this.version.latest)
1412+
this._page[0].getChildrens()[4].valueOf().style.display = (this.version.cur != this.version.latest ? "" : "none")
1413+
}
1414+
connect(page) {
1415+
page.push(...this._page)
1416+
}
1417+
}
13651418
class Storage {
13661419
constructor() {
13671420
this._storages = []
13681421
}
1369-
connect() {
1422+
connect(page) {
13701423
//ws.send("storage")
13711424
}
13721425
}
13731426
const ws = new MainWebSocket()
13741427
const dashboard = new Dashboard()
13751428
const measure = new Measure()
13761429
const storage = new Storage()
1430+
const version = new Version()
13771431
menu("dashboard", "", dashboard)
1432+
menu("version", "", version)
13781433
ws.menu("measure", "", measure)
13791434
ws.setAuthInfo()
13801435
})();

core/api.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import zlib
1010

1111
import aiofiles
12-
from tqdm import tqdm
1312

1413
from core.config import Config
1514

@@ -28,7 +27,7 @@ class BMCLAPIFile:
2827
mtime: int = 0
2928

3029
def __hash__(self):
31-
return int.from_bytes(bytes.fromhex(self.hash))
30+
return int.from_bytes(bytes.fromhex(self.hash), byteorder="big")
3231

3332
def __eq__(self, other):
3433
if isinstance(other, BMCLAPIFile):
@@ -47,6 +46,7 @@ class File:
4746
size: int
4847
last_hit: float = 0
4948
last_access: float = 0
49+
expiry: Optional[float] = None
5050
data: Optional[io.BytesIO] = None
5151
cache: bool = False
5252

@@ -99,15 +99,6 @@ async def get_size(self, hash: str) -> int:
9999
"""
100100
raise NotImplementedError
101101

102-
@abc.abstractmethod
103-
async def copy(self, origin: Path, hash: str) -> int:
104-
"""
105-
origin: src path
106-
hash: desc path (new path)
107-
return File size
108-
"""
109-
raise NotImplementedError
110-
111102
@abc.abstractmethod
112103
async def write(self, hash: str, io: io.BytesIO) -> int:
113104
"""

0 commit comments

Comments
 (0)