mirror of
https://github.com/flarum/framework.git
synced 2025-02-01 14:20:44 +08:00
Catch errors when uploading white avatar (#3119)
This commit is contained in:
parent
f508c829db
commit
9117aac0bd
|
@ -89,8 +89,18 @@ Object.assign(User.prototype, {
|
|||
const user = this;
|
||||
|
||||
image.onload = function () {
|
||||
const colorThief = new ColorThief();
|
||||
user.avatarColor = colorThief.getColor(this);
|
||||
try {
|
||||
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();
|
||||
m.redraw();
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user