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":