mirror of
https://github.com/usebruno/bruno.git
synced 2025-06-25 14:31:44 +02:00
Added the ablility to save the response in utf8 format. (#2792)
This commit is contained in:
parent
0d3e7acf9b
commit
5706c4b138
@ -1165,12 +1165,22 @@ const registerNetworkIpc = (mainWindow) => {
|
|||||||
return `response.${extension}`;
|
return `response.${extension}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
const fileName =
|
const getEncodingFormat = () => {
|
||||||
getFileNameFromContentDispositionHeader() || getFileNameFromUrlPath() || getFileNameBasedOnContentTypeHeader();
|
const contentType = getHeaderValue('content-type');
|
||||||
|
const extension = mime.extension(contentType) || 'txt';
|
||||||
|
return ['json', 'xml', 'html', 'yml', 'yaml', 'txt'].includes(extension) ? 'utf-8' : 'base64';
|
||||||
|
};
|
||||||
|
|
||||||
|
const determineFileName = () => {
|
||||||
|
return (
|
||||||
|
getFileNameFromContentDispositionHeader() || getFileNameFromUrlPath() || getFileNameBasedOnContentTypeHeader()
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const fileName = determineFileName();
|
||||||
const filePath = await chooseFileToSave(mainWindow, fileName);
|
const filePath = await chooseFileToSave(mainWindow, fileName);
|
||||||
if (filePath) {
|
if (filePath) {
|
||||||
await writeBinaryFile(filePath, Buffer.from(response.dataBuffer, 'base64'));
|
await writeBinaryFile(filePath, Buffer.from(response.dataBuffer, getEncodingFormat()));
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return Promise.reject(error);
|
return Promise.reject(error);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user