mirror of
https://github.com/usebruno/bruno.git
synced 2024-11-21 23:43:15 +01: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}`;
|
||||
};
|
||||
|
||||
const fileName =
|
||||
getFileNameFromContentDispositionHeader() || getFileNameFromUrlPath() || getFileNameBasedOnContentTypeHeader();
|
||||
const getEncodingFormat = () => {
|
||||
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);
|
||||
if (filePath) {
|
||||
await writeBinaryFile(filePath, Buffer.from(response.dataBuffer, 'base64'));
|
||||
await writeBinaryFile(filePath, Buffer.from(response.dataBuffer, getEncodingFormat()));
|
||||
}
|
||||
} catch (error) {
|
||||
return Promise.reject(error);
|
||||
|
Loading…
Reference in New Issue
Block a user