mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-26 12:21:36 +03:00
Do not allow upload of invalid images to gallery
no issue - added `onUploadStart` action to `{{gh-uploader}}` that is triggered when individual files start uploading - will not be triggered for any files that fail client-side validation - changed `{{koenig-card-gallery}}` to only add images to the local gallery display when the uploader starts an upload
This commit is contained in:
parent
a11ccccae0
commit
bfe985abe2
@ -70,6 +70,7 @@ export default Component.extend({
|
||||
onComplete() {},
|
||||
onFailed() {},
|
||||
onStart() {},
|
||||
onUploadStart() {},
|
||||
onUploadFailure() {},
|
||||
onUploadSuccess() {},
|
||||
|
||||
@ -212,6 +213,8 @@ export default Component.extend({
|
||||
let url = `${ghostPaths().apiRoot}${this.get('uploadUrl')}`;
|
||||
|
||||
try {
|
||||
this.onUploadStart(file);
|
||||
|
||||
let response = yield ajax.post(url, {
|
||||
data: formData,
|
||||
processData: false,
|
||||
|
@ -117,6 +117,15 @@ export default Component.extend({
|
||||
},
|
||||
|
||||
actions: {
|
||||
addImage(file) {
|
||||
let count = this.images.length + 1;
|
||||
let row = Math.ceil(count / MAX_PER_ROW) - 1;
|
||||
|
||||
let image = this._readDataFromImageFile(file);
|
||||
image.row = row;
|
||||
this.images.pushObject(image);
|
||||
},
|
||||
|
||||
setImageSrc(uploadResult) {
|
||||
let image = this.images.findBy('fileName', uploadResult.fileName);
|
||||
|
||||
@ -212,18 +221,6 @@ export default Component.extend({
|
||||
this.set('errorMessage', 'Galleries are limited to 9 images');
|
||||
}
|
||||
this.set('files', strippedFiles);
|
||||
|
||||
let count = this.images.length;
|
||||
let row = Math.ceil(count / MAX_PER_ROW) - 1;
|
||||
|
||||
strippedFiles.forEach((file) => {
|
||||
count = count + 1;
|
||||
row = Math.ceil(count / MAX_PER_ROW) - 1;
|
||||
|
||||
let image = this._readDataFromImageFile(file);
|
||||
image.row = row;
|
||||
this.images.pushObject(image);
|
||||
});
|
||||
},
|
||||
|
||||
_readDataFromImageFile(file) {
|
||||
|
@ -18,6 +18,7 @@
|
||||
files=files
|
||||
accept=imageMimeTypes
|
||||
extensions=imageExtensions
|
||||
onUploadStart=(action "addImage")
|
||||
onUploadSuccess=(action "setImageSrc")
|
||||
onUploadFailure=(action "uploadFailed")
|
||||
as |uploader|
|
||||
|
Loading…
Reference in New Issue
Block a user