Skip to content

Commit 9043023

Browse files
committed
add: 给存储 unique id 加一个对应的数据,以方便查看存储数据
1 parent 8e8c7ac commit 9043023

File tree

6 files changed

+120
-18
lines changed

6 files changed

+120
-18
lines changed

VERSION

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

assets/js/common.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,6 @@ class Router {
503503
this._after_handler = null
504504
this._current_path = this._get_current_path()
505505
this._routes = []
506-
this._handled = null
507506
}
508507
init() {
509508
window.addEventListener("popstate", () => {
@@ -531,7 +530,7 @@ class Router {
531530
async _popstate_handler(path) {
532531
const new_path = (path ?? this._get_current_path()).replace(this._route_prefix, "") || "/"
533532
const old_path = this._current_path
534-
if (this._handled == new_path) return;
533+
if (old_path == new_path) return;
535534
window.history.pushState(null, '', this._route_prefix + new_path)
536535
this._current_path = new_path
537536
try {

assets/js/index.js

Lines changed: 84 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,10 @@ class Menu extends Element {
148148
$style.addAll({
149149
".menu-side": {
150150
"position": "absolute",
151-
"width": "200px",
151+
"width": "216px",
152152
"height": "100%",
153-
"background": "black",//"var(--background)",
153+
"padding-left": "24px",
154+
"background": "var(--background)",
154155
"transition": "transform 500ms cubic-bezier(0, 0, 0.2, 1)",
155156
"transform": "translateX(0%)"
156157
},
@@ -163,10 +164,52 @@ class Menu extends Element {
163164
},
164165
".menu-side.hidden ~ .menu-main": {
165166
"margin-left": "0px",
166-
}
167+
},
168+
".menu-button": `
169+
-webkit-tap-highlight-color: transparent;
170+
background-color: transparent;
171+
cursor: pointer;
172+
user-select: none;
173+
vertical-align: middle;
174+
appearance: none;
175+
color: inherit;
176+
display: flex;
177+
-webkit-box-flex: 1;
178+
-webkit-box-pack: start;
179+
justify-content: flex-start;
180+
-webkit-box-align: center;
181+
align-items: center;
182+
position: relative;
183+
min-width: 0px;
184+
box-sizing: border-box;
185+
text-align: left;
186+
padding-top: 8px;
187+
padding-bottom: 8px;
188+
padding-left: 16px;
189+
padding-right: 16px;
190+
height: 46px;
191+
outline: 0px;
192+
border-width: 0px;
193+
border-style: initial;
194+
border-color: initial;
195+
border-image: initial;
196+
margin: 0px 0px 4px;
197+
text-decoration: none;
198+
transition: color 150ms cubic-bezier(0.4, 0, 0.2, 1);
199+
border-radius: 4px;
200+
`,
201+
".menu-button:hover": `
202+
color: var(--main-color);
203+
`,
204+
".menu-button.active": `
205+
background-color: var(--main-color);
206+
color: var(--dark-color);
207+
box-shadow: rgba(var(--main-color-r), var(--main-color-g), var(--main-color-b), 0.2) 0px 10px 25px 0px;
208+
`
167209
})
168210
this.$menus = {}
169211
this._render_task = null
212+
this.route_handler_lock = null;
170213
}
171214
toggle() {
172215
super.toggle("hidden")
@@ -191,30 +234,58 @@ class Menu extends Element {
191234
this._render_task = requestAnimationFrame(() => {
192235
this._render()
193236
})
237+
var cur_key, cur_sub;
238+
$router.before_handler(async (event) => {
239+
if (this._render_task) await new Promise((resolve) => {
240+
this.route_handler_lock = resolve
241+
})
242+
var page = event.current_route
243+
var [key, sub] = page.slice(1).split("/", 2)
244+
if (cur_key == key && cur_sub == sub) return;
245+
for (const [$key, $val] of Object.entries(this.$menus)) {
246+
if ($key.toLocaleLowerCase() != key.toLocaleLowerCase()) {
247+
$val.$dom.removeClasses("active")
248+
if ($val.$child) $val.$child.removeClasses("hidden")
249+
continue
250+
}
251+
$val.$dom.classes("active")
252+
if ($val.$child) $val.$child.classes("hidden")
253+
console.log($val)
254+
}
255+
cur_key = key;
256+
cur_sub = sub;
257+
})
194258
}
195259
_render() {
196260
this._render_task = null;
197261
const menu = this.$menus
198262
while (this.firstChild != null) this.removeChild(this.firstChild)
199263
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-
)
264+
var root = createElement("div").classes("menu-button").append(
265+
Utils.isDOM($val.icon) || $val.icon instanceof Element ? $val.icon : createElement("div"),
266+
createElement("p").i18n(`menu.${$key}`),
267+
).addEventListener("click", () => {
268+
$router.page(`/${$key}`)
269+
})
270+
this.append(root)
271+
menu[$key].$dom = root
206272
if ($val.children.length == 0) continue
207273
var child = createElement("div")
208274
for (const $child of $val.children) {
275+
var children = createElement("div").append(
276+
createElement("span"),
277+
createElement("p").i18n(`menu.${$key}.${$child.type}`)
278+
)
279+
menu[$key].children[$child.type].$dom = children
209280
child.append(
210-
createElement("div").append(
211-
createElement("span"),
212-
createElement("p").i18n(`menu.${$key}.${$child.type}`)
213-
)
281+
children
214282
)
215283
}
216284
this.append(child)
285+
root.append(SVGContainers.arrow_down)
286+
menu[$key].$child = child
217287
}
288+
this.route_handler_lock?.()
218289
}
219290
}
220291

core/cluster.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,10 @@ async def init():
10611061
clusters.storage_manager.add_storage(storage)
10621062
if config.const.measure_storage:
10631063
logger.tinfo("cluster.info.enable.measure_storage")
1064+
1065+
1066+
db.init_storages_key(*clusters.storage_manager.storages)
1067+
10641068
scheduler.run_later(
10651069
clusters.start, 0
10661070
)

core/database.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from collections import defaultdict
22
from dataclasses import dataclass, field
33
from enum import Enum
4+
import json
45
import time
56
from typing import Optional
67
import pyzstd
@@ -9,7 +10,7 @@
910
from sqlalchemy.orm import sessionmaker
1011
from sqlalchemy.orm.decl_api import DeclarativeMeta
1112

12-
from core import logger, scheduler, utils
13+
from core import logger, scheduler, storages, utils
1314

1415
@dataclass
1516
class StorageStatistics:
@@ -81,6 +82,12 @@ class ResponseTable(Base):
8182
ip_tables = Column(LargeBinary, nullable=False)
8283
user_agents = Column(LargeBinary, nullable=False)
8384

85+
class StorageUniqueIDTable(Base):
86+
__tablename__ = 'StorageUniqueID'
87+
id = Column(Integer, primary_key=True)
88+
unique_id = Column(String, nullable=False)
89+
data = Column(String, nullable=False)
90+
8491
class StatusType(Enum):
8592
SUCCESS = "success"
8693
PARTIAL = "partial"
@@ -306,6 +313,27 @@ def commit():
306313
except:
307314
logger.terror("database.error.write")
308315

316+
def init_storages_key(*storage: storages.iStorage):
317+
session = SESSION.get_session()
318+
for s in storage:
319+
data = {
320+
"type": s.type,
321+
"path": s.path,
322+
}
323+
if isinstance(s, storages.AlistStorage):
324+
data["url"] = s.url
325+
content = json.dumps(data, separators=(',', ':'))
326+
327+
q = session.query(StorageUniqueIDTable).filter(StorageUniqueIDTable.unique_id == s.unique_id)
328+
r = q.first() or StorageUniqueIDTable(
329+
unique_id = s.unique_id,
330+
data = content
331+
)
332+
if q.count() == 0:
333+
session.add(r)
334+
session.commit()
335+
336+
309337
async def init():
310338
Base.metadata.create_all(engine)
311339
scheduler.run_repeat_later(commit, 5, 10)

core/storages/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ class AlistStorage(iStorage):
213213
type: str = "alist"
214214
def __init__(self, path: str, weight: int, url: str, username: Optional[str], password: Optional[str], link_cache_expires: Optional[str] = None) -> None:
215215
super().__init__(path[0:-1] if path.endswith("/") else path, weight)
216-
self.url = url
216+
self.url = url.rstrip("/")
217217
self.username = username
218218
self.password = password
219219
self.can_write = username is not None and password is not None

0 commit comments

Comments
 (0)