mirror of
https://github.com/usebruno/bruno.git
synced 2026-07-07 22:18:33 +00:00
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:
31
packages/bruno-common/src/runner/utils/index.ts
Normal file
31
packages/bruno-common/src/runner/utils/index.ts
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user