From ee2fc36ffd7a06878fc2df86d3290f018f22a03e Mon Sep 17 00:00:00 2001 From: kicer Date: Fri, 4 Sep 2026 15:04:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E6=96=87=E4=BB=B6=E7=AA=97?= =?UTF-8?q?=E5=8F=A3=E6=8C=89=E6=97=B6=E9=97=B4=E5=80=92=E5=BA=8F=E6=8E=92?= =?UTF-8?q?=E5=88=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/server/public/index.html | 9 ++++++++- app/server/routes/sessions.js | 18 ++++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/app/server/public/index.html b/app/server/public/index.html index 3a7b27c..5dca912 100644 --- a/app/server/public/index.html +++ b/app/server/public/index.html @@ -1367,6 +1367,11 @@ el.innerHTML = '
还没有文件,在对话框上传或让 AI 生成
'; return; } + // 后端已按创建时间倒序,这里再排一次防旧排序缓存;时间缺失排最后 + files.sort(function (a, b) { + const ca = a.ctime || a.mtime || 0, cb = b.ctime || b.mtime || 0; + return cb - ca; + }); filesAllPaths = files.map(f => f.filename); el.innerHTML = files.map(f => { // 预览策略:md/txt/html + 图片在 fs-viewer 预览(pdf 不预) @@ -1376,11 +1381,13 @@ ? '' : ''; const name = esc(String(f.filename).split('/').pop() || f.filename); + const ftime = fmtTime(f.ctime || f.mtime); return '
' + '' + '
' + '
' + name + '
' + - '
' + ico + '' + fmtSize(f.size) + '
' + + '
' + ico + '' + fmtSize(f.size) + '' + + (ftime ? '' + ftime + '' : '') + '
' + '
' + '
'; }).join(''); diff --git a/app/server/routes/sessions.js b/app/server/routes/sessions.js index 1e545a8..1e1f3a9 100644 --- a/app/server/routes/sessions.js +++ b/app/server/routes/sessions.js @@ -36,13 +36,23 @@ function listTaskFiles(dir) { const relPath = rel ? rel + '/' + e.name : e.name; if (e.isDirectory()) rec(abs, relPath); else if (e.isFile()) { - let size = null, mtime = null; - try { const st = fs.statSync(abs); size = st.size; mtime = st.mtimeMs; } catch (_) {} - out.push({ filename: relPath, size, mtime }); + let size = null, mtime = null, ctime = null; + // birthtime 在部分文件系统不可用(返回 0),回退 mtime;新生成/上传的文件两者基本一致 + try { + const st = fs.statSync(abs); + size = st.size; mtime = st.mtimeMs; + ctime = (st.birthtimeMs && st.birthtimeMs > 0 ? st.birthtimeMs : st.mtimeMs) || null; + } catch (_) {} + out.push({ filename: relPath, size, mtime, ctime }); } } })(dir, ''); - out.sort(function (a, b) { return a.filename < b.filename ? -1 : a.filename > b.filename ? 1 : 0; }); + // 按创建时间倒序(最新在前)方便查找;同一时刻按文件名升序保证稳定 + out.sort(function (a, b) { + const ca = a.ctime || a.mtime || 0, cb = b.ctime || b.mtime || 0; + if (cb !== ca) return cb - ca; + return a.filename < b.filename ? -1 : a.filename > b.filename ? 1 : 0; + }); return out; }