Skip to content

Commit 1372819

Browse files
committed
fix fb avatar expired
1 parent 745856c commit 1372819

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

scripts/ufs_statistic.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,26 @@ async function onDocumentEnd() {
533533
.querySelectorAll(`[data-profile-avatar="${uid}"]`)
534534
.forEach((el) => {
535535
el.src = info.avatar.replace(/\\\//g, "/") || el.src;
536+
537+
let tried = 0,
538+
loading = false;
539+
540+
// in case cached avatqr expired
541+
el.onerror = () => {
542+
if (loading) return;
543+
tried++;
544+
if (tried > 3) el.src = getUserAvatarFromUid(uid);
545+
else {
546+
loading = true;
547+
getFbProfile(uid, true)
548+
.then((info) => {
549+
el.src = info.avatar.replace(/\\\//g, "/") || el.src;
550+
})
551+
.finally(() => {
552+
loading = false;
553+
});
554+
}
555+
};
536556
});
537557
})
538558
);
@@ -654,8 +674,8 @@ async function initCache() {
654674
}
655675
}
656676

657-
async function getFbProfile(uid) {
658-
if (CACHED.fbProfile.has(uid)) return CACHED.fbProfile.get(uid);
677+
async function getFbProfile(uid, force = false) {
678+
if (CACHED.fbProfile.has(uid) && !force) return CACHED.fbProfile.get(uid);
659679

660680
const variables = {
661681
userID: uid,

0 commit comments

Comments
 (0)