feat: Moved logic related to html report generation to bruno-common package (#4536)

---------
Co-authored-by: lohit jiddimani <lohitjiddimani@lohits-MacBook-Air.local>
This commit is contained in:
lohit
2025-04-22 16:35:54 +05:30
committed by GitHub
parent e3c28fd0ec
commit 220da6b58e
14 changed files with 1040 additions and 238 deletions

View File

@@ -0,0 +1,31 @@
export const encodeBase64 = (str: string) => {
const bytes = new TextEncoder().encode(str);
const binary = bytes.reduce((acc, byte) => acc + String.fromCharCode(byte), '');
return btoa(binary);
}
export const decodeBase64 = (base64: string) => {
const binary = atob(base64);
const bytes = Uint8Array.from(binary, c => c.charCodeAt(0));
return new TextDecoder().decode(bytes);
}
export const getContentType = (headers: Record<string, string | number | undefined>): string => {
if (!headers || typeof headers !== 'object') {
return '';
}
const contentType = Object.entries(headers)
.find(([key]) => key.toLowerCase() === 'content-type')?.[1];
return typeof contentType === 'string' ? contentType : '';
};
export const isHtmlContentType = (contentType: string) => {
return contentType?.includes("html");
};
export const redactImageData = (data: string | object | number | boolean, contentType: string) => {
if (contentType?.includes("image")) {
return "Response content redacted (image data)";
}
return data;
}