mirror of
https://github.com/usebruno/bruno.git
synced 2026-07-01 08:34:07 +00:00
fix: resolve Load Request button error when loading large collection … (#6809)
* fix: resolve Load Request button error when loading large collection requests * scope down to .bru requests
This commit is contained in:
committed by
GitHub
parent
707ed63be6
commit
8b1b18cc39
@@ -583,7 +583,7 @@ const change = async (win, pathname, collectionUid, collectionPath) => {
|
||||
const fileStats = fs.statSync(pathname);
|
||||
|
||||
if (fileStats.size >= MAX_FILE_SIZE && format === 'bru') {
|
||||
file.data = await parseLargeRequestWithRedaction(content);
|
||||
file.data = await parseLargeRequestWithRedaction(content, 'bru');
|
||||
} else {
|
||||
file.data = await parseRequest(content, { format });
|
||||
}
|
||||
|
||||
@@ -382,14 +382,14 @@ const registerRendererEventHandlers = (mainWindow, watcher) => {
|
||||
});
|
||||
|
||||
// Helper: Parse file content based on scope type
|
||||
const parseFileByType = async (fileContent, scopeType) => {
|
||||
const parseFileByType = async (fileContent, scopeType, format) => {
|
||||
switch (scopeType) {
|
||||
case 'request':
|
||||
return await parseRequestViaWorker(fileContent);
|
||||
return await parseRequestViaWorker(fileContent, { format });
|
||||
case 'folder':
|
||||
return parseFolder(fileContent);
|
||||
return parseFolder(fileContent, { format });
|
||||
case 'collection':
|
||||
return parseCollection(fileContent);
|
||||
return parseCollection(fileContent, { format });
|
||||
default:
|
||||
throw new Error(`Invalid scope type: ${scopeType}`);
|
||||
}
|
||||
@@ -430,7 +430,7 @@ const registerRendererEventHandlers = (mainWindow, watcher) => {
|
||||
|
||||
// Read and parse the file
|
||||
const fileContent = fs.readFileSync(pathname, 'utf8');
|
||||
const parsedData = await parseFileByType(fileContent, scopeType);
|
||||
const parsedData = await parseFileByType(fileContent, scopeType, format);
|
||||
|
||||
// Update the specific variable or create it if it doesn't exist
|
||||
const varsPath = 'request.vars.req';
|
||||
@@ -1429,7 +1429,7 @@ const registerRendererEventHandlers = (mainWindow, watcher) => {
|
||||
file.size = sizeInMB(fileStats?.size);
|
||||
hydrateRequestWithUuid(file.data, pathname);
|
||||
mainWindow.webContents.send('main:collection-tree-updated', 'addFile', file);
|
||||
file.data = await parseRequestViaWorker(bruContent);
|
||||
file.data = await parseRequestViaWorker(bruContent, { format: 'bru' });
|
||||
file.partial = false;
|
||||
file.loading = true;
|
||||
file.size = sizeInMB(fileStats?.size);
|
||||
@@ -1536,7 +1536,7 @@ const registerRendererEventHandlers = (mainWindow, watcher) => {
|
||||
await mainWindow.webContents.send('main:collection-tree-updated', 'addFile', file);
|
||||
|
||||
try {
|
||||
const parsedData = await parseLargeRequestWithRedaction(bruContent);
|
||||
const parsedData = await parseLargeRequestWithRedaction(bruContent, 'bru');
|
||||
|
||||
file.data = parsedData;
|
||||
file.loading = false;
|
||||
|
||||
@@ -4,11 +4,12 @@ const { parseRequestAndRedactBody, parseRequestViaWorker } = require('@usebruno/
|
||||
* Parses a large BRU request string by redacting body blocks, parsing the remainder,
|
||||
* and then reinserting extracted body content into the parsed structure.
|
||||
* @param {string} bruContent
|
||||
* @param {string} format - Collection format, defaults to 'bru'
|
||||
* @returns {Promise<any>} parsed request JSON
|
||||
*/
|
||||
async function parseLargeRequestWithRedaction(bruContent) {
|
||||
const { bruFileStringWithRedactedBody, extractedBodyContent } = parseRequestAndRedactBody(bruContent);
|
||||
const parsedData = await parseRequestViaWorker(bruFileStringWithRedactedBody);
|
||||
async function parseLargeRequestWithRedaction(bruContent, format = 'bru') {
|
||||
const { bruFileStringWithRedactedBody, extractedBodyContent } = parseRequestAndRedactBody(bruContent, { format });
|
||||
const parsedData = await parseRequestViaWorker(bruFileStringWithRedactedBody, { format });
|
||||
|
||||
if (!parsedData.request) {
|
||||
parsedData.request = {};
|
||||
|
||||
Reference in New Issue
Block a user