2MB max thumb size messaging (#650)

This commit is contained in:
Thomas Zarebczan 2022-01-07 14:39:27 -05:00 committed by GitHub
parent b822fbdac8
commit ac93e0c22c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 5 deletions

View file

@ -2246,5 +2246,7 @@
"Streamer": "Streamer",
"Pinned": "Pinned",
"From Comments": "From Comments",
"Upload your thumbnail to %domain%. Recommended ratio is 16:9, 2MB max.": "Upload your thumbnail to %domain%. Recommended ratio is 16:9, 2MB max.",
"Thumbnail size over 2MB, please edit and reupload.": "Thumbnail size over 2MB, please edit and reupload.",
"--end--": "--end--"
}

View file

@ -282,7 +282,7 @@ function ChannelForm(props: Props) {
openModal(MODALS.IMAGE_UPLOAD, {
onUpdate: (coverUrl, isUpload) => handleCoverChange(coverUrl, isUpload),
title: __('Edit Cover Image'),
helpText: __('(6.25:1)'),
helpText: __('(6.25:1 ratio, 2MB max)'),
assetName: __('Cover Image'),
currentValue: params.coverUrl,
})
@ -308,7 +308,7 @@ function ChannelForm(props: Props) {
openModal(MODALS.IMAGE_UPLOAD, {
onUpdate: (thumbnailUrl, isUpload) => handleThumbnailChange(thumbnailUrl, isUpload),
title: __('Edit Thumbnail Image'),
helpText: __('(1:1)'),
helpText: __('(1:1 ratio, 2MB max)'),
assetName: __('Thumbnail'),
currentValue: params.thumbnailUrl,
})

View file

@ -188,7 +188,7 @@ function SelectThumbnail(props: Props) {
<p className="help">
{manualInput
? __('Enter a URL for your thumbnail.')
: __('Upload your thumbnail to %domain%. Recommended size is 16:9.', { domain: DOMAIN })}
: __('Upload your thumbnail to %domain%. Recommended ratio is 16:9, 2MB max.', { domain: DOMAIN })}
</p>
)}
</>

View file

@ -412,7 +412,7 @@ export const doUploadThumbnail = (
path?: any,
cb?: (string) => void
) => (dispatch: Dispatch) => {
let thumbnail, fileExt, fileName, fileType;
let thumbnail, fileExt, fileName, fileType, stats, size;
const uploadError = (error = '') => {
dispatch(
@ -475,7 +475,11 @@ export const doUploadThumbnail = (
message = __('Thumbnail upload service may be down, try again later.');
}
const userInput = [fileName, fileExt, fileType, thumbnail];
const userInput = [fileName, fileExt, fileType, thumbnail, size];
if (size >= 2097152) {
message = __('Thumbnail size over 2MB, please edit and reupload.');
}
uploadError({ message, cause: `${userInput.join(' | ')}` });
});
};
@ -502,11 +506,14 @@ export const doUploadThumbnail = (
thumbnail = fs.readFileSync(filePath);
fileExt = path.extname(filePath);
fileName = path.basename(filePath);
stats = fs.statSync(filePath);
size = stats.size;
fileType = `image/${fileExt.slice(1)}`;
} else if (thumbnailBlob) {
fileExt = `.${thumbnailBlob.type && thumbnailBlob.type.split('/')[1]}`;
fileName = thumbnailBlob.name;
fileType = thumbnailBlob.type;
size = thumbnailBlob.size;
} else {
return null;
}