Skip to content

Commit

Permalink
Merge pull request #26 from TTB-Network/dev/storage
Browse files Browse the repository at this point in the history
Dev/storage
  • Loading branch information
SilianZ authored Mar 30, 2024
2 parents 73b7289 + 49f5c85 commit 3a1c7f9
Show file tree
Hide file tree
Showing 8 changed files with 305 additions and 106 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.10.1-708e4ab
v1.10.1-708e4ab
65 changes: 60 additions & 5 deletions bmclapi_dashboard/static/js/index.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const langs = {
"zh_cn": {
"dashboard": "数据统计",
"version": "版本信息",
"measure": "宽带测试",
"authentication.fetching": "获取账户信息中",
"authentication.login": "登陆",
Expand Down Expand Up @@ -238,6 +239,21 @@
".root .left .copyright": [
"position: fixed;",
"bottom: 2px",
"width: 184px",
"box-sizing: border-sizing",
"display: flex",
"justify-content: center",
"flex-direction: column",
"align-items: center"
],
".root .left .box": [
"box-sizing: border-sizing",
"border-radius: 8px",
"padding-left: 8px",
"padding-right: 8px",
"background: white",
"margin-bottom: 4px",
"margin-top: 4px"
],
".qps .icon": [
"width: 14px",
Expand Down Expand Up @@ -471,14 +487,15 @@
display_left()
update_left()
}
header.append(ttb.createElement("h3").append(ttb.createElement("a").setText(document.title).setAttribute("href", (() => {
const github = (() => {
for (child of document.head.children) {
if (child.getAttribute("github")) return "//github.com/" + child.getAttribute("github")
}
return ""
})())))
})();
header.append(ttb.createElement("h3").append(ttb.createElement("a").setText(document.title).setAttribute("href", github)))
left_copyright.append(
ttb.createElement("p").append(ttb.createElement("a").setAttribute("href", "//github.com/TTB-Network").setText("TTB Network"), " - ", ttb.VERSION)
ttb.createElement("a").class("box").setAttribute("href", "//github.com/TTB-Network").setText("TTB Network")
)
left_arrow.event("click", () => {
left.toggle("hide")
Expand Down Expand Up @@ -841,7 +858,7 @@
onopen() {
if (this._isws) ttb.createNotication("info", "", ttb.createElement("h4").setText("实时隧道已开启"))
this.send("uptime")
this.send("storage")
this.send("version")
this.send("status")
this._timer_qps?.block();
this._timer?.block()
Expand Down Expand Up @@ -1099,6 +1116,13 @@
})

}
if (type == "version") {
if (data.cur != data.latest) {
ttb.createNotication("info", "", ttb.createElement("h4").setText("有新的版本更新"), ttb.createElement("p").setText(data.latest))
}
version.version = data
version._update()
}
root_handler("_ws_message", type, data)
}
_deserializeData(input) {
Expand Down Expand Up @@ -1362,19 +1386,50 @@
page.push(...this._page)
}
}
class Version {
constructor() {
this.version = {
"cur": "Unknown",
"latest": "Unknown"
}
this._page = [
ttb.createElement("div").class("panel").append(
ttb.createElement("p").class("title").setText("当前节点版本"),
ttb.createElement("p").class("value").setText("-"),
ttb.createElement("p").class("title").setText("最新版本"),
ttb.createElement("p").class("value").setText("-"),
ttb.createElement("button").class("button").setText("查看详情").setAttribute("href").event('click', () => {
if (this.version.cur == this.version.latest) return
window.location.href = github + "/releases/" + this.version.latest
})
)
]
this._update()
}
_update() {
this._page[0].getChildrens()[1].setText(this.version.cur)
this._page[0].getChildrens()[3].setText(this.version.latest)
this._page[0].getChildrens()[4].valueOf().style.display = (this.version.cur != this.version.latest ? "" : "none")
}
connect(page) {
page.push(...this._page)
}
}
class Storage {
constructor() {
this._storages = []
}
connect() {
connect(page) {
//ws.send("storage")
}
}
const ws = new MainWebSocket()
const dashboard = new Dashboard()
const measure = new Measure()
const storage = new Storage()
const version = new Version()
menu("dashboard", "", dashboard)
menu("version", "", version)
ws.menu("measure", "", measure)
ws.setAuthInfo()
})();
Expand Down
13 changes: 2 additions & 11 deletions core/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import zlib

import aiofiles
from tqdm import tqdm

from core.config import Config

Expand All @@ -28,7 +27,7 @@ class BMCLAPIFile:
mtime: int = 0

def __hash__(self):
return int.from_bytes(bytes.fromhex(self.hash))
return int.from_bytes(bytes.fromhex(self.hash), byteorder="big")

def __eq__(self, other):
if isinstance(other, BMCLAPIFile):
Expand All @@ -47,6 +46,7 @@ class File:
size: int
last_hit: float = 0
last_access: float = 0
expiry: Optional[float] = None
data: Optional[io.BytesIO] = None
cache: bool = False

Expand Down Expand Up @@ -99,15 +99,6 @@ async def get_size(self, hash: str) -> int:
"""
raise NotImplementedError

@abc.abstractmethod
async def copy(self, origin: Path, hash: str) -> int:
"""
origin: src path
hash: desc path (new path)
return File size
"""
raise NotImplementedError

@abc.abstractmethod
async def write(self, hash: str, io: io.BytesIO) -> int:
"""
Expand Down
Loading

0 comments on commit 3a1c7f9

Please sign in to comment.