mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-03-03 19:11:22 +01:00
fix: closes #7221 restrict cropperjs box to profileImageDimension form ACP
this also resizes the image down to that value and sends a small image to server move profileImageDimenstion & maximumProfileImageSize from edit to all profile pages, on harmony profile pic can be changed from any page by clicking the avatar change image.resize so it doesn't resize if image is already same width/height
This commit is contained in:
@@ -40,7 +40,7 @@
|
|||||||
"default-avatar": "Custom Default Avatar",
|
"default-avatar": "Custom Default Avatar",
|
||||||
"upload": "Upload",
|
"upload": "Upload",
|
||||||
"profile-image-dimension": "Profile Image Dimension",
|
"profile-image-dimension": "Profile Image Dimension",
|
||||||
"profile-image-dimension-help": "(in pixels, default: 128 pixels)",
|
"profile-image-dimension-help": "(in pixels, default: 200 pixels)",
|
||||||
"max-profile-image-size": "Maximum Profile Image File Size",
|
"max-profile-image-size": "Maximum Profile Image File Size",
|
||||||
"max-profile-image-size-help": "(in kibibytes, default: 256 KiB)",
|
"max-profile-image-size-help": "(in kibibytes, default: 256 KiB)",
|
||||||
"max-cover-image-size": "Maximum Cover Image File Size",
|
"max-cover-image-size": "Maximum Cover Image File Size",
|
||||||
|
|||||||
@@ -450,6 +450,10 @@ UserObjectFull:
|
|||||||
type: boolean
|
type: boolean
|
||||||
allowProfileImageUploads:
|
allowProfileImageUploads:
|
||||||
type: number
|
type: number
|
||||||
|
maximumProfileImageSize:
|
||||||
|
type: number
|
||||||
|
profileImageDimension:
|
||||||
|
type: number
|
||||||
allowedProfileImageExtensions:
|
allowedProfileImageExtensions:
|
||||||
type: string
|
type: string
|
||||||
groups:
|
groups:
|
||||||
|
|||||||
@@ -23,8 +23,6 @@ get:
|
|||||||
type: number
|
type: number
|
||||||
maximumAboutMeLength:
|
maximumAboutMeLength:
|
||||||
type: number
|
type: number
|
||||||
maximumProfileImageSize:
|
|
||||||
type: number
|
|
||||||
allowProfilePicture:
|
allowProfilePicture:
|
||||||
type: boolean
|
type: boolean
|
||||||
allowCoverPicture:
|
allowCoverPicture:
|
||||||
@@ -41,8 +39,6 @@ get:
|
|||||||
type: boolean
|
type: boolean
|
||||||
allowSignature:
|
allowSignature:
|
||||||
type: boolean
|
type: boolean
|
||||||
profileImageDimension:
|
|
||||||
type: number
|
|
||||||
defaultAvatar:
|
defaultAvatar:
|
||||||
type: string
|
type: string
|
||||||
sso:
|
sso:
|
||||||
|
|||||||
@@ -169,15 +169,16 @@ define('accounts/picture', [
|
|||||||
modal.modal('hide');
|
modal.modal('hide');
|
||||||
|
|
||||||
pictureCropper.show({
|
pictureCropper.show({
|
||||||
socketMethod: 'user.uploadCroppedPicture',
|
|
||||||
route: config.relative_path + '/api/user/' + ajaxify.data.userslug + '/uploadpicture',
|
|
||||||
aspectRatio: 1 / 1,
|
|
||||||
paramName: 'uid',
|
|
||||||
paramValue: ajaxify.data.theirid,
|
|
||||||
fileSize: ajaxify.data.maximumProfileImageSize,
|
|
||||||
allowSkippingCrop: false,
|
|
||||||
title: '[[user:upload-picture]]',
|
title: '[[user:upload-picture]]',
|
||||||
description: '[[user:upload-a-picture]]',
|
description: '[[user:upload-a-picture]]',
|
||||||
|
socketMethod: 'user.uploadCroppedPicture',
|
||||||
|
route: `${config.relative_path}/api/user/${ajaxify.data.userslug}/uploadpicture`,
|
||||||
|
aspectRatio: 1 / 1,
|
||||||
|
allowSkippingCrop: false,
|
||||||
|
paramName: 'uid',
|
||||||
|
paramValue: ajaxify.data.theirid,
|
||||||
|
restrictImageDimension: true,
|
||||||
|
imageDimension: ajaxify.data.profileImageDimension,
|
||||||
accept: ajaxify.data.allowedProfileImageExtensions,
|
accept: ajaxify.data.allowedProfileImageExtensions,
|
||||||
}, function (url) {
|
}, function (url) {
|
||||||
onUploadComplete(url);
|
onUploadComplete(url);
|
||||||
|
|||||||
@@ -101,12 +101,11 @@ define('pictureCropper', ['alerts'], function (alerts) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
cropperModal.find('.crop-btn').on('click', function () {
|
cropperModal.find('.crop-btn').on('click', function () {
|
||||||
$(this).addClass('disabled');
|
|
||||||
const imageData = checkCORS(cropperTool, data);
|
const imageData = checkCORS(cropperTool, data);
|
||||||
if (!imageData) {
|
if (!imageData) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
$(this).addClass('disabled');
|
||||||
cropperModal.find('#upload-progress-bar').css('width', '0%');
|
cropperModal.find('#upload-progress-bar').css('width', '0%');
|
||||||
cropperModal.find('#upload-progress-box').show().removeClass('hide');
|
cropperModal.find('#upload-progress-box').show().removeClass('hide');
|
||||||
|
|
||||||
@@ -160,7 +159,7 @@ define('pictureCropper', ['alerts'], function (alerts) {
|
|||||||
params: socketData,
|
params: socketData,
|
||||||
}, function (err, result) {
|
}, function (err, result) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return alerts.error(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (socketData.progress + chunkSize < socketData.size) {
|
if (socketData.progress + chunkSize < socketData.size) {
|
||||||
@@ -178,9 +177,14 @@ define('pictureCropper', ['alerts'], function (alerts) {
|
|||||||
function checkCORS(cropperTool, data) {
|
function checkCORS(cropperTool, data) {
|
||||||
let imageData;
|
let imageData;
|
||||||
try {
|
try {
|
||||||
|
const opts = {};
|
||||||
|
if (data.restrictImageDimension) {
|
||||||
|
opts.width = data.imageDimension;
|
||||||
|
opts.height = data.imageDimension;
|
||||||
|
}
|
||||||
imageData = data.imageType ?
|
imageData = data.imageType ?
|
||||||
cropperTool.getCroppedCanvas().toDataURL(data.imageType) :
|
cropperTool.getCroppedCanvas(opts).toDataURL(data.imageType) :
|
||||||
cropperTool.getCroppedCanvas().toDataURL();
|
cropperTool.getCroppedCanvas(opts).toDataURL();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const corsErrors = [
|
const corsErrors = [
|
||||||
'The operation is insecure.',
|
'The operation is insecure.',
|
||||||
@@ -209,7 +213,7 @@ define('pictureCropper', ['alerts'], function (alerts) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const file = fileInput[0].files[0];
|
const file = fileInput[0].files[0];
|
||||||
const fileSize = data.hasOwnProperty('fileSize') && data.fileSize !== undefined ? parseInt(data.fileSize, 10) : false;
|
const fileSize = data.hasOwnProperty('fileSize') && data.fileSize ? parseInt(data.fileSize, 10) : false;
|
||||||
if (fileSize && file.size > fileSize * 1024) {
|
if (fileSize && file.size > fileSize * 1024) {
|
||||||
return showAlert('error', '[[error:file-too-big, ' + fileSize + ']]');
|
return showAlert('error', '[[error:file-too-big, ' + fileSize + ']]');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,12 +35,10 @@ editController.get = async function (req, res, next) {
|
|||||||
userData.customUserFields = customUserFields;
|
userData.customUserFields = customUserFields;
|
||||||
userData.maximumSignatureLength = meta.config.maximumSignatureLength;
|
userData.maximumSignatureLength = meta.config.maximumSignatureLength;
|
||||||
userData.maximumAboutMeLength = meta.config.maximumAboutMeLength;
|
userData.maximumAboutMeLength = meta.config.maximumAboutMeLength;
|
||||||
userData.maximumProfileImageSize = meta.config.maximumProfileImageSize;
|
|
||||||
userData.allowMultipleBadges = meta.config.allowMultipleBadges === 1;
|
userData.allowMultipleBadges = meta.config.allowMultipleBadges === 1;
|
||||||
userData.allowAccountDelete = meta.config.allowAccountDelete === 1;
|
userData.allowAccountDelete = meta.config.allowAccountDelete === 1;
|
||||||
userData.allowAboutMe = !isSelf || !!meta.config['reputation:disabled'] || reputation >= meta.config['min:rep:aboutme'];
|
userData.allowAboutMe = !isSelf || !!meta.config['reputation:disabled'] || reputation >= meta.config['min:rep:aboutme'];
|
||||||
userData.allowSignature = canUseSignature && (!isSelf || !!meta.config['reputation:disabled'] || reputation >= meta.config['min:rep:signature']);
|
userData.allowSignature = canUseSignature && (!isSelf || !!meta.config['reputation:disabled'] || reputation >= meta.config['min:rep:signature']);
|
||||||
userData.profileImageDimension = meta.config.profileImageDimension;
|
|
||||||
userData.defaultAvatar = user.getDefaultAvatar();
|
userData.defaultAvatar = user.getDefaultAvatar();
|
||||||
|
|
||||||
userData.groups = _groups.filter(g => g && g.userTitleEnabled && !groups.isPrivilegeGroup(g.name) && g.name !== 'registered-users');
|
userData.groups = _groups.filter(g => g && g.userTitleEnabled && !groups.isPrivilegeGroup(g.name) && g.name !== 'registered-users');
|
||||||
|
|||||||
@@ -97,6 +97,8 @@ helpers.getUserDataByUserSlug = async function (userslug, callerUID, query = {})
|
|||||||
userData.allowCoverPicture = !userData.isSelf || !!meta.config['reputation:disabled'] || userData.reputation >= meta.config['min:rep:cover-picture'];
|
userData.allowCoverPicture = !userData.isSelf || !!meta.config['reputation:disabled'] || userData.reputation >= meta.config['min:rep:cover-picture'];
|
||||||
userData.allowProfileImageUploads = meta.config.allowProfileImageUploads;
|
userData.allowProfileImageUploads = meta.config.allowProfileImageUploads;
|
||||||
userData.allowedProfileImageExtensions = user.getAllowedProfileImageExtensions().map(ext => `.${ext}`).join(', ');
|
userData.allowedProfileImageExtensions = user.getAllowedProfileImageExtensions().map(ext => `.${ext}`).join(', ');
|
||||||
|
userData.maximumProfileImageSize = meta.config.maximumProfileImageSize;
|
||||||
|
userData.profileImageDimension = meta.config.profileImageDimension;
|
||||||
userData.groups = Array.isArray(results.groups) && results.groups.length ? results.groups[0] : [];
|
userData.groups = Array.isArray(results.groups) && results.groups.length ? results.groups[0] : [];
|
||||||
userData.selectedGroup = userData.groups.filter(group => group && userData.groupTitleArray.includes(group.name))
|
userData.selectedGroup = userData.groups.filter(group => group && userData.groupTitleArray.includes(group.name))
|
||||||
.sort((a, b) => userData.groupTitleArray.indexOf(a.name) - userData.groupTitleArray.indexOf(b.name));
|
.sort((a, b) => userData.groupTitleArray.indexOf(a.name) - userData.groupTitleArray.indexOf(b.name));
|
||||||
|
|||||||
@@ -51,7 +51,10 @@ image.resizeImage = async function (data) {
|
|||||||
const metadata = await sharpImage.metadata();
|
const metadata = await sharpImage.metadata();
|
||||||
|
|
||||||
sharpImage.rotate(); // auto-orients based on exif data
|
sharpImage.rotate(); // auto-orients based on exif data
|
||||||
sharpImage.resize(data.hasOwnProperty('width') ? data.width : null, data.hasOwnProperty('height') ? data.height : null);
|
// don't resize if width/height not changing or not specificied
|
||||||
|
if ((data.width && metadata.width !== data.width) || (data.height && metadata.height !== data.height)) {
|
||||||
|
sharpImage.resize(data.width || null, data.height || null);
|
||||||
|
}
|
||||||
|
|
||||||
if (data.quality) {
|
if (data.quality) {
|
||||||
switch (metadata.format) {
|
switch (metadata.format) {
|
||||||
|
|||||||
Reference in New Issue
Block a user