Skip to content

Commit 8e8c7ac

Browse files
committed
fix: 修复统计存储的 unique_id 用的同一个问题
1 parent 1e2ac77 commit 8e8c7ac

File tree

6 files changed

+92
-27
lines changed

6 files changed

+92
-27
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.0.19
1+
3.0.20

assets/js/index.js

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import {
88
createElement,
99
SVGContainers,
1010
Modal,
11-
calcElementHeight
11+
calcElementHeight,
12+
Utils
1213
} from './common.js'
1314

1415
const $configuration = new Configuration();
@@ -149,7 +150,7 @@ class Menu extends Element {
149150
"position": "absolute",
150151
"width": "200px",
151152
"height": "100%",
152-
"background": "var(--background)",
153+
"background": "black",//"var(--background)",
153154
"transition": "transform 500ms cubic-bezier(0, 0, 0.2, 1)",
154155
"transform": "translateX(0%)"
155156
},
@@ -165,13 +166,55 @@ class Menu extends Element {
165166
}
166167
})
167168
this.$menus = {}
169+
this._render_task = null
168170
}
169171
toggle() {
170172
super.toggle("hidden")
171173
}
172174
add(type, icon, callback) {
173175
var path = type.replaceAll(".", "/")
174-
$router.on()
176+
$router.on(`/${path}`, callback)
177+
var [main, sub] = type.split(".", 1)
178+
if (!this.$menus[main]) {
179+
this.$menus[main] = {
180+
icon: icon,
181+
children: []
182+
}
183+
}
184+
this.$menus[main].icon = icon ? icon : this.$menus[main].icon
185+
if (sub) {
186+
this.$menus[main].children.push({
187+
type: sub
188+
})
189+
}
190+
if (this._render_task) return;
191+
this._render_task = requestAnimationFrame(() => {
192+
this._render()
193+
})
194+
}
195+
_render() {
196+
this._render_task = null;
197+
const menu = this.$menus
198+
while (this.firstChild != null) this.removeChild(this.firstChild)
199+
for (const [$key, $val] of Object.entries(menu)) {
200+
this.append(
201+
createElement("div").append(
202+
Utils.isDOM($val.icon) || $val.icon instanceof Element ? $val.icon : createElement("div"),
203+
createElement("p").i18n(`menu.${$key}`),
204+
)
205+
)
206+
if ($val.children.length == 0) continue
207+
var child = createElement("div")
208+
for (const $child of $val.children) {
209+
child.append(
210+
createElement("div").append(
211+
createElement("span"),
212+
createElement("p").i18n(`menu.${$key}.${$child.type}`)
213+
)
214+
)
215+
}
216+
this.append(child)
217+
}
175218
}
176219
}
177220

@@ -200,6 +243,10 @@ async function load() {
200243
const $main = createElement("main")
201244
const $menu = new Menu()
202245

246+
$menu.add("dashboard", "a", (...args) => {
247+
console.log("a")
248+
})
249+
203250
for (const $theme_key in $theme) {
204251
$theme[$theme_key].addEventListener("click", () => {
205252
$theme_change.removeChild($theme[$theme_key]);
@@ -230,6 +277,8 @@ async function load() {
230277
});
231278
observer.observe($app.origin, { childList: true, subtree: true });
232279

280+
$router.init()
281+
233282
}
234283
window.addEventListener("DOMContentLoaded", async () => {
235284
await load()

core/cluster.py

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,26 +1004,32 @@ async def init_measure(maxsize: int = 50):
10041004
for i in range(1, maxsize, 10):
10051005
init_measure_block(i)
10061006

1007+
async def init_measure_file(
1008+
storage: storages.iStorage,
1009+
size: int,
1010+
hash: str
1011+
):
1012+
file = File(
1013+
hash,
1014+
hash,
1015+
size * 1024 * 1024,
1016+
946684800000
1017+
)
1018+
try:
1019+
if await storage.exists(hash) and await storage.get_size(hash) == size * 1024 * 1024:
1020+
return True
1021+
await storage.write_file(
1022+
convert_file_to_storage_file(file),
1023+
MEASURE_BUFFER * 1024 * 1024 * size,
1024+
file.mtime
1025+
)
1026+
return True
1027+
except:
1028+
logger.terror("cluster.error.init_measure_file", storage=storage.path, type=storage.type, size=units.format_bytes(size * 1024 * 1024), hash=hash)
1029+
return False
10071030
async def init_measure_files():
1008-
for storage in clusters.storage_manager.storages:
1009-
for size, hash in MEASURES_HASH.items():
1010-
file = File(
1011-
hash,
1012-
hash,
1013-
size * 1024 * 1024,
1014-
946684800000
1015-
)
1016-
try:
1017-
if await storage.exists(hash) and await storage.get_size(hash) == size * 1024 * 1024:
1018-
continue
1019-
await storage.write_file(
1020-
convert_file_to_storage_file(file),
1021-
MEASURE_BUFFER * 1024 * 1024 * size,
1022-
file.mtime
1023-
)
1024-
except:
1025-
logger.terror("cluster.error.init_measure_file", storage=storage.path, type=storage.type, size=units.format_bytes(size * 1024 * 1024), hash=hash)
1026-
...
1031+
results = await asyncio.gather(*[init_measure_file(storage, size, MEASURES_HASH[size]) for storage in clusters.storage_manager.storages for size in MEASURES_HASH])
1032+
logger.debug(results)
10271033

10281034
async def init():
10291035
logger.tinfo("cluster.info.init", openbmclapi_version=API_VERSION, version=config.VERSION)
@@ -1074,7 +1080,7 @@ def check_sign(hash: str, s: str, e: str):
10741080

10751081
def get_cluster_id_from_sign(hash: str, s: str, e: str) -> Optional[str]:
10761082
for cluster in clusters.clusters:
1077-
if utils.check_sign(hash, cluster.secret, s, e):
1083+
if utils.check_sign_without_time(hash, cluster.secret, s, e):
10781084
return cluster.id
10791085
return None
10801086

core/storages/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,13 @@ def __init__(self, path: str, weight: int) -> None:
3535
raise ValueError("Cannot instantiate interface")
3636
self.path = path
3737
self.weight = weight
38-
self.unique_id = hashlib.md5(f"{self.type},{self.path}".encode("utf-8")).hexdigest()
3938
self.current_weight = 0
4039
self.cache_files = cache.MemoryStorage()
4140

41+
@property
42+
def unique_id(self) -> str:
43+
return hashlib.md5(f"{self.type},{self.path}".encode("utf-8")).hexdigest()
44+
4245
def __repr__(self) -> str:
4346
return f"{self.type}({self.path})"
4447

@@ -229,6 +232,10 @@ def __init__(self, path: str, weight: int, url: str, username: Optional[str], pa
229232
self.url
230233
)
231234

235+
@property
236+
def unique_id(self) -> str:
237+
return hashlib.md5(f"{self.type},{self.url},{self.path}".encode("utf-8")).hexdigest()
238+
232239
async def _get_token(self):
233240
await self.wait_token.wait()
234241
return str(self.fetch_token)

core/utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ def to_days(self):
182182

183183

184184
def check_sign(hash: str, secret: str, s: str, e: str) -> bool:
185+
return check_sign(hash, secret, s, e) and time.time() - 300 < int(e, 36)
186+
187+
def check_sign_without_time(hash: str, secret: str, s: str, e: str):
185188
if not s or not e:
186189
return False
187190
sign = (
@@ -191,7 +194,7 @@ def check_sign(hash: str, secret: str, s: str, e: str) -> bool:
191194
.decode()
192195
.rstrip("=")
193196
)
194-
return sign == s and time.time() - 300 < int(e, 36)
197+
return sign == s
195198

196199
def equals_hash(origin: str, content: bytes):
197200
return get_hash_hexdigest(origin, content) == origin

i18n/zh_cn.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"storage.error.alist": "Alist 返回出错,错误代码 [${status}],原因 [${message}]",
2828
"storage.debug.error_alist": "Alist 返回出错,错误代码 [${status}],原因 [${message}]",
2929
"storage.error.alist.fetch_token": "Alist 获取 Token 出错,错误代码 [${status}],原因 [${message}]",
30-
"cluster.success.keepalive": "节点 [${cluster}] 保活成功,已回原 [${hits}] 个文件,共计 [${bytes}] 流量,延迟为 [${ping}ms]",
30+
"cluster.success.keepalive": "节点 [${cluster}] 保活成功,已回源 [${hits}] 个文件,共计 [${bytes}] 流量,延迟为 [${ping}ms]",
3131
"cluster.debug.socketio.disconnected": "SocketIO 已断开连接",
3232
"cluster.debug.socketio.connected": "SocketIO 已连接",
3333
"cluster.success.cluster.disable": "节点 [${cluster}] 已正常下线",

0 commit comments

Comments
 (0)