mirror of
https://github.com/usebruno/bruno.git
synced 2026-07-08 06:28:33 +00:00
persist request/folder uids after request/folder resequencing and ui updates (#4611)
* move file/folder uids to new paths * drag file/folder preview ui updates, can item be dropped ui hint check --------- Co-authored-by: lohit <lohit@usebruno.com>
This commit is contained in:
@@ -341,7 +341,8 @@ const addDirectory = async (win, pathname, collectionUid, collectionPath) => {
|
||||
collectionUid,
|
||||
pathname,
|
||||
name,
|
||||
seq
|
||||
seq,
|
||||
uid: getRequestUid(pathname)
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -25,7 +25,8 @@ const {
|
||||
sizeInMB,
|
||||
safeWriteFileSync,
|
||||
copyPath,
|
||||
removePath
|
||||
removePath,
|
||||
getPaths
|
||||
} = require('../utils/filesystem');
|
||||
const { openCollectionDialog } = require('../app/collections');
|
||||
const { generateUidBasedOnHash, stringifyJson, safeParseJSON, safeStringifyJSON } = require('../utils/common');
|
||||
@@ -799,8 +800,15 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
|
||||
ipcMain.handle('renderer:move-item', async (event, { targetDirname, sourcePathname }) => {
|
||||
try {
|
||||
if (fs.existsSync(targetDirname)) {
|
||||
const sourceDirname = path.dirname(sourcePathname);
|
||||
const pathnamesBefore = await getPaths(sourcePathname);
|
||||
const pathnamesAfter = pathnamesBefore?.map(p => p?.replace(sourceDirname, targetDirname));
|
||||
await copyPath(sourcePathname, targetDirname);
|
||||
await removePath(sourcePathname);
|
||||
// move the request uids of the previous file/folders to the new file/folder items
|
||||
pathnamesAfter?.forEach((_, index) => {
|
||||
moveRequestUid(pathnamesBefore[index], pathnamesAfter[index]);
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
return Promise.reject(error);
|
||||
|
||||
@@ -324,6 +324,25 @@ const removePath = async (source) => {
|
||||
}
|
||||
}
|
||||
|
||||
// Recursively gets paths.
|
||||
const getPaths = async (source) => {
|
||||
let paths = [];
|
||||
const _getPaths = async (source) => {
|
||||
const stat = await fsPromises.lstat(source);
|
||||
paths.push(source);
|
||||
if (stat.isDirectory()) {
|
||||
const entries = await fsPromises.readdir(source);
|
||||
for (const entry of entries) {
|
||||
const entryPath = path.join(source, entry);
|
||||
await _getPaths(entryPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
await _getPaths(source);
|
||||
return paths;
|
||||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
isValidPathname,
|
||||
exists,
|
||||
@@ -352,5 +371,6 @@ module.exports = {
|
||||
safeWriteFile,
|
||||
safeWriteFileSync,
|
||||
copyPath,
|
||||
removePath
|
||||
removePath,
|
||||
getPaths
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user