mirror of
https://github.com/flarum/framework.git
synced 2025-02-01 19:52:02 +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;
|
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();
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user