From 0f9e8b3d06b63e974eefb96640616b6308fc9fcd Mon Sep 17 00:00:00 2001 From: rofe Date: Mon, 21 Nov 2022 14:59:18 +0100 Subject: [PATCH 1/3] fix: sharepoint avatar cannot be loaded --- src/extension/module.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/extension/module.js b/src/extension/module.js index c88555a75..3df6e11ac 100644 --- a/src/extension/module.js +++ b/src/extension/module.js @@ -1460,9 +1460,21 @@ function checkUserState(sk) { const toggle = sk.get('user').firstElementChild; toggle.removeAttribute('disabled'); - const updateUserPicture = (picture) => { + const updateUserPicture = async (picture) => { toggle.querySelectorAll('.user-picture').forEach((img) => img.remove()); if (picture) { + if (picture.startsWith('https://admin.hlx.page/')) { + // fetch the image with auth token + picture = await new Promise((resolve) => { + fetch(picture, { + headers: { + 'x-auth-token': sk.config.authToken, + }, + }) + .then((resp) => resp.blob()) + .then((blob) => resolve(URL.createObjectURL(blob))); + }); + } toggle.querySelector('.user-icon').classList.add('user-icon-hidden'); appendTag(toggle, { tag: 'img', From f4ecd3548624dbb713c90a0958322ad495bf0488 Mon Sep 17 00:00:00 2001 From: Raphael Wegmueller Date: Mon, 21 Nov 2022 16:21:54 +0100 Subject: [PATCH 2/3] Update src/extension/module.js Co-authored-by: Tobias Bocanegra --- src/extension/module.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/extension/module.js b/src/extension/module.js index 3df6e11ac..ab0ab0894 100644 --- a/src/extension/module.js +++ b/src/extension/module.js @@ -1465,15 +1465,12 @@ if (picture) { if (picture.startsWith('https://admin.hlx.page/')) { // fetch the image with auth token - picture = await new Promise((resolve) => { - fetch(picture, { + const resp = await fetch(picture, { headers: { 'x-auth-token': sk.config.authToken, }, - }) - .then((resp) => resp.blob()) - .then((blob) => resolve(URL.createObjectURL(blob))); - }); + }); + picture = URL.createObjectURL(await resp.blob()); } toggle.querySelector('.user-icon').classList.add('user-icon-hidden'); appendTag(toggle, { From 8eb7b89f575f49a60c4a2352578d1825594ed02d Mon Sep 17 00:00:00 2001 From: rofe Date: Mon, 21 Nov 2022 16:22:36 +0100 Subject: [PATCH 3/3] chore: linting --- src/extension/module.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/extension/module.js b/src/extension/module.js index ab0ab0894..bfd5b80f5 100644 --- a/src/extension/module.js +++ b/src/extension/module.js @@ -1466,11 +1466,11 @@ if (picture.startsWith('https://admin.hlx.page/')) { // fetch the image with auth token const resp = await fetch(picture, { - headers: { - 'x-auth-token': sk.config.authToken, - }, - }); - picture = URL.createObjectURL(await resp.blob()); + headers: { + 'x-auth-token': sk.config.authToken, + }, + }); + picture = URL.createObjectURL(await resp.blob()); } toggle.querySelector('.user-icon').classList.add('user-icon-hidden'); appendTag(toggle, {