Compare commits

..
3 changed files with 41 additions and 3 deletions

No files matched your search

+8
View File
@@ -89,6 +89,14 @@
- AI 配图复用 `/relay/ai/gen-image` 与每日免费生图额度,按图框宽高比自动匹配上游尺寸档位。
- 完成后一键导出 1080×1440 PNG(旋转图层同步导出)。授权应用,支持每日免费试用。
### 后台文件管理·按功能查询(2026.11 新增)
管理后台「📁 文件管理」在来源筛选旁新增**功能下拉**:按文件的 `kind`(AI 生图 / AI 换脸 / AI 海报 / 文字生图 / 标签设计 / 图片工具 / PDF 工具 / 未分类…)过滤,选项自带计数(如「AI 生图(65)」),计数随来源筛选联动;与「来源」下拉可组合使用,选择后页码自动回到第 1 页。
- 接口:`GET /admin/files?kind=<值>`,新增返回 `kinds: [{k, n}]` 分布统计(kind 过滤前统计,保证计数是当前来源下的全集);`kind=__none__` 表示未分类(无 kind 的用户根目录文件);
- 表格「类型」列同步显示中文功能名(原为 kind 英文原值);
- 仍带 `X-Admin-Token` 鉴权,无令牌 403。
### 历史记录 100 条上限(2026.11 新增)
所有功能里的历史记录最多显示 100 条(按时间倒序取最新 100 条):
+15 -2
View File
@@ -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":
+18 -1
View File
@@ -109,6 +109,17 @@ async function loadOverview() {
// ============ 文件管理(默认全量聚合,50 条/页自动分页)============
const fileUser = ref(''); // ''=全部, '__gen__'=AI生成, 其他=指定用户
const fileKind = ref(''); // 按功能筛选:''=全部功能, '__none__'=未分类, 其他=kind 原值
const fileKinds = ref<{ k: string; n: number }[]>([]); // 后端返回的 kind 分布(带计数)
const KIND_LABELS: Record<string, string> = {
gen: 'AI 生图', edit: 'AI 图片编辑', 'face-swap': 'AI 换脸', retouch: 'AI 修图',
'text-edit': 'AI 文字编辑', poster: 'AI 海报', 'text-to-image': '文字生图',
'image-lab': 'AI 图片实验室', 'image-tools': '图片工具', 'label-designer': '标签设计',
'pdf-tools': 'PDF 工具', ocr: 'OCR 识别', mcp: 'MCP 产出', __none__: '未分类',
};
function kindLabel(k: string) {
return KIND_LABELS[k] || k || '未分类';
}
const fileList = ref<any[]>([]);
const fileTotal = ref(0); // 合计字节数
const fileCount = ref(0); // 总记录数
@@ -123,10 +134,12 @@ async function loadFiles() {
const q = new URLSearchParams();
if (fileUser.value === '__gen__') q.set('scope', 'gen');
else if (fileUser.value) q.set('username', fileUser.value);
if (fileKind.value) q.set('kind', fileKind.value);
q.set('page', String(filePage.value));
q.set('page_size', String(FILE_PAGE_SIZE));
const b = await api(`/admin/files?${q}`);
fileList.value = b.data?.files ?? [];
fileKinds.value = b.data?.kinds ?? [];
fileTotal.value = b.data?.total_size ?? 0;
fileCount.value = b.data?.total ?? 0;
filePages.value = b.data?.pages ?? 1;
@@ -641,6 +654,10 @@ function switchTab(id: 'overview' | 'files' | 'usage' | 'mcp' | 'storage' | 'rec
<option value="__gen__">仅 AI 生成图片(换脸/生图/海报)</option>
<option v-for="u in users" :key="u.username" :value="u.username">仅 {{ u.username }}</option>
</select>
<select v-model="fileKind" class="adm-select" title="按功能查询文件" @change="filePage = 1; loadFiles()">
<option value="">全部功能</option>
<option v-for="k in fileKinds" :key="k.k" :value="k.k">{{ kindLabel(k.k) }}({{ k.n }})</option>
</select>
<span class="adm-sub">共 {{ fileCount }} 条记录 · 合计 {{ fmtSize(fileTotal) }}</span>
<span v-if="filePages > 1" class="adm-pager">
<button class="adm-btn adm-btn-sm" :disabled="filePage <= 1" @click="gotoFilePage(filePage - 1)">‹ 上一页</button>
@@ -680,7 +697,7 @@ function switchTab(id: 'overview' | 'files' | 'usage' | 'mcp' | 'storage' | 'rec
</td>
<td class="adm-fname" :title="f.prompt || f.name">{{ f.name }}</td>
<td>{{ fileOwner(f) }}</td>
<td>{{ f.kind || '-' }}</td>
<td>{{ kindLabel(f.kind || '__none__') }}</td>
<td>{{ fmtSize(f.size) }}</td>
<td>{{ fmtTime(f.mtime) }}</td>
<td class="adm-ops">