파일 삭제 기능 추가, undo / redo 기능에 적용
This commit is contained in:
+54
-1
@@ -1,4 +1,4 @@
|
||||
const { ipcMain } = require('electron');
|
||||
const { ipcMain, app } = require('electron');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const crypto = require('crypto');
|
||||
@@ -73,6 +73,59 @@ function register() {
|
||||
return { moved, errors };
|
||||
});
|
||||
|
||||
// 삭제 → 스테이징 폴더로 이동 (undo 가능)
|
||||
ipcMain.handle('stage-delete-files', async (_event, filePaths) => {
|
||||
const batchDir = path.join(app.getPath('userData'), 'deleted_staging', Date.now().toString());
|
||||
fs.mkdirSync(batchDir, { recursive: true });
|
||||
|
||||
const staged = [];
|
||||
const errors = [];
|
||||
for (const fp of filePaths) {
|
||||
const name = path.basename(fp);
|
||||
const dest = path.join(batchDir, name);
|
||||
try {
|
||||
fs.renameSync(fp, dest);
|
||||
staged.push({ name, originalPath: fp, stagingPath: dest });
|
||||
} catch (e) {
|
||||
if (e.code === 'EXDEV') {
|
||||
try {
|
||||
fs.copyFileSync(fp, dest);
|
||||
fs.unlinkSync(fp);
|
||||
staged.push({ name, originalPath: fp, stagingPath: dest });
|
||||
} catch (e2) { errors.push(`${name}: ${e2.message}`); }
|
||||
} else { errors.push(`${name}: ${e.message}`); }
|
||||
}
|
||||
}
|
||||
if (!staged.length) try { fs.rmdirSync(batchDir); } catch {}
|
||||
return { staged, errors };
|
||||
});
|
||||
|
||||
// 스테이징 파일 원래 위치로 복원 (undo delete)
|
||||
ipcMain.handle('restore-staged-files', async (_event, deletedEntries) => {
|
||||
const restored = [];
|
||||
const errors = [];
|
||||
for (const { name, originalPath, stagingPath } of deletedEntries) {
|
||||
if (fs.existsSync(originalPath)) {
|
||||
errors.push(`${name}: 같은 이름의 파일이 이미 존재합니다`);
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
fs.mkdirSync(path.dirname(originalPath), { recursive: true });
|
||||
fs.renameSync(stagingPath, originalPath);
|
||||
restored.push(originalPath);
|
||||
} catch (e) {
|
||||
if (e.code === 'EXDEV') {
|
||||
try {
|
||||
fs.copyFileSync(stagingPath, originalPath);
|
||||
fs.unlinkSync(stagingPath);
|
||||
restored.push(originalPath);
|
||||
} catch (e2) { errors.push(`${name}: ${e2.message}`); }
|
||||
} else { errors.push(`${name}: ${e.message}`); }
|
||||
}
|
||||
}
|
||||
return { restored, errors };
|
||||
});
|
||||
|
||||
ipcMain.handle('rename-files', async (_event, { folderPath, files, prefix, digits }) => {
|
||||
const errors = [];
|
||||
const pad = (n) => String(n + 1).padStart(digits, '0');
|
||||
|
||||
Reference in New Issue
Block a user