diff options
author | Richard Steinmetz <richard@steinmetz.cloud> | 2021-10-19 18:31:18 +0200 |
---|---|---|
committer | Richard Steinmetz <richard@steinmetz.cloud> | 2021-10-19 18:31:47 +0200 |
commit | 851f7653b4e6cf81cbc9e8671f7e3e2919368469 (patch) | |
tree | eb2ea1a1bc962c9d9be8be43aa610cbcb7a5aa24 /src/models | |
parent | b4e9065ca49e67dc39f5661f9a0a8c0e61e3a9ae (diff) |
Fix contact avatars not loading
Signed-off-by: Richard Steinmetz <richard@steinmetz.cloud>
Diffstat (limited to 'src/models')
-rw-r--r-- | src/models/contact.js | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/models/contact.js b/src/models/contact.js index b87e295d..1f33343a 100644 --- a/src/models/contact.js +++ b/src/models/contact.js @@ -239,20 +239,21 @@ export default class Contact { } const encoding = photo.getFirstParameter('encoding') let photoType = photo.getFirstParameter('type') - let photoB64 = this.photo + const photoB64 = this.photo const isBinary = photo.type === 'binary' || encoding === 'b' + let photoB64Data = photoB64 if (photo && photoB64.startsWith('data') && !isBinary) { // get the last part = base64 - photoB64 = photoB64.split(',').pop() - // 'data:image/png' => 'png' - photoType = photoB64.split(';')[0].split('/') + photoB64Data = photoB64.split(',').pop() + // 'data:image/png;base64' => 'png' + photoType = photoB64.split(';')[0].split('/').pop() } // Verify if SVG is valid if (photoType.startsWith('svg')) { - const imageSvg = atob(photoB64) + const imageSvg = atob(photoB64Data) const cleanSvg = await sanitizeSVG(imageSvg) if (!cleanSvg) { @@ -263,7 +264,7 @@ export default class Contact { try { // Create blob from url - const blob = b64toBlob(photoB64, `image/${photoType}`) + const blob = b64toBlob(photoB64Data, `image/${photoType}`) return URL.createObjectURL(blob) } catch { console.error('Invalid photo for the following contact. Ignoring...', this.contact, { photoB64, photoType }) |