fix failure to upload large avatar
This commit is contained in:
+1
-1
@@ -810,7 +810,7 @@ i.search {
|
|||||||
position: relative;
|
position: relative;
|
||||||
display: none;
|
display: none;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
padding: 1rem 1.5rem 1rem 0.5rem;
|
padding: 1rem 1.5rem 0.75rem 0.5rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.info-box > span {
|
.info-box > span {
|
||||||
|
|||||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -90,7 +90,7 @@ export function imageScaled(fileOrBlob, maxWidth, maxHeight, maxSize, forceSquar
|
|||||||
URL.revokeObjectURL(img.src);
|
URL.revokeObjectURL(img.src);
|
||||||
|
|
||||||
// Calculate the desired image dimensions.
|
// Calculate the desired image dimensions.
|
||||||
const dim = fitImageSize(this.width, this.height, maxWidth, maxHeight, forceSquare);
|
const dim = fitImageSize(img.width, img.height, maxWidth, maxHeight, forceSquare);
|
||||||
if (!dim) {
|
if (!dim) {
|
||||||
reject(new Error("Invalid image"));
|
reject(new Error("Invalid image"));
|
||||||
return;
|
return;
|
||||||
@@ -100,7 +100,7 @@ export function imageScaled(fileOrBlob, maxWidth, maxHeight, maxSize, forceSquar
|
|||||||
canvas.height = dim.dstHeight;
|
canvas.height = dim.dstHeight;
|
||||||
let ctx = canvas.getContext('2d');
|
let ctx = canvas.getContext('2d');
|
||||||
ctx.imageSmoothingEnabled = true;
|
ctx.imageSmoothingEnabled = true;
|
||||||
ctx.drawImage(this, dim.xoffset, dim.yoffset, dim.srcWidth, dim.srcHeight,
|
ctx.drawImage(img, dim.xoffset, dim.yoffset, dim.srcWidth, dim.srcHeight,
|
||||||
0, 0, dim.dstWidth, dim.dstHeight);
|
0, 0, dim.dstWidth, dim.dstHeight);
|
||||||
|
|
||||||
const mime = SUPPORTED_IMAGE_FORMATS.includes(fileOrBlob.type) ? fileOrBlob.type : 'image/jpeg';
|
const mime = SUPPORTED_IMAGE_FORMATS.includes(fileOrBlob.type) ? fileOrBlob.type : 'image/jpeg';
|
||||||
@@ -110,7 +110,6 @@ export function imageScaled(fileOrBlob, maxWidth, maxHeight, maxSize, forceSquar
|
|||||||
reject(new Error("Unsupported image format"));
|
reject(new Error("Unsupported image format"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure the image is not too large. Shrink the image keeping the aspect ratio.
|
// Ensure the image is not too large. Shrink the image keeping the aspect ratio.
|
||||||
// Do nothing if maxsize is <= 0.
|
// Do nothing if maxsize is <= 0.
|
||||||
while (maxSize > 0 && blob.length > maxSize) {
|
while (maxSize > 0 && blob.length > maxSize) {
|
||||||
@@ -120,7 +119,7 @@ export function imageScaled(fileOrBlob, maxWidth, maxHeight, maxSize, forceSquar
|
|||||||
canvas.height = dim.dstHeight;
|
canvas.height = dim.dstHeight;
|
||||||
ctx = canvas.getContext('2d');
|
ctx = canvas.getContext('2d');
|
||||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||||
ctx.drawImage(this, dim.xoffset, dim.yoffset, dim.srcWidth, dim.srcHeight,
|
ctx.drawImage(img, dim.xoffset, dim.yoffset, dim.srcWidth, dim.srcHeight,
|
||||||
0, 0, dim.dstWidth, dim.dstHeight);
|
0, 0, dim.dstWidth, dim.dstHeight);
|
||||||
blob = await new Promise(resolve => canvas.toBlob(resolve, mime));
|
blob = await new Promise(resolve => canvas.toBlob(resolve, mime));
|
||||||
}
|
}
|
||||||
@@ -151,7 +150,7 @@ export function imageCrop(mime, objURL, left, top, width, height, scale) {
|
|||||||
canvas.height = height * scale;
|
canvas.height = height * scale;
|
||||||
let ctx = canvas.getContext('2d');
|
let ctx = canvas.getContext('2d');
|
||||||
ctx.imageSmoothingEnabled = true;
|
ctx.imageSmoothingEnabled = true;
|
||||||
ctx.drawImage(this, left, top, width, height, 0, 0, canvas.width, canvas.height);
|
ctx.drawImage(img, left, top, width, height, 0, 0, canvas.width, canvas.height);
|
||||||
|
|
||||||
mime = SUPPORTED_IMAGE_FORMATS.includes(mime) ? mime : 'image/jpeg';
|
mime = SUPPORTED_IMAGE_FORMATS.includes(mime) ? mime : 'image/jpeg';
|
||||||
// Generate blob to check size of the image.
|
// Generate blob to check size of the image.
|
||||||
|
|||||||
@@ -141,10 +141,8 @@ export default class TopicDescEdit extends React.Component {
|
|||||||
if (width > AVATAR_SIZE || height > AVATAR_SIZE || width != height) {
|
if (width > AVATAR_SIZE || height > AVATAR_SIZE || width != height) {
|
||||||
// Avatar is not square or too large even after cropping. Shrink it and make square.
|
// Avatar is not square or too large even after cropping. Shrink it and make square.
|
||||||
imageScaled(blob, AVATAR_SIZE, AVATAR_SIZE, MAX_EXTERN_ATTACHMENT_SIZE, true)
|
imageScaled(blob, AVATAR_SIZE, AVATAR_SIZE, MAX_EXTERN_ATTACHMENT_SIZE, true)
|
||||||
.then(scaled => readyToUpload)
|
.then(scaled => readyToUpload(scaled))
|
||||||
.catch(err => {
|
.catch(err => this.props.onError(err, 'err'));
|
||||||
this.props.onError(err, 'err');
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
readyToUpload({mime: mime, blob: blob, width: width, height: height});
|
readyToUpload({mime: mime, blob: blob, width: width, height: height});
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-7
@@ -191,7 +191,7 @@ function imageScaled(fileOrBlob, maxWidth, maxHeight, maxSize, forceSquare) {
|
|||||||
|
|
||||||
img.onload = async function () {
|
img.onload = async function () {
|
||||||
URL.revokeObjectURL(img.src);
|
URL.revokeObjectURL(img.src);
|
||||||
const dim = fitImageSize(this.width, this.height, maxWidth, maxHeight, forceSquare);
|
const dim = fitImageSize(img.width, img.height, maxWidth, maxHeight, forceSquare);
|
||||||
|
|
||||||
if (!dim) {
|
if (!dim) {
|
||||||
reject(new Error("Invalid image"));
|
reject(new Error("Invalid image"));
|
||||||
@@ -203,7 +203,7 @@ function imageScaled(fileOrBlob, maxWidth, maxHeight, maxSize, forceSquare) {
|
|||||||
canvas.height = dim.dstHeight;
|
canvas.height = dim.dstHeight;
|
||||||
let ctx = canvas.getContext('2d');
|
let ctx = canvas.getContext('2d');
|
||||||
ctx.imageSmoothingEnabled = true;
|
ctx.imageSmoothingEnabled = true;
|
||||||
ctx.drawImage(this, dim.xoffset, dim.yoffset, dim.srcWidth, dim.srcHeight, 0, 0, dim.dstWidth, dim.dstHeight);
|
ctx.drawImage(img, dim.xoffset, dim.yoffset, dim.srcWidth, dim.srcHeight, 0, 0, dim.dstWidth, dim.dstHeight);
|
||||||
const mime = SUPPORTED_IMAGE_FORMATS.includes(fileOrBlob.type) ? fileOrBlob.type : 'image/jpeg';
|
const mime = SUPPORTED_IMAGE_FORMATS.includes(fileOrBlob.type) ? fileOrBlob.type : 'image/jpeg';
|
||||||
let blob = await new Promise(resolve => canvas.toBlob(resolve, mime));
|
let blob = await new Promise(resolve => canvas.toBlob(resolve, mime));
|
||||||
|
|
||||||
@@ -219,7 +219,7 @@ function imageScaled(fileOrBlob, maxWidth, maxHeight, maxSize, forceSquare) {
|
|||||||
canvas.height = dim.dstHeight;
|
canvas.height = dim.dstHeight;
|
||||||
ctx = canvas.getContext('2d');
|
ctx = canvas.getContext('2d');
|
||||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||||
ctx.drawImage(this, dim.xoffset, dim.yoffset, dim.srcWidth, dim.srcHeight, 0, 0, dim.dstWidth, dim.dstHeight);
|
ctx.drawImage(img, dim.xoffset, dim.yoffset, dim.srcWidth, dim.srcHeight, 0, 0, dim.dstWidth, dim.dstHeight);
|
||||||
blob = await new Promise(resolve => canvas.toBlob(resolve, mime));
|
blob = await new Promise(resolve => canvas.toBlob(resolve, mime));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -252,7 +252,7 @@ function imageCrop(mime, objURL, left, top, width, height, scale) {
|
|||||||
canvas.height = height * scale;
|
canvas.height = height * scale;
|
||||||
let ctx = canvas.getContext('2d');
|
let ctx = canvas.getContext('2d');
|
||||||
ctx.imageSmoothingEnabled = true;
|
ctx.imageSmoothingEnabled = true;
|
||||||
ctx.drawImage(this, left, top, width, height, 0, 0, canvas.width, canvas.height);
|
ctx.drawImage(img, left, top, width, height, 0, 0, canvas.width, canvas.height);
|
||||||
mime = SUPPORTED_IMAGE_FORMATS.includes(mime) ? mime : 'image/jpeg';
|
mime = SUPPORTED_IMAGE_FORMATS.includes(mime) ? mime : 'image/jpeg';
|
||||||
canvas.toBlob(blob => {
|
canvas.toBlob(blob => {
|
||||||
canvas = null;
|
canvas = null;
|
||||||
@@ -12652,9 +12652,7 @@ class TopicDescEdit extends (react__WEBPACK_IMPORTED_MODULE_0___default().Compon
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (width > _config_js__WEBPACK_IMPORTED_MODULE_7__.AVATAR_SIZE || height > _config_js__WEBPACK_IMPORTED_MODULE_7__.AVATAR_SIZE || width != height) {
|
if (width > _config_js__WEBPACK_IMPORTED_MODULE_7__.AVATAR_SIZE || height > _config_js__WEBPACK_IMPORTED_MODULE_7__.AVATAR_SIZE || width != height) {
|
||||||
(0,_lib_blob_helpers_js__WEBPACK_IMPORTED_MODULE_8__.imageScaled)(blob, _config_js__WEBPACK_IMPORTED_MODULE_7__.AVATAR_SIZE, _config_js__WEBPACK_IMPORTED_MODULE_7__.AVATAR_SIZE, _config_js__WEBPACK_IMPORTED_MODULE_7__.MAX_EXTERN_ATTACHMENT_SIZE, true).then(scaled => readyToUpload).catch(err => {
|
(0,_lib_blob_helpers_js__WEBPACK_IMPORTED_MODULE_8__.imageScaled)(blob, _config_js__WEBPACK_IMPORTED_MODULE_7__.AVATAR_SIZE, _config_js__WEBPACK_IMPORTED_MODULE_7__.AVATAR_SIZE, _config_js__WEBPACK_IMPORTED_MODULE_7__.MAX_EXTERN_ATTACHMENT_SIZE, true).then(scaled => readyToUpload(scaled)).catch(err => this.props.onError(err, 'err'));
|
||||||
this.props.onError(err, 'err');
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
readyToUpload({
|
readyToUpload({
|
||||||
mime: mime,
|
mime: mime,
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
+1
-1
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user