From 6d50969caa082ca4f1cda1de77b34999f5908d4b Mon Sep 17 00:00:00 2001 From: jinghui Date: Sat, 14 Nov 2026 21:46:23 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20/admin/files=20=E6=94=AF=E6=8C=81=20kin?= =?UTF-8?q?d=20=E6=8C=89=E5=8A=9F=E8=83=BD=E7=AD=9B=E9=80=89=20+=20?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=20kinds=20=E5=88=86=E5=B8=83=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1;=20=E4=BF=AE=E7=94=A8=E6=88=B7=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E9=81=8D=E5=8E=86=E5=8F=98=E9=87=8F=E8=A6=86=E7=9B=96=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E5=8F=82=E6=95=B0=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/server.py b/server.py index 0b94bd3..2d3e1fe 100644 --- a/server.py +++ b/server.py @@ -1396,6 +1396,7 @@ def admin_api(method: str, sub: str, payload: dict, handler): qs = parse.parse_qs(parse.urlparse(handler.path).query) username = (qs.get("username") or [""])[0] scope = (qs.get("scope") or [""])[0] + kind = (qs.get("kind") or [""])[0] # 按功能筛选:gen/face-swap/poster/... 或 __none__=未分类 try: page = max(1, int((qs.get("page") or ["1"])[0])) except Exception: @@ -1430,7 +1431,7 @@ def admin_api(method: str, sub: str, payload: dict, handler): if not os.path.isdir(fdir): continue for root, _d, fs in os.walk(fdir): - kind = os.path.basename(root) if root != fdir else "" + ukind = os.path.basename(root) if root != fdir else "" for f in fs: fp = os.path.join(root, f) try: @@ -1440,7 +1441,7 @@ def admin_api(method: str, sub: str, payload: dict, handler): nm, mi = db_meta.get((u, f), (f, "")) ext = os.path.splitext(nm)[1].lower().lstrip(".") items.append({ - "id": f, "name": nm, "kind": kind, "size": st.st_size, + "id": f, "name": nm, "kind": ukind, "size": st.st_size, "mtime": int(st.st_mtime), "source": "user", "username": u, "mime": mi, "is_image": mi.startswith("image/") or ext in IMG_EXT, "file_type": (ext or (mi.split("/")[-1] if mi else "file") or "file").upper(), @@ -1499,6 +1500,17 @@ def admin_api(method: str, sub: str, payload: dict, handler): "file_type": (ext or "file").upper(), "path": os.path.relpath(fp, DATA_DIR), }) + # 按功能(kind)分布:在 kind 过滤之前统计,下拉计数反映 scope/username 下的全集 + _kc: dict = {} + for x in items: + k = str(x.get("kind") or "").strip() or "__none__" + _kc[k] = _kc.get(k, 0) + 1 + kinds = sorted(({"k": k, "n": n} for k, n in _kc.items()), key=lambda y: (-y["n"], y["k"])) + if kind: + if kind == "__none__": + items = [x for x in items if not str(x.get("kind") or "").strip()] + else: + items = [x for x in items if str(x.get("kind") or "").strip() == kind] items.sort(key=lambda x: -x["mtime"]) total = len(items) total_size = sum(x["size"] for x in items) @@ -1509,6 +1521,7 @@ def admin_api(method: str, sub: str, payload: dict, handler): return 200, {"code": 200, "message": "ok", "data": { "files": page_items, "total": total, "total_size": total_size, "page": page, "page_size": page_size, "pages": pages, "count": len(page_items), + "kinds": kinds, }} if method == "POST" and sub == "/cleanup":