Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6e086d629d |
No files matched your search
@@ -1,5 +1,16 @@
|
|||||||
# 更新日志
|
# 更新日志
|
||||||
|
|
||||||
|
## 2026-11-18 → v1.4.8
|
||||||
|
|
||||||
|
**搜索结果批量改名 + 关键词替换**——搜索出一批文件后直接对命中结果批量改名,支持把文件名中的关键词替换掉:
|
||||||
|
|
||||||
|
- ✨ **搜索结果入口**:任意搜索(Header 搜索框,模糊匹配文件名+OCR 文本)后,结果区顶部出现「批量重命名搜索结果…」按钮;打开弹窗头部徽标显示当前搜索词,范围与搜索列表完全一致(选中文件夹时含其子目录,未选中则全库)
|
||||||
|
- ✨ **新重命名模式「关键词替换」**:找什么→替换成(文件名中所有出现处全部替换);**替换成留空 = 删除该关键词**;不含关键词的文件自动跳过并在结果中报告;预览实时显示替换前后对照
|
||||||
|
- ✨ 搜索范围与列表同款 `LIKE` 模糊匹配(多关键词 AND、filename+ocr_text),后端 `POST /api/batch/rename-preview` 与 `/start` 新增 `scope='search'` + `keywords` 参数(folder 可不传,传了则按文件夹递归限定范围)
|
||||||
|
- ✨ 弹窗模式改 2×2 布局(4 种模式);关键词模式下隐藏「包含子目录」开关(搜索范围本身就含子目录);文件夹右键入口的原有三种模式行为不变
|
||||||
|
- 🛡️ 关键词与替换文本同样走文件名非法字符 `\ / : * ? " < > |` 前后端校验;预览与执行共用同一计划(命中数、跳过原因一致)
|
||||||
|
- 端到端实测:preview/scope=search 预览命中数、keyword 执行改名+DB path 同步、搜索态按钮与弹窗渲染
|
||||||
|
|
||||||
## 2026-11-18 → v1.4.7
|
## 2026-11-18 → v1.4.7
|
||||||
|
|
||||||
**文件类型自动识别(通用机制)**——原先统计卡、文件夹卡、多选条等多处硬编码「图片/N 张图片」,库里实际有图片/视频/文档三种类型(356 个文件被显示成「356 图片总数」)。现改为类型注册表驱动,**以后新增文件类型只需在注册表加一行,全站文案与统计自动识别**:
|
**文件类型自动识别(通用机制)**——原先统计卡、文件夹卡、多选条等多处硬编码「图片/N 张图片」,库里实际有图片/视频/文档三种类型(356 个文件被显示成「356 图片总数」)。现改为类型注册表驱动,**以后新增文件类型只需在注册表加一行,全站文案与统计自动识别**:
|
||||||
|
|||||||
+92
-25
@@ -195,6 +195,15 @@ async function callInpaint(imageBuffer, maskBuffer) {
|
|||||||
|
|
||||||
/** 收集文件夹内图片(含子文件夹) */
|
/** 收集文件夹内图片(含子文件夹) */
|
||||||
function collectImages(req, libraryId, folder) {
|
function collectImages(req, libraryId, folder) {
|
||||||
|
return collectRenameTargets(req, { libraryId, folder, scope: 'folder' });
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 收集重命名目标
|
||||||
|
* scope=folder(默认):文件夹递归(沿用 collectImages 语义)
|
||||||
|
* scope=search:按关键词模糊匹配整个库(filename/ocr_text LIKE,跨文件夹)
|
||||||
|
*/
|
||||||
|
function collectRenameTargets(req, { libraryId, folder, scope, keywords }) {
|
||||||
const configManager = req.app.get('configManager');
|
const configManager = req.app.get('configManager');
|
||||||
const dbPool = req.app.get('dbPool');
|
const dbPool = req.app.get('dbPool');
|
||||||
if (!configManager || !dbPool) throw new ValidationError('服务未初始化');
|
if (!configManager || !dbPool) throw new ValidationError('服务未初始化');
|
||||||
@@ -206,6 +215,13 @@ function collectImages(req, libraryId, folder) {
|
|||||||
const db = dbPool.acquire(library.path);
|
const db = dbPool.acquire(library.path);
|
||||||
try {
|
try {
|
||||||
const model = new ImageModel(db.db);
|
const model = new ImageModel(db.db);
|
||||||
|
if (scope === 'search') {
|
||||||
|
const kw = String(keywords || '').trim();
|
||||||
|
if (!kw) throw new ValidationError('搜索关键词不能为空');
|
||||||
|
// folder 与搜索列表同款过滤(含子目录):选中文件夹时范围一致,未选中则全库
|
||||||
|
const { images } = model.search({ keywords: kw, folder: folder || undefined }, null);
|
||||||
|
return { library, images };
|
||||||
|
}
|
||||||
const { images } = model.search({ folder }, null);
|
const { images } = model.search({ folder }, null);
|
||||||
return { library, images };
|
return { library, images };
|
||||||
} finally {
|
} finally {
|
||||||
@@ -320,11 +336,14 @@ const ILLEGAL_NAME_RE = /[\\/:*?"<>|]/;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 计算重命名计划(preview 与执行共用,保证一致)
|
* 计算重命名计划(preview 与执行共用,保证一致)
|
||||||
* @param {object} opts { images, folder, mode: 'prefix'|'suffix'|'replace', text, includeSubdirs }
|
* @param {object} opts { images, folder, mode: 'prefix'|'suffix'|'replace'|'keyword', text, find?, includeSubdirs }
|
||||||
|
* keyword 模式:把文件名中的 find 全部替换为 text(text 可为空 = 删除关键词),
|
||||||
|
* 不含 find 的文件标记 skipReason='不含关键词'
|
||||||
* @returns {Array<{img, newFilename, newPath, absNew, skipReason?}>}
|
* @returns {Array<{img, newFilename, newPath, absNew, skipReason?}>}
|
||||||
*/
|
*/
|
||||||
function computeRenamePlan({ images, folder, mode, text, includeSubdirs }) {
|
function computeRenamePlan({ images, folder, mode, text, find, includeSubdirs }) {
|
||||||
const cleanText = String(text || '').trim();
|
const cleanText = String(text || '').trim();
|
||||||
|
const cleanFind = String(find || '').trim();
|
||||||
let list = images;
|
let list = images;
|
||||||
if (!includeSubdirs) {
|
if (!includeSubdirs) {
|
||||||
// 只重命名该文件夹直接子项,排除子目录内文件
|
// 只重命名该文件夹直接子项,排除子目录内文件
|
||||||
@@ -357,6 +376,9 @@ function computeRenamePlan({ images, folder, mode, text, includeSubdirs }) {
|
|||||||
newBase = group.length > 1
|
newBase = group.length > 1
|
||||||
? `${cleanText}-${String(i + 1).padStart(width, '0')}`
|
? `${cleanText}-${String(i + 1).padStart(width, '0')}`
|
||||||
: cleanText;
|
: cleanText;
|
||||||
|
} else if (mode === 'keyword') {
|
||||||
|
// 关键词替换:文件名中所有出现的 find 换成 text;不含 find 跳过
|
||||||
|
newBase = base.includes(cleanFind) ? base.split(cleanFind).join(cleanText) : base;
|
||||||
} else newBase = base;
|
} else newBase = base;
|
||||||
|
|
||||||
const newFilename = `${newBase}${ext}`;
|
const newFilename = `${newBase}${ext}`;
|
||||||
@@ -364,7 +386,9 @@ function computeRenamePlan({ images, folder, mode, text, includeSubdirs }) {
|
|||||||
const absNew = newPath; // 相对库根,执行时再 join
|
const absNew = newPath; // 相对库根,执行时再 join
|
||||||
|
|
||||||
const entry = { img, newFilename, newPath, skipReason: null };
|
const entry = { img, newFilename, newPath, skipReason: null };
|
||||||
if (newFilename === img.filename) {
|
if (mode === 'keyword' && !base.includes(cleanFind)) {
|
||||||
|
entry.skipReason = '不含关键词';
|
||||||
|
} else if (newFilename === img.filename) {
|
||||||
entry.skipReason = '文件名未变化';
|
entry.skipReason = '文件名未变化';
|
||||||
} else if (used.has(newPath.toLowerCase())) {
|
} else if (used.has(newPath.toLowerCase())) {
|
||||||
entry.skipReason = '目标文件名冲突(本次内)';
|
entry.skipReason = '目标文件名冲突(本次内)';
|
||||||
@@ -377,15 +401,23 @@ function computeRenamePlan({ images, folder, mode, text, includeSubdirs }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function runRename(req, task) {
|
async function runRename(req, task) {
|
||||||
const { library, images } = collectImages(req, task.payload.libraryId, task.payload.folder);
|
const p = task.payload;
|
||||||
|
const { library, images } = collectRenameTargets(req, {
|
||||||
|
libraryId: p.libraryId,
|
||||||
|
folder: p.folder,
|
||||||
|
scope: p.scope,
|
||||||
|
keywords: p.keywords
|
||||||
|
});
|
||||||
const opts = task.payload.options;
|
const opts = task.payload.options;
|
||||||
|
const isSearch = p.scope === 'search';
|
||||||
|
|
||||||
const plan = computeRenamePlan({
|
const plan = computeRenamePlan({
|
||||||
images,
|
images,
|
||||||
folder: task.payload.folder,
|
folder: task.payload.folder,
|
||||||
mode: opts.mode,
|
mode: opts.mode,
|
||||||
text: opts.text,
|
text: opts.text,
|
||||||
includeSubdirs: opts.includeSubdirs !== false
|
find: opts.find,
|
||||||
|
includeSubdirs: isSearch ? true : opts.includeSubdirs !== false
|
||||||
});
|
});
|
||||||
task.total = plan.length;
|
task.total = plan.length;
|
||||||
|
|
||||||
@@ -439,26 +471,40 @@ async function runRename(req, task) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* POST /api/batch/rename-preview
|
* POST /api/batch/rename-preview
|
||||||
* body: { libraryId, folder, options: { mode, text, includeSubdirs } }
|
* body: { libraryId, folder?, scope?: 'folder'|'search', keywords?, options: { mode, text, find?, includeSubdirs } }
|
||||||
|
* scope=search 时按 keywords 模糊匹配全库(跨文件夹),folder 可不传
|
||||||
* 返回重命名预览(不执行)
|
* 返回重命名预览(不执行)
|
||||||
*/
|
*/
|
||||||
router.post(
|
router.post(
|
||||||
'/rename-preview',
|
'/rename-preview',
|
||||||
asyncHandler(async (req, res) => {
|
asyncHandler(async (req, res) => {
|
||||||
const { libraryId, folder, options } = req.body || {};
|
const { libraryId, folder, scope, options } = req.body || {};
|
||||||
if (!libraryId || !folder) throw new ValidationError('缺少 libraryId 或 folder');
|
if (!libraryId) throw new ValidationError('缺少 libraryId');
|
||||||
|
const isSearch = scope === 'search';
|
||||||
|
if (!isSearch && !folder) throw new ValidationError('缺少 libraryId 或 folder');
|
||||||
const mode = options && options.mode;
|
const mode = options && options.mode;
|
||||||
if (!['prefix', 'suffix', 'replace'].includes(mode)) {
|
if (!['prefix', 'suffix', 'replace', 'keyword'].includes(mode)) {
|
||||||
throw new ValidationError('mode 必须是 prefix / suffix / replace');
|
throw new ValidationError('mode 必须是 prefix / suffix / replace / keyword');
|
||||||
}
|
}
|
||||||
const text = String((options && options.text) || '').trim();
|
const text = String((options && options.text) || '').trim();
|
||||||
if (!text) throw new ValidationError('重命名文本不能为空');
|
const find = String((options && options.find) || '').trim();
|
||||||
if (ILLEGAL_NAME_RE.test(text)) throw new ValidationError('文本包含文件名非法字符 \\ / : * ? " < > |');
|
if (mode === 'keyword') {
|
||||||
|
if (!find) throw new ValidationError('请填写要查找的关键词');
|
||||||
|
if (ILLEGAL_NAME_RE.test(find)) throw new ValidationError('关键词包含文件名非法字符 \\ / : * ? " < > |');
|
||||||
|
if (ILLEGAL_NAME_RE.test(text)) throw new ValidationError('替换文本包含文件名非法字符 \\ / : * ? " < > |');
|
||||||
|
} else {
|
||||||
|
if (!text) throw new ValidationError('重命名文本不能为空');
|
||||||
|
if (ILLEGAL_NAME_RE.test(text)) throw new ValidationError('文本包含文件名非法字符 \\ / : * ? " < > |');
|
||||||
|
}
|
||||||
|
|
||||||
const { images } = collectImages(req, libraryId, folder);
|
const targets = collectRenameTargets(req, {
|
||||||
|
libraryId, folder, scope, keywords: options && options.keywords
|
||||||
|
});
|
||||||
const plan = computeRenamePlan({
|
const plan = computeRenamePlan({
|
||||||
images, folder, mode, text,
|
images: targets.images,
|
||||||
includeSubdirs: options.includeSubdirs !== false
|
folder: isSearch ? null : folder,
|
||||||
|
mode, text, find,
|
||||||
|
includeSubdirs: isSearch ? true : options.includeSubdirs !== false
|
||||||
});
|
});
|
||||||
const effective = plan.filter((p) => !p.skipReason);
|
const effective = plan.filter((p) => !p.skipReason);
|
||||||
res.json({
|
res.json({
|
||||||
@@ -479,20 +525,28 @@ router.post(
|
|||||||
router.post(
|
router.post(
|
||||||
'/start',
|
'/start',
|
||||||
asyncHandler(async (req, res) => {
|
asyncHandler(async (req, res) => {
|
||||||
const { libraryId, folder, type, output, options } = req.body || {};
|
const { libraryId, folder, type, output, options, scope } = req.body || {};
|
||||||
if (!libraryId || !folder) throw new ValidationError('缺少 libraryId 或 folder');
|
if (!libraryId) throw new ValidationError('缺少 libraryId');
|
||||||
|
const isSearch = type === 'rename' && scope === 'search';
|
||||||
|
if (!folder && !isSearch) throw new ValidationError('缺少 libraryId 或 folder');
|
||||||
if (!['add', 'remove', 'rename'].includes(type)) throw new ValidationError('type 必须是 add / remove / rename');
|
if (!['add', 'remove', 'rename'].includes(type)) throw new ValidationError('type 必须是 add / remove / rename');
|
||||||
|
|
||||||
if (type === 'add') {
|
if (type === 'add') {
|
||||||
if (!options || !String(options.text || '').trim()) throw new ValidationError('水印文字不能为空');
|
if (!options || !String(options.text || '').trim()) throw new ValidationError('水印文字不能为空');
|
||||||
} else if (type === 'rename') {
|
} else if (type === 'rename') {
|
||||||
const mode = options && options.mode;
|
const mode = options && options.mode;
|
||||||
if (!['prefix', 'suffix', 'replace'].includes(mode)) {
|
if (!['prefix', 'suffix', 'replace', 'keyword'].includes(mode)) {
|
||||||
throw new ValidationError('mode 必须是 prefix / suffix / replace');
|
throw new ValidationError('mode 必须是 prefix / suffix / replace / keyword');
|
||||||
}
|
}
|
||||||
if (!String(options.text || '').trim()) throw new ValidationError('重命名文本不能为空');
|
const text = String((options && options.text) || '').trim();
|
||||||
if (ILLEGAL_NAME_RE.test(String(options.text).trim())) {
|
const find = String((options && options.find) || '').trim();
|
||||||
throw new ValidationError('文本包含文件名非法字符 \\ / : * ? " < > |');
|
if (mode === 'keyword') {
|
||||||
|
if (!find) throw new ValidationError('请填写要查找的关键词');
|
||||||
|
if (ILLEGAL_NAME_RE.test(find)) throw new ValidationError('关键词包含文件名非法字符 \\ / : * ? " < > |');
|
||||||
|
if (ILLEGAL_NAME_RE.test(text)) throw new ValidationError('替换文本包含文件名非法字符 \\ / : * ? " < > |');
|
||||||
|
} else {
|
||||||
|
if (!text) throw new ValidationError('重命名文本不能为空');
|
||||||
|
if (ILLEGAL_NAME_RE.test(text)) throw new ValidationError('文本包含文件名非法字符 \\ / : * ? " < > |');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const r = options && options.region;
|
const r = options && options.region;
|
||||||
@@ -502,10 +556,23 @@ router.post(
|
|||||||
if (r.w <= 0 || r.h <= 0) throw new ValidationError('水印区域宽高必须大于 0');
|
if (r.w <= 0 || r.h <= 0) throw new ValidationError('水印区域宽高必须大于 0');
|
||||||
}
|
}
|
||||||
|
|
||||||
const { images } = collectImages(req, libraryId, folder);
|
const { images } = collectRenameTargets(req, {
|
||||||
if (images.length === 0) throw new ValidationError(type === 'rename' ? '该文件夹下没有文件' : '该文件夹下没有图片');
|
libraryId, folder, scope, keywords: options && options.keywords
|
||||||
|
});
|
||||||
|
if (images.length === 0) {
|
||||||
|
throw new ValidationError(
|
||||||
|
scope === 'search' ? '搜索没有匹配到文件' : (type === 'rename' ? '该文件夹下没有文件' : '该文件夹下没有图片')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const task = newTask(type, { libraryId, folder, output, options });
|
const task = newTask(type, {
|
||||||
|
libraryId,
|
||||||
|
folder: folder || null,
|
||||||
|
scope: scope || 'folder',
|
||||||
|
keywords: scope === 'search' ? String(options?.keywords || '').trim() : null,
|
||||||
|
output,
|
||||||
|
options
|
||||||
|
});
|
||||||
task.total = images.length;
|
task.total = images.length;
|
||||||
logger.info(`▶️ 批量${type === 'add' ? '加水印' : type === 'remove' ? '去水印' : '重命名'}启动: ${folder} (${images.length} 张)`);
|
logger.info(`▶️ 批量${type === 'add' ? '加水印' : type === 'remove' ? '去水印' : '重命名'}启动: ${folder} (${images.length} 张)`);
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ const { getSettings } = require('./settings');
|
|||||||
const HUB_URL = (process.env.HUB_URL || 'https://auth.88531.cn/api').replace(/\/+$/, '');
|
const HUB_URL = (process.env.HUB_URL || 'https://auth.88531.cn/api').replace(/\/+$/, '');
|
||||||
const HUB_PROJECT_ID = process.env.HUB_PROJECT_ID || '';
|
const HUB_PROJECT_ID = process.env.HUB_PROJECT_ID || '';
|
||||||
const HUB_API_KEY = process.env.HUB_API_KEY || '';
|
const HUB_API_KEY = process.env.HUB_API_KEY || '';
|
||||||
const SITE_VERSION = process.env.SITE_VERSION || '1.4.7';
|
const SITE_VERSION = process.env.SITE_VERSION || '1.4.8';
|
||||||
const TIMEOUT_MS = 8000;
|
const TIMEOUT_MS = 8000;
|
||||||
|
|
||||||
const state = {
|
const state = {
|
||||||
|
|||||||
+1
-1
@@ -28,7 +28,7 @@ services:
|
|||||||
- HUB_API_KEY=${HUB_API_KEY:-}
|
- HUB_API_KEY=${HUB_API_KEY:-}
|
||||||
- NEWAPI_KEY=${NEWAPI_KEY:-}
|
- NEWAPI_KEY=${NEWAPI_KEY:-}
|
||||||
# 当前站点版本(与 frontend/package.json、CHANGELOG 保持一致,界面版本徽标来源)
|
# 当前站点版本(与 frontend/package.json、CHANGELOG 保持一致,界面版本徽标来源)
|
||||||
- SITE_VERSION=1.4.7
|
- SITE_VERSION=1.4.8
|
||||||
# 让容器经 host.docker.internal 访问宿主机的 AI 侧车
|
# 让容器经 host.docker.internal 访问宿主机的 AI 侧车
|
||||||
extra_hosts:
|
extra_hosts:
|
||||||
- "host.docker.internal:host-gateway"
|
- "host.docker.internal:host-gateway"
|
||||||
|
|||||||
@@ -15,15 +15,17 @@ import { batchAPI } from '../api';
|
|||||||
const MODES = [
|
const MODES = [
|
||||||
{ key: 'prefix', label: '前面加', desc: '在原文件名前加文本', hint: '文本 + 原文件名 + 扩展名' },
|
{ key: 'prefix', label: '前面加', desc: '在原文件名前加文本', hint: '文本 + 原文件名 + 扩展名' },
|
||||||
{ key: 'suffix', label: '后面加', desc: '在原文件名后加文本', hint: '原文件名 + 文本 + 扩展名' },
|
{ key: 'suffix', label: '后面加', desc: '在原文件名后加文本', hint: '原文件名 + 文本 + 扩展名' },
|
||||||
{ key: 'replace', label: '全部改名', desc: '原文件名替换为文本', hint: '同目录多个文件自动编号:文本-001、文本-002…' }
|
{ key: 'replace', label: '全部改名', desc: '原文件名替换为文本', hint: '同目录多个文件自动编号:文本-001、文本-002…' },
|
||||||
|
{ key: 'keyword', label: '关键词替换', desc: '替换文件名中的关键词', hint: '把文件名中的「找什么」全部换成「替换成」,替换成留空 = 删除该关键词' }
|
||||||
];
|
];
|
||||||
|
|
||||||
const ILLEGAL_RE = /[\\/:*?"<>|]/;
|
const ILLEGAL_RE = /[\\/:*?"<>|]/;
|
||||||
|
|
||||||
function BatchRenameModal({ isOpen, folder, libraryId, onClose, onFinished }) {
|
function BatchRenameModal({ isOpen, folder, libraryId, scope, keywords, onClose, onFinished }) {
|
||||||
const [phase, setPhase] = useState('config'); // config | running | done
|
const [phase, setPhase] = useState('config'); // config | running | done
|
||||||
const [mode, setMode] = useState('prefix');
|
const [mode, setMode] = useState('prefix');
|
||||||
const [text, setText] = useState('');
|
const [text, setText] = useState('');
|
||||||
|
const [find, setFind] = useState('');
|
||||||
const [includeSubdirs, setIncludeSubdirs] = useState(true);
|
const [includeSubdirs, setIncludeSubdirs] = useState(true);
|
||||||
const [preview, setPreview] = useState(null); // { count, total, samples, skipped }
|
const [preview, setPreview] = useState(null); // { count, total, samples, skipped }
|
||||||
const [previewErr, setPreviewErr] = useState('');
|
const [previewErr, setPreviewErr] = useState('');
|
||||||
@@ -48,6 +50,7 @@ function BatchRenameModal({ isOpen, folder, libraryId, onClose, onFinished }) {
|
|||||||
setPhase('config');
|
setPhase('config');
|
||||||
setMode('prefix');
|
setMode('prefix');
|
||||||
setText('');
|
setText('');
|
||||||
|
setFind('');
|
||||||
setIncludeSubdirs(true);
|
setIncludeSubdirs(true);
|
||||||
setPreview(null);
|
setPreview(null);
|
||||||
setPreviewErr('');
|
setPreviewErr('');
|
||||||
@@ -59,11 +62,11 @@ function BatchRenameModal({ isOpen, folder, libraryId, onClose, onFinished }) {
|
|||||||
}, [isOpen, stopPolling]);
|
}, [isOpen, stopPolling]);
|
||||||
|
|
||||||
// 实时预览(防抖 300ms)
|
// 实时预览(防抖 300ms)
|
||||||
|
const needInput = mode === 'keyword' ? find.trim() : text.trim();
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isOpen || phase !== 'config') return;
|
if (!isOpen || phase !== 'config') return;
|
||||||
if (previewTimerRef.current) clearTimeout(previewTimerRef.current);
|
if (previewTimerRef.current) clearTimeout(previewTimerRef.current);
|
||||||
const t = text.trim();
|
if (!needInput) {
|
||||||
if (!t) {
|
|
||||||
setPreview(null);
|
setPreview(null);
|
||||||
setPreviewErr('');
|
setPreviewErr('');
|
||||||
return;
|
return;
|
||||||
@@ -71,8 +74,8 @@ function BatchRenameModal({ isOpen, folder, libraryId, onClose, onFinished }) {
|
|||||||
previewTimerRef.current = setTimeout(async () => {
|
previewTimerRef.current = setTimeout(async () => {
|
||||||
try {
|
try {
|
||||||
const resp = await batchAPI.renamePreview({
|
const resp = await batchAPI.renamePreview({
|
||||||
libraryId, folder,
|
libraryId, folder, scope, keywords,
|
||||||
options: { mode, text: t, includeSubdirs }
|
options: { mode, text: text.trim(), find: find.trim(), keywords: keywords || undefined, includeSubdirs }
|
||||||
});
|
});
|
||||||
setPreview(resp);
|
setPreview(resp);
|
||||||
setPreviewErr('');
|
setPreviewErr('');
|
||||||
@@ -82,7 +85,7 @@ function BatchRenameModal({ isOpen, folder, libraryId, onClose, onFinished }) {
|
|||||||
}
|
}
|
||||||
}, 300);
|
}, 300);
|
||||||
return () => { if (previewTimerRef.current) clearTimeout(previewTimerRef.current); };
|
return () => { if (previewTimerRef.current) clearTimeout(previewTimerRef.current); };
|
||||||
}, [isOpen, phase, mode, text, includeSubdirs, libraryId, folder]);
|
}, [isOpen, phase, mode, text, find, includeSubdirs, libraryId, folder, scope, keywords, needInput]);
|
||||||
|
|
||||||
const startPolling = useCallback((id) => {
|
const startPolling = useCallback((id) => {
|
||||||
stopPolling();
|
stopPolling();
|
||||||
@@ -102,19 +105,35 @@ function BatchRenameModal({ isOpen, folder, libraryId, onClose, onFinished }) {
|
|||||||
const handleStart = async () => {
|
const handleStart = async () => {
|
||||||
setError('');
|
setError('');
|
||||||
const t = text.trim();
|
const t = text.trim();
|
||||||
if (!t) {
|
const f = find.trim();
|
||||||
setError('请输入重命名文本');
|
if (mode === 'keyword') {
|
||||||
return;
|
if (!f) {
|
||||||
}
|
setError('请填写要查找的关键词');
|
||||||
if (ILLEGAL_RE.test(t)) {
|
return;
|
||||||
setError('文本包含文件名非法字符 \\ / : * ? " < > |');
|
}
|
||||||
return;
|
if (ILLEGAL_RE.test(f)) {
|
||||||
|
setError('关键词包含文件名非法字符 \\ / : * ? " < > |');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (ILLEGAL_RE.test(t)) {
|
||||||
|
setError('替换文本包含文件名非法字符 \\ / : * ? " < > |');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!t) {
|
||||||
|
setError('请输入重命名文本');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (ILLEGAL_RE.test(t)) {
|
||||||
|
setError('文本包含文件名非法字符 \\ / : * ? " < > |');
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
setStarting(true);
|
setStarting(true);
|
||||||
try {
|
try {
|
||||||
const resp = await batchAPI.start({
|
const resp = await batchAPI.start({
|
||||||
libraryId, folder, type: 'rename',
|
libraryId, folder, scope, keywords, type: 'rename',
|
||||||
options: { mode, text: t, includeSubdirs }
|
options: { mode, text: t, find: f, keywords: keywords || undefined, includeSubdirs }
|
||||||
});
|
});
|
||||||
setTaskId(resp.taskId);
|
setTaskId(resp.taskId);
|
||||||
setPhase('running');
|
setPhase('running');
|
||||||
@@ -161,7 +180,7 @@ function BatchRenameModal({ isOpen, folder, libraryId, onClose, onFinished }) {
|
|||||||
<Replace className="w-5 h-5 text-violet-500" />
|
<Replace className="w-5 h-5 text-violet-500" />
|
||||||
<h2 className="text-lg font-semibold text-gray-900 dark:text-white">批量重命名文件</h2>
|
<h2 className="text-lg font-semibold text-gray-900 dark:text-white">批量重命名文件</h2>
|
||||||
<span className="text-xs px-2 py-0.5 rounded-full bg-gray-100 dark:bg-gray-700 text-gray-600 dark:text-gray-300 truncate max-w-[240px]">
|
<span className="text-xs px-2 py-0.5 rounded-full bg-gray-100 dark:bg-gray-700 text-gray-600 dark:text-gray-300 truncate max-w-[240px]">
|
||||||
{folder}
|
{scope === 'search' ? `搜索:${keywords}` : folder}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<button onClick={handleClose} className="p-1 rounded hover:bg-gray-100 dark:hover:bg-gray-700">
|
<button onClick={handleClose} className="p-1 rounded hover:bg-gray-100 dark:hover:bg-gray-700">
|
||||||
@@ -176,7 +195,7 @@ function BatchRenameModal({ isOpen, folder, libraryId, onClose, onFinished }) {
|
|||||||
{/* 重命名模式 */}
|
{/* 重命名模式 */}
|
||||||
<div className="mb-4">
|
<div className="mb-4">
|
||||||
<div className="text-xs font-medium text-gray-500 dark:text-gray-400 mb-1.5">重命名方式</div>
|
<div className="text-xs font-medium text-gray-500 dark:text-gray-400 mb-1.5">重命名方式</div>
|
||||||
<div className="grid grid-cols-3 gap-2">
|
<div className="grid grid-cols-2 gap-2">
|
||||||
{MODES.map((m) => (
|
{MODES.map((m) => (
|
||||||
<button
|
<button
|
||||||
key={m.key}
|
key={m.key}
|
||||||
@@ -196,23 +215,54 @@ function BatchRenameModal({ isOpen, folder, libraryId, onClose, onFinished }) {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* 文本输入 */}
|
{/* 文本输入 */}
|
||||||
<div className="mb-4">
|
{mode === 'keyword' ? (
|
||||||
<div className="text-xs font-medium text-gray-500 dark:text-gray-400 mb-1.5">文本内容</div>
|
<div className="mb-4">
|
||||||
<input
|
<div className="text-xs font-medium text-gray-500 dark:text-gray-400 mb-1.5">关键词</div>
|
||||||
type="text"
|
<input
|
||||||
value={text}
|
type="text"
|
||||||
onChange={(e) => setText(e.target.value)}
|
value={find}
|
||||||
placeholder={mode === 'replace' ? '例如:风景素材(全部文件改为 风景素材-001.jpg …)' : '例如:2026_'}
|
onChange={(e) => setFind(e.target.value)}
|
||||||
maxLength={100}
|
placeholder="找什么:要被替换的文件名关键词,例如:素材"
|
||||||
autoFocus
|
maxLength={100}
|
||||||
className="w-full px-3 py-2 rounded-lg border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-white text-sm focus:outline-none focus:ring-2 focus:ring-violet-500"
|
autoFocus
|
||||||
/>
|
className="w-full px-3 py-2 rounded-lg border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-white text-sm focus:outline-none focus:ring-2 focus:ring-violet-500"
|
||||||
{ILLEGAL_RE.test(text) && (
|
/>
|
||||||
<div className="text-[11px] text-red-500 mt-1">包含文件名非法字符 \ / : * ? " < > |</div>
|
{ILLEGAL_RE.test(find) && (
|
||||||
)}
|
<div className="text-[11px] text-red-500 mt-1">关键词包含文件名非法字符 \ / : * ? " < > |</div>
|
||||||
</div>
|
)}
|
||||||
|
<div className="text-xs font-medium text-gray-500 dark:text-gray-400 mb-1.5 mt-3">替换成</div>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={text}
|
||||||
|
onChange={(e) => setText(e.target.value)}
|
||||||
|
placeholder="替换成:留空 = 直接删除该关键词,例如:视频"
|
||||||
|
maxLength={100}
|
||||||
|
className="w-full px-3 py-2 rounded-lg border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-white text-sm focus:outline-none focus:ring-2 focus:ring-violet-500"
|
||||||
|
/>
|
||||||
|
{ILLEGAL_RE.test(text) && (
|
||||||
|
<div className="text-[11px] text-red-500 mt-1">替换文本包含文件名非法字符 \ / : * ? " < > |</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="mb-4">
|
||||||
|
<div className="text-xs font-medium text-gray-500 dark:text-gray-400 mb-1.5">文本内容</div>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={text}
|
||||||
|
onChange={(e) => setText(e.target.value)}
|
||||||
|
placeholder={mode === 'replace' ? '例如:风景素材(全部文件改为 风景素材-001.jpg …)' : '例如:2026_'}
|
||||||
|
maxLength={100}
|
||||||
|
autoFocus
|
||||||
|
className="w-full px-3 py-2 rounded-lg border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-white text-sm focus:outline-none focus:ring-2 focus:ring-violet-500"
|
||||||
|
/>
|
||||||
|
{ILLEGAL_RE.test(text) && (
|
||||||
|
<div className="text-[11px] text-red-500 mt-1">包含文件名非法字符 \ / : * ? " < > |</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{/* 包含子目录 */}
|
{/* 包含子目录(搜索范围时全库命中,无需此开关) */}
|
||||||
|
{scope !== 'search' && (
|
||||||
<label className="flex items-center gap-2 mb-4 cursor-pointer select-none">
|
<label className="flex items-center gap-2 mb-4 cursor-pointer select-none">
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
@@ -222,17 +272,18 @@ function BatchRenameModal({ isOpen, folder, libraryId, onClose, onFinished }) {
|
|||||||
/>
|
/>
|
||||||
<span className="text-sm text-gray-700 dark:text-gray-300">包含子目录(递归处理所有层级文件)</span>
|
<span className="text-sm text-gray-700 dark:text-gray-300">包含子目录(递归处理所有层级文件)</span>
|
||||||
</label>
|
</label>
|
||||||
|
)}
|
||||||
|
|
||||||
{/* 实时预览 */}
|
{/* 实时预览 */}
|
||||||
<div className="rounded-lg border border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-900/50 p-3">
|
<div className="rounded-lg border border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-900/50 p-3">
|
||||||
<div className="text-xs font-medium text-gray-500 dark:text-gray-400 mb-2">预览</div>
|
<div className="text-xs font-medium text-gray-500 dark:text-gray-400 mb-2">预览</div>
|
||||||
{!text.trim() && (
|
{!needInput && (
|
||||||
<div className="text-[11px] text-gray-400">输入文本后显示改名效果</div>
|
<div className="text-[11px] text-gray-400">{mode === 'keyword' ? '输入关键词后显示改名效果' : '输入文本后显示改名效果'}</div>
|
||||||
)}
|
)}
|
||||||
{text.trim() && previewErr && (
|
{needInput && previewErr && (
|
||||||
<div className="text-[11px] text-red-500">{previewErr}</div>
|
<div className="text-[11px] text-red-500">{previewErr}</div>
|
||||||
)}
|
)}
|
||||||
{text.trim() && !previewErr && !preview && (
|
{needInput && !previewErr && !preview && (
|
||||||
<div className="text-[11px] text-gray-400 flex items-center gap-1.5">
|
<div className="text-[11px] text-gray-400 flex items-center gap-1.5">
|
||||||
<Loader2 className="w-3 h-3 animate-spin" /> 计算中…
|
<Loader2 className="w-3 h-3 animate-spin" /> 计算中…
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ function Header() {
|
|||||||
// 授权系统 hub:版本 / 公告 / 在线人数
|
// 授权系统 hub:版本 / 公告 / 在线人数
|
||||||
const hub = useHub();
|
const hub = useHub();
|
||||||
const announcements = hub.announcements || [];
|
const announcements = hub.announcements || [];
|
||||||
const appVersion = hub.version ? `v${String(hub.version).replace(/^v/, '')}` : 'v1.4.7';
|
const appVersion = hub.version ? `v${String(hub.version).replace(/^v/, '')}` : 'v1.4.8';
|
||||||
|
|
||||||
// 从全局 store 获取筛选状态
|
// 从全局 store 获取筛选状态
|
||||||
const selectedFormats = filters.formats || [];
|
const selectedFormats = filters.formats || [];
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import requestManager, { RequestType } from '../services/requestManager';
|
|||||||
import domCleanup from '../utils/domCleanup';
|
import domCleanup from '../utils/domCleanup';
|
||||||
import ImageWaterfall from './ImageWaterfall';
|
import ImageWaterfall from './ImageWaterfall';
|
||||||
import Dashboard from './Dashboard';
|
import Dashboard from './Dashboard';
|
||||||
|
import BatchRenameModal from './BatchRenameModal';
|
||||||
|
import { PencilLine } from 'lucide-react';
|
||||||
import { createLogger } from '../utils/logger';
|
import { createLogger } from '../utils/logger';
|
||||||
|
|
||||||
const logger = createLogger('MainContent');
|
const logger = createLogger('MainContent');
|
||||||
@@ -18,6 +20,9 @@ function MainContent() {
|
|||||||
const { searchKeywords, filters, selectedFolder, favoritesView, setImages, setOriginalImages, imageLoadingState, images, refreshTick, folders, foldersLoaded } = useImageStore();
|
const { searchKeywords, filters, selectedFolder, favoritesView, setImages, setOriginalImages, imageLoadingState, images, refreshTick, folders, foldersLoaded } = useImageStore();
|
||||||
const { scanProgress } = useScanStore();
|
const { scanProgress } = useScanStore();
|
||||||
|
|
||||||
|
// 搜索结果批量重命名弹窗
|
||||||
|
const [searchRenameOpen, setSearchRenameOpen] = useState(false);
|
||||||
|
|
||||||
// 使用 ref 跟踪最新的请求上下文
|
// 使用 ref 跟踪最新的请求上下文
|
||||||
const currentRequestContextRef = useRef(null);
|
const currentRequestContextRef = useRef(null);
|
||||||
// 文件夹切换防抖
|
// 文件夹切换防抖
|
||||||
@@ -236,7 +241,39 @@ function MainContent() {
|
|||||||
{(!selectedFolder && !searchKeywords && filters.formats.length === 0 && !favoritesView && (!foldersLoaded || folders.length > 0)) ? (
|
{(!selectedFolder && !searchKeywords && filters.formats.length === 0 && !favoritesView && (!foldersLoaded || folders.length > 0)) ? (
|
||||||
<Dashboard />
|
<Dashboard />
|
||||||
) : (
|
) : (
|
||||||
<ImageWaterfall />
|
<>
|
||||||
|
{/* 搜索结果工具条:对模糊命中的全部文件批量重命名 */}
|
||||||
|
{searchKeywords && (
|
||||||
|
<div className="px-3 sm:px-5 pt-3 flex items-center gap-2 flex-wrap">
|
||||||
|
<span className="text-xs text-gray-500 dark:text-gray-400">
|
||||||
|
搜索「{searchKeywords}」的模糊匹配结果
|
||||||
|
</span>
|
||||||
|
<button
|
||||||
|
onClick={() => setSearchRenameOpen(true)}
|
||||||
|
className="inline-flex items-center gap-1.5 text-xs px-2.5 py-1 rounded-lg bg-violet-500 text-white hover:bg-violet-600 transition-colors"
|
||||||
|
>
|
||||||
|
<PencilLine className="w-3.5 h-3.5" />
|
||||||
|
批量重命名搜索结果…
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<ImageWaterfall />
|
||||||
|
{/* 搜索结果批量重命名 */}
|
||||||
|
{searchRenameOpen && (
|
||||||
|
<BatchRenameModal
|
||||||
|
isOpen={searchRenameOpen}
|
||||||
|
folder={selectedFolder}
|
||||||
|
libraryId={currentLibraryId}
|
||||||
|
scope="search"
|
||||||
|
keywords={searchKeywords}
|
||||||
|
onClose={() => setSearchRenameOpen(false)}
|
||||||
|
onFinished={() => {
|
||||||
|
setSearchRenameOpen(false);
|
||||||
|
useImageStore.getState().bumpRefresh();
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { useState, useEffect } from 'react';
|
|||||||
import { X, ScanText, Info, Save, FlaskConical, Github, ExternalLink, Wand2 } from 'lucide-react';
|
import { X, ScanText, Info, Save, FlaskConical, Github, ExternalLink, Wand2 } from 'lucide-react';
|
||||||
import { settingsAPI } from '../api';
|
import { settingsAPI } from '../api';
|
||||||
|
|
||||||
const APP_VERSION = 'v1.4.7';
|
const APP_VERSION = 'v1.4.8';
|
||||||
const REPO_URL = 'https://gitea.88531.cn/jinghui/flypic';
|
const REPO_URL = 'https://gitea.88531.cn/jinghui/flypic';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in new issue
Block a user