diff options
author | alyssaf16 <alyssa_feinberg@brown.edu> | 2024-10-07 22:49:05 -0400 |
---|---|---|
committer | alyssaf16 <alyssa_feinberg@brown.edu> | 2024-10-07 22:49:05 -0400 |
commit | b67de10bc8b2eab16de7bb5dd4a7a8646e2a8d5f (patch) | |
tree | c405d8af41af09d146cfac4871c3a11c25410e83 /src/ClientUtils.ts | |
parent | 66950dca6e7add542aba3c6caa8115ce7f1ecd73 (diff) | |
parent | efaa2991ac2670c73a81ab07f61c1626a4300507 (diff) |
Merge branch 'alyssa-starter' of https://github.com/brown-dash/Dash-Web into alyssa-starter
Diffstat (limited to 'src/ClientUtils.ts')
-rw-r--r-- | src/ClientUtils.ts | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/ClientUtils.ts b/src/ClientUtils.ts index 972910071..e8165d5ab 100644 --- a/src/ClientUtils.ts +++ b/src/ClientUtils.ts @@ -655,6 +655,27 @@ export function dateRangeStrToDates(dateStr: string) { return { start: new Date(dateRangeParts[0]), end: new Date(dateRangeParts[1]) }; } +/** + * converts the image to base url formate + * @param imageUrl imageurl taken from the collection icon + */ +export async function imageUrlToBase64(imageUrl: string): Promise<string> { + try { + const response = await fetch(imageUrl); + const blob = await response.blob(); + + return new Promise((resolve, reject) => { + const reader = new FileReader(); + reader.readAsDataURL(blob); + reader.onloadend = () => resolve(reader.result as string); + reader.onerror = error => reject(error); + }); + } catch (error) { + console.error('Error:', error); + throw error; + } +} + function replaceCanvases(oldDiv: HTMLElement, newDiv: HTMLElement) { if (oldDiv.childNodes && newDiv) { for (let i = 0; i < oldDiv.childNodes.length; i++) { |