Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ES5 Compatiblitiy #480

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@
"dependencies": {
"dropzone": "^5.5.1"
}
}
}
30 changes: 17 additions & 13 deletions src/components/vue-dropzone.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ export default {
required: false
}
},
data() {
data: function() {
return {
isS3: false,
isS3OverridesServerPropagation: false,
wasQueueAutoProcess: true
};
},
computed: {
dropzoneSettings() {
dropzoneSettings: function() {
let defaultValues = {
thumbnailWidth: 200,
thumbnailHeight: 200
Expand All @@ -74,15 +74,15 @@ export default {
this.wasQueueAutoProcess = this.options.autoProcessQueue; //eslint-disable-line

if (this.isS3OverridesServerPropagation) {
defaultValues["url"] = files => {
defaultValues["url"] = function(files) {
return files[0].s3Url;
};
}
}
return defaultValues;
}
},
mounted() {
mounted: function() {
if (this.$isServer && this.hasBeenMounted) {
return;
}
Expand Down Expand Up @@ -267,7 +267,7 @@ export default {

vm.$emit("vdropzone-mounted");
},
beforeDestroy() {
beforeDestroy: function () {
if (this.destroyDropzone) this.dropzone.destroy();
},
methods: {
Expand Down Expand Up @@ -316,7 +316,7 @@ export default {
processQueue: function() {
let dropzoneEle = this.dropzone;
if (this.isS3 && !this.wasQueueAutoProcess) {
this.getQueuedFiles().forEach(file => {
this.getQueuedFiles().forEach(function (file) {
this.getSignedAndUploadToS3(file);
});
} else {
Expand Down Expand Up @@ -389,17 +389,19 @@ export default {
getActiveFiles: function() {
return this.dropzone.getActiveFiles();
},
getSignedAndUploadToS3(file) {
getSignedAndUploadToS3: function(file) {
var promise = awsEndpoint.sendFile(
file,
this.awss3,
this.isS3OverridesServerPropagation
);
if (!this.isS3OverridesServerPropagation) {
promise.then(response => {
promise.then(function (response) {
if (response.success) {
file.s3ObjectLocation = response.message;
setTimeout(() => this.dropzone.processFile(file));
setTimeout(function () {
this.dropzone.processFile(file)
});
this.$emit("vdropzone-s3-upload-success", response.message);
} else {
if ("undefined" !== typeof response.message) {
Expand All @@ -413,15 +415,17 @@ export default {
}
});
} else {
promise.then(() => {
setTimeout(() => this.dropzone.processFile(file));
promise.then(function () {
setTimeout(function () {
this.dropzone.processFile(file)
});
});
}
promise.catch(error => {
promise.catch(function (error) {
alert(error);
});
},
setAWSSigningURL(location) {
setAWSSigningURL: function(location) {
if (this.isS3) {
this.awss3.signingURL = location;
}
Expand Down
20 changes: 10 additions & 10 deletions src/services/urlsigner.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export default {
getSignedURL(file, config) {
getSignedURL: function(file, config) {
let payload = {
filePath: file.name,
contentType: file.type
}

return new Promise((resolve, reject) => {
return new Promise(function (resolve, reject) {
var fd = new FormData();
let request = new XMLHttpRequest(),
signingURL = (typeof config.signingURL === "function") ? config.signingURL(file) : config.signingURL;
Expand All @@ -24,37 +24,37 @@ export default {
if (config.withCredentials === true) {
request.withCredentials = true;
}
Object.entries(config.headers || {}).forEach(([name, value]) => {
Object.entries(config.headers || {}).forEach(function (name, value) {
request.setRequestHeader(name, value);
});
payload = Object.assign(payload, config.params || {});
Object.entries(payload).forEach(([name, value]) => {
Object.entries(payload).forEach(function (name, value) {
fd.append(name, value);
});

request.send(fd);
});
},
sendFile(file, config, is_sending_s3) {
sendFile: function(file, config, is_sending_s3) {
var handler = (is_sending_s3) ? this.setResponseHandler : this.sendS3Handler;

return this.getSignedURL(file, config)
.then((response) => {return handler(response, file)})
.catch((error) => { return error; });
.then(function (response) {return handler(response, file)})
.catch(function (error) { return error; });
},
setResponseHandler(response, file) {
setResponseHandler: function (response, file) {
file.s3Signature = response.signature;
file.s3Url = response.postEndpoint;
},
sendS3Handler(response, file) {
sendS3Handler: function(response, file) {
let fd = new FormData(),
signature = response.signature;

Object.keys(signature).forEach(function (key) {
fd.append(key, signature[key]);
});
fd.append('file', file);
return new Promise((resolve, reject) => {
return new Promise(function (resolve, reject) {
let request = new XMLHttpRequest();
request.open('POST', response.postEndpoint);
request.onload = function () {
Expand Down