mirror of
https://github.com/ascribe/onion.git
synced 2024-12-22 17:33:14 +01:00
Limit thumbnail size to 5mb
This commit is contained in:
parent
0f8094ef55
commit
e3c9ebe5f3
@ -20,6 +20,7 @@ let FurtherDetailsFileuploader = React.createClass({
|
|||||||
otherData: React.PropTypes.arrayOf(React.PropTypes.object),
|
otherData: React.PropTypes.arrayOf(React.PropTypes.object),
|
||||||
setIsUploadReady: React.PropTypes.func,
|
setIsUploadReady: React.PropTypes.func,
|
||||||
submitFile: React.PropTypes.func,
|
submitFile: React.PropTypes.func,
|
||||||
|
onValidationFailed: React.PropTypes.func,
|
||||||
isReadyForFormSubmission: React.PropTypes.func,
|
isReadyForFormSubmission: React.PropTypes.func,
|
||||||
editable: React.PropTypes.bool,
|
editable: React.PropTypes.bool,
|
||||||
multiple: React.PropTypes.bool
|
multiple: React.PropTypes.bool
|
||||||
@ -60,6 +61,7 @@ let FurtherDetailsFileuploader = React.createClass({
|
|||||||
}}
|
}}
|
||||||
validation={AppConstants.fineUploader.validation.additionalData}
|
validation={AppConstants.fineUploader.validation.additionalData}
|
||||||
submitFile={this.props.submitFile}
|
submitFile={this.props.submitFile}
|
||||||
|
onValidationFailed={this.props.onValidationFailed}
|
||||||
setIsUploadReady={this.props.setIsUploadReady}
|
setIsUploadReady={this.props.setIsUploadReady}
|
||||||
isReadyForFormSubmission={this.props.isReadyForFormSubmission}
|
isReadyForFormSubmission={this.props.isReadyForFormSubmission}
|
||||||
session={{
|
session={{
|
||||||
|
@ -109,6 +109,11 @@ let RegisterPieceForm = React.createClass({
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
handleThumbnailValidationFailed(thumbnailFile) {
|
||||||
|
// If the validation fails, set the thumbnail as submittable since its optional
|
||||||
|
this.refs.submitButton.setReadyStateForKey('thumbnailKeyReady', true);
|
||||||
|
},
|
||||||
|
|
||||||
isThumbnailDialogExpanded() {
|
isThumbnailDialogExpanded() {
|
||||||
const { enableSeparateThumbnail } = this.props;
|
const { enableSeparateThumbnail } = this.props;
|
||||||
const { digitalWorkFile } = this.state;
|
const { digitalWorkFile } = this.state;
|
||||||
@ -194,14 +199,15 @@ let RegisterPieceForm = React.createClass({
|
|||||||
url: ApiUrls.blob_thumbnails
|
url: ApiUrls.blob_thumbnails
|
||||||
}}
|
}}
|
||||||
handleChangedFile={this.handleChangedThumbnail}
|
handleChangedFile={this.handleChangedThumbnail}
|
||||||
|
onValidationFailed={this.handleThumbnailValidationFailed}
|
||||||
isReadyForFormSubmission={formSubmissionValidation.fileOptional}
|
isReadyForFormSubmission={formSubmissionValidation.fileOptional}
|
||||||
keyRoutine={{
|
keyRoutine={{
|
||||||
url: AppConstants.serverUrl + 's3/key/',
|
url: AppConstants.serverUrl + 's3/key/',
|
||||||
fileClass: 'thumbnail'
|
fileClass: 'thumbnail'
|
||||||
}}
|
}}
|
||||||
validation={{
|
validation={{
|
||||||
itemLimit: AppConstants.fineUploader.validation.registerWork.itemLimit,
|
itemLimit: AppConstants.fineUploader.validation.workThumbnail.itemLimit,
|
||||||
sizeLimit: AppConstants.fineUploader.validation.additionalData.sizeLimit,
|
sizeLimit: AppConstants.fineUploader.validation.workThumbnail.sizeLimit,
|
||||||
allowedExtensions: ['png', 'jpg', 'jpeg', 'gif']
|
allowedExtensions: ['png', 'jpg', 'jpeg', 'gif']
|
||||||
}}
|
}}
|
||||||
setIsUploadReady={this.setIsUploadReady('thumbnailKeyReady')}
|
setIsUploadReady={this.setIsUploadReady('thumbnailKeyReady')}
|
||||||
|
@ -52,6 +52,7 @@ const InputFineUploader = React.createClass({
|
|||||||
plural: string
|
plural: string
|
||||||
}),
|
}),
|
||||||
handleChangedFile: func,
|
handleChangedFile: func,
|
||||||
|
onValidationFailed: func,
|
||||||
|
|
||||||
// Provided by `Property`
|
// Provided by `Property`
|
||||||
onChange: React.PropTypes.func
|
onChange: React.PropTypes.func
|
||||||
@ -107,6 +108,7 @@ const InputFineUploader = React.createClass({
|
|||||||
isFineUploaderActive,
|
isFineUploaderActive,
|
||||||
isReadyForFormSubmission,
|
isReadyForFormSubmission,
|
||||||
keyRoutine,
|
keyRoutine,
|
||||||
|
onValidationFailed,
|
||||||
setIsUploadReady,
|
setIsUploadReady,
|
||||||
uploadMethod,
|
uploadMethod,
|
||||||
validation,
|
validation,
|
||||||
@ -127,6 +129,7 @@ const InputFineUploader = React.createClass({
|
|||||||
createBlobRoutine={createBlobRoutine}
|
createBlobRoutine={createBlobRoutine}
|
||||||
validation={validation}
|
validation={validation}
|
||||||
submitFile={this.submitFile}
|
submitFile={this.submitFile}
|
||||||
|
onValidationFailed={onValidationFailed}
|
||||||
setIsUploadReady={setIsUploadReady}
|
setIsUploadReady={setIsUploadReady}
|
||||||
isReadyForFormSubmission={isReadyForFormSubmission}
|
isReadyForFormSubmission={isReadyForFormSubmission}
|
||||||
areAssetsDownloadable={areAssetsDownloadable}
|
areAssetsDownloadable={areAssetsDownloadable}
|
||||||
|
@ -50,6 +50,7 @@ const ReactS3FineUploader = React.createClass({
|
|||||||
}),
|
}),
|
||||||
handleChangedFile: func, // is for when a file is dropped or selected
|
handleChangedFile: func, // is for when a file is dropped or selected
|
||||||
submitFile: func, // is for when a file has been successfully uploaded, TODO: rename to handleSubmitFile
|
submitFile: func, // is for when a file has been successfully uploaded, TODO: rename to handleSubmitFile
|
||||||
|
onValidationFailed: func,
|
||||||
autoUpload: bool,
|
autoUpload: bool,
|
||||||
debug: bool,
|
debug: bool,
|
||||||
objectProperties: shape({
|
objectProperties: shape({
|
||||||
@ -523,13 +524,16 @@ const ReactS3FineUploader = React.createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
isFileValid(file) {
|
isFileValid(file) {
|
||||||
if(file.size > this.props.validation.sizeLimit) {
|
if (file.size > this.props.validation.sizeLimit) {
|
||||||
|
const fileSizeInMegaBytes = this.props.validation.sizeLimit / 1000000;
|
||||||
|
|
||||||
let fileSizeInMegaBytes = this.props.validation.sizeLimit / 1000000;
|
const notification = new GlobalNotificationModel(getLangText('A file you submitted is bigger than ' + fileSizeInMegaBytes + 'MB.'), 'danger', 5000);
|
||||||
|
|
||||||
let notification = new GlobalNotificationModel(getLangText('A file you submitted is bigger than ' + fileSizeInMegaBytes + 'MB.'), 'danger', 5000);
|
|
||||||
GlobalNotificationActions.appendGlobalNotification(notification);
|
GlobalNotificationActions.appendGlobalNotification(notification);
|
||||||
|
|
||||||
|
if (typeof this.props.onValidationFailed === 'function') {
|
||||||
|
this.props.onValidationFailed(file);
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
|
@ -139,7 +139,7 @@ const PRRegisterPieceForm = React.createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is overloaded so that we can track the ready-state
|
* These two methods are overloaded so that we can track the ready-state
|
||||||
* of each uploader in the component
|
* of each uploader in the component
|
||||||
* @param {string} uploaderKey Name of the uploader's key to track
|
* @param {string} uploaderKey Name of the uploader's key to track
|
||||||
*/
|
*/
|
||||||
@ -151,6 +151,14 @@ const PRRegisterPieceForm = React.createClass({
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
handleOptionalFileValidationFailed(uploaderKey) {
|
||||||
|
return () => {
|
||||||
|
this.setState({
|
||||||
|
[uploaderKey]: true
|
||||||
|
});
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
getSubmitButton() {
|
getSubmitButton() {
|
||||||
const { digitalWorkKeyReady,
|
const { digitalWorkKeyReady,
|
||||||
thumbnailKeyReady,
|
thumbnailKeyReady,
|
||||||
@ -303,7 +311,7 @@ const PRRegisterPieceForm = React.createClass({
|
|||||||
</Property>
|
</Property>
|
||||||
<Property
|
<Property
|
||||||
name="thumbnailKey"
|
name="thumbnailKey"
|
||||||
label={getLangText('Featured Cover photo')}>
|
label={getLangText('Featured Cover photo (max 2MB)')}>
|
||||||
<InputFineuploader
|
<InputFineuploader
|
||||||
fileInputElement={UploadButton()}
|
fileInputElement={UploadButton()}
|
||||||
createBlobRoutine={{
|
createBlobRoutine={{
|
||||||
@ -316,8 +324,8 @@ const PRRegisterPieceForm = React.createClass({
|
|||||||
fileClass: 'thumbnail'
|
fileClass: 'thumbnail'
|
||||||
}}
|
}}
|
||||||
validation={{
|
validation={{
|
||||||
itemLimit: AppConstants.fineUploader.validation.registerWork.itemLimit,
|
itemLimit: AppConstants.fineUploader.validation.workThumbnail.itemLimit,
|
||||||
sizeLimit: AppConstants.fineUploader.validation.additionalData.sizeLimit,
|
sizeLimit: AppConstants.fineUploader.validation.workThumbnail.sizeLimit,
|
||||||
allowedExtensions: ['png', 'jpg', 'jpeg', 'gif']
|
allowedExtensions: ['png', 'jpg', 'jpeg', 'gif']
|
||||||
}}
|
}}
|
||||||
location={location}
|
location={location}
|
||||||
@ -334,6 +342,7 @@ const PRRegisterPieceForm = React.createClass({
|
|||||||
fileInputElement={UploadButton()}
|
fileInputElement={UploadButton()}
|
||||||
isReadyForFormSubmission={formSubmissionValidation.atLeastOneUploadedFile}
|
isReadyForFormSubmission={formSubmissionValidation.atLeastOneUploadedFile}
|
||||||
setIsUploadReady={this.setIsUploadReady('supportingMaterialsReady')}
|
setIsUploadReady={this.setIsUploadReady('supportingMaterialsReady')}
|
||||||
|
onValidationFailed={this.handleOptionalFileValidationFailed('supportingMaterialsReady')}
|
||||||
createBlobRoutine={this.getCreateBlobRoutine()}
|
createBlobRoutine={this.getCreateBlobRoutine()}
|
||||||
keyRoutine={{
|
keyRoutine={{
|
||||||
url: AppConstants.serverUrl + 's3/key/',
|
url: AppConstants.serverUrl + 's3/key/',
|
||||||
|
@ -91,6 +91,10 @@ const constants = {
|
|||||||
'registerWork': {
|
'registerWork': {
|
||||||
'itemLimit': 1,
|
'itemLimit': 1,
|
||||||
'sizeLimit': '25000000000'
|
'sizeLimit': '25000000000'
|
||||||
|
},
|
||||||
|
'workThumbnail': {
|
||||||
|
'itemLimit': 1,
|
||||||
|
'sizeLimit': '5000000'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user