Skip to content

Commit

Permalink
add: 给存储 unique id 加一个对应的数据,以方便查看存储数据
Browse files Browse the repository at this point in the history
  • Loading branch information
tianxiu2b2t committed Dec 3, 2024
1 parent 8e8c7ac commit 9043023
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 18 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.20
3.0.21
3 changes: 1 addition & 2 deletions assets/js/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,6 @@ class Router {
this._after_handler = null
this._current_path = this._get_current_path()
this._routes = []
this._handled = null
}
init() {
window.addEventListener("popstate", () => {
Expand Down Expand Up @@ -531,7 +530,7 @@ class Router {
async _popstate_handler(path) {
const new_path = (path ?? this._get_current_path()).replace(this._route_prefix, "") || "/"
const old_path = this._current_path
if (this._handled == new_path) return;
if (old_path == new_path) return;
window.history.pushState(null, '', this._route_prefix + new_path)
this._current_path = new_path
try {
Expand Down
97 changes: 84 additions & 13 deletions assets/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,10 @@ class Menu extends Element {
$style.addAll({
".menu-side": {
"position": "absolute",
"width": "200px",
"width": "216px",
"height": "100%",
"background": "black",//"var(--background)",
"padding-left": "24px",
"background": "var(--background)",
"transition": "transform 500ms cubic-bezier(0, 0, 0.2, 1)",
"transform": "translateX(0%)"
},
Expand All @@ -163,10 +164,52 @@ class Menu extends Element {
},
".menu-side.hidden ~ .menu-main": {
"margin-left": "0px",
}
},
".menu-button": `
-webkit-tap-highlight-color: transparent;
background-color: transparent;
cursor: pointer;
user-select: none;
vertical-align: middle;
appearance: none;
color: inherit;
display: flex;
-webkit-box-flex: 1;
-webkit-box-pack: start;
justify-content: flex-start;
-webkit-box-align: center;
align-items: center;
position: relative;
min-width: 0px;
box-sizing: border-box;
text-align: left;
padding-top: 8px;
padding-bottom: 8px;
padding-left: 16px;
padding-right: 16px;
height: 46px;
outline: 0px;
border-width: 0px;
border-style: initial;
border-color: initial;
border-image: initial;
margin: 0px 0px 4px;
text-decoration: none;
transition: color 150ms cubic-bezier(0.4, 0, 0.2, 1);
border-radius: 4px;
`,
".menu-button:hover": `
color: var(--main-color);
`,
".menu-button.active": `
background-color: var(--main-color);
color: var(--dark-color);
box-shadow: rgba(var(--main-color-r), var(--main-color-g), var(--main-color-b), 0.2) 0px 10px 25px 0px;
`
})
this.$menus = {}
this._render_task = null
this.route_handler_lock = null;
}
toggle() {
super.toggle("hidden")
Expand All @@ -191,30 +234,58 @@ class Menu extends Element {
this._render_task = requestAnimationFrame(() => {
this._render()
})
var cur_key, cur_sub;
$router.before_handler(async (event) => {
if (this._render_task) await new Promise((resolve) => {
this.route_handler_lock = resolve
})
var page = event.current_route
var [key, sub] = page.slice(1).split("/", 2)
if (cur_key == key && cur_sub == sub) return;
for (const [$key, $val] of Object.entries(this.$menus)) {
if ($key.toLocaleLowerCase() != key.toLocaleLowerCase()) {
$val.$dom.removeClasses("active")
if ($val.$child) $val.$child.removeClasses("hidden")
continue
}
$val.$dom.classes("active")
if ($val.$child) $val.$child.classes("hidden")
console.log($val)
}
cur_key = key;
cur_sub = sub;
})
}
_render() {
this._render_task = null;
const menu = this.$menus
while (this.firstChild != null) this.removeChild(this.firstChild)
for (const [$key, $val] of Object.entries(menu)) {
this.append(
createElement("div").append(
Utils.isDOM($val.icon) || $val.icon instanceof Element ? $val.icon : createElement("div"),
createElement("p").i18n(`menu.${$key}`),
)
)
var root = createElement("div").classes("menu-button").append(
Utils.isDOM($val.icon) || $val.icon instanceof Element ? $val.icon : createElement("div"),
createElement("p").i18n(`menu.${$key}`),
).addEventListener("click", () => {
$router.page(`/${$key}`)
})
this.append(root)
menu[$key].$dom = root
if ($val.children.length == 0) continue
var child = createElement("div")
for (const $child of $val.children) {
var children = createElement("div").append(
createElement("span"),
createElement("p").i18n(`menu.${$key}.${$child.type}`)
)
menu[$key].children[$child.type].$dom = children
child.append(
createElement("div").append(
createElement("span"),
createElement("p").i18n(`menu.${$key}.${$child.type}`)
)
children
)
}
this.append(child)
root.append(SVGContainers.arrow_down)
menu[$key].$child = child
}
this.route_handler_lock?.()
}
}

Expand Down
4 changes: 4 additions & 0 deletions core/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -1061,6 +1061,10 @@ async def init():
clusters.storage_manager.add_storage(storage)
if config.const.measure_storage:
logger.tinfo("cluster.info.enable.measure_storage")


db.init_storages_key(*clusters.storage_manager.storages)

scheduler.run_later(
clusters.start, 0
)
Expand Down
30 changes: 29 additions & 1 deletion core/database.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from collections import defaultdict
from dataclasses import dataclass, field
from enum import Enum
import json
import time
from typing import Optional
import pyzstd
Expand All @@ -9,7 +10,7 @@
from sqlalchemy.orm import sessionmaker
from sqlalchemy.orm.decl_api import DeclarativeMeta

from core import logger, scheduler, utils
from core import logger, scheduler, storages, utils

@dataclass
class StorageStatistics:
Expand Down Expand Up @@ -81,6 +82,12 @@ class ResponseTable(Base):
ip_tables = Column(LargeBinary, nullable=False)
user_agents = Column(LargeBinary, nullable=False)

class StorageUniqueIDTable(Base):
__tablename__ = 'StorageUniqueID'
id = Column(Integer, primary_key=True)
unique_id = Column(String, nullable=False)
data = Column(String, nullable=False)

class StatusType(Enum):
SUCCESS = "success"
PARTIAL = "partial"
Expand Down Expand Up @@ -306,6 +313,27 @@ def commit():
except:
logger.terror("database.error.write")

def init_storages_key(*storage: storages.iStorage):
session = SESSION.get_session()
for s in storage:
data = {
"type": s.type,
"path": s.path,
}
if isinstance(s, storages.AlistStorage):
data["url"] = s.url
content = json.dumps(data, separators=(',', ':'))

q = session.query(StorageUniqueIDTable).filter(StorageUniqueIDTable.unique_id == s.unique_id)
r = q.first() or StorageUniqueIDTable(
unique_id = s.unique_id,
data = content
)
if q.count() == 0:
session.add(r)
session.commit()


async def init():
Base.metadata.create_all(engine)
scheduler.run_repeat_later(commit, 5, 10)
Expand Down
2 changes: 1 addition & 1 deletion core/storages/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ class AlistStorage(iStorage):
type: str = "alist"
def __init__(self, path: str, weight: int, url: str, username: Optional[str], password: Optional[str], link_cache_expires: Optional[str] = None) -> None:
super().__init__(path[0:-1] if path.endswith("/") else path, weight)
self.url = url
self.url = url.rstrip("/")
self.username = username
self.password = password
self.can_write = username is not None and password is not None
Expand Down

0 comments on commit 9043023

Please sign in to comment.