fix(paste): deduplicate filenames when pasting multiple images#1931
fix(paste): deduplicate filenames when pasting multiple images#1931kaizhou-lab merged 1 commit intomainfrom
Conversation
…aneously When multiple clipboard images are pasted at the same time, they generate identical filenames (second-precision timestamp). The backend collision handler appends _aionui_<ts> suffixes, but buildDisplayMessage strips these suffixes, causing all files to map to the same display path. Add a usedFileNames Set in the paste loop to detect and resolve filename collisions at the source by appending _2, _3, etc. suffixes. Closes #1177
Code Review:fix(paste): deduplicate filenames when pasting multiple images (#1931)变更概述本 PR 修复了在同一秒内粘贴多张截图时,因生成相同的时间戳文件名( 方案评估结论:✅ 方案合理 在粘贴循环中引入 问题清单🔵 LOW — 去重辅助逻辑重复文件: 问题说明:图片分支和非图片文件分支各自包含一份相同的去重逻辑。若后续需修改命名策略(如改用 修复建议(可选,不阻塞合并):提取为内联辅助函数: function deduplicateFileName(name: string, used: Set<string>, fallbackExt: string): string {
if (!used.has(name)) return name;
const extIdx = name.lastIndexOf('.');
const base = extIdx > 0 ? name.slice(0, extIdx) : name;
const ext = extIdx > 0 ? name.slice(extIdx) : fallbackExt;
let counter = 2;
while (used.has(`${base}_${counter}${ext}`)) counter++;
return `${base}_${counter}${ext}`;
}🔵 LOW — 测试未覆盖非图片文件分支去重文件: 问题说明:三个测试用例均使用 汇总
结论✅ 批准合并 — 仅有两处 LOW 级问题,均不阻塞合并。核心逻辑正确,测试覆盖主路径,方案简洁合理。 本报告由本地 CONCLUSION: APPROVED |
|
✅ 已自动 review,无阻塞性问题,正在触发自动合并。 |
|
|
Summary
HHmmss). The backend collision handler (fsBridge.createTempFile) appends_aionui_<timestamp>suffixes, butbuildDisplayMessagestrips these suffixes viaAIONUI_TIMESTAMP_REGEX, causing all files to map to the same display path — so only one image appears in conversation details.usedFileNamesSet in the paste loop to detect and resolve filename collisions at the source by appending_2,_3, etc. suffixes before callingcreateTempFile.Related Issues
Closes #1177
Test Plan
PasteService.dom.test.ts) covering 2-image and 3-image simultaneous paste