1
0
mirror of https://github.com/flarum/core.git synced 2025-08-03 23:17:43 +02:00

Catch errors when uploading white avatar (#3119)

This commit is contained in:
Alexander Skvortsov
2021-10-25 17:34:39 -04:00
committed by GitHub
parent 5a1bf08d3f
commit a661376d16

View File

@@ -89,8 +89,18 @@ Object.assign(User.prototype, {
const user = this; const user = this;
image.onload = function () { image.onload = function () {
const colorThief = new ColorThief(); try {
user.avatarColor = colorThief.getColor(this); const colorThief = new ColorThief();
user.avatarColor = colorThief.getColor(this);
} catch (e) {
// Completely white avatars throw errors due to a glitch in color thief
// See https://github.com/lokesh/color-thief/issues/40
if (e instanceof TypeError) {
user.avatarColor = [255, 255, 255];
} else {
throw e;
}
}
user.freshness = new Date(); user.freshness = new Date();
m.redraw(); m.redraw();
}; };