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", "Streamer": "Streamer",
"Pinned": "Pinned", "Pinned": "Pinned",
"From Comments": "From Comments", "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--" "--end--": "--end--"
} }

View file

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

View file

@ -188,7 +188,7 @@ function SelectThumbnail(props: Props) {
<p className="help"> <p className="help">
{manualInput {manualInput
? __('Enter a URL for your thumbnail.') ? __('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> </p>
)} )}
</> </>

View file

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