From 206393f8b3151a7c51d3b618dfb09f7ccb5cf937 Mon Sep 17 00:00:00 2001 From: Michael Chen Date: Tue, 22 Dec 2020 13:30:06 +0800 Subject: [PATCH] make csrfName configurable; aware of response filePath --- src/js/easymde.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/js/easymde.js b/src/js/easymde.js index f5758df..958eaa3 100644 --- a/src/js/easymde.js +++ b/src/js/easymde.js @@ -2328,7 +2328,8 @@ EasyMDE.prototype.uploadImage = function (file, onSuccess, onError) { // insert CSRF token if provided in config. if (self.options.imageCSRFToken) { - formData.append('csrfmiddlewaretoken', self.options.imageCSRFToken); + var csrfName = self.options.imageCSRFName || 'csrfmiddlewaretoken'; + formData.append(csrfName, self.options.imageCSRFToken); } var request = new XMLHttpRequest(); request.upload.onprogress = function (event) { @@ -2347,8 +2348,14 @@ EasyMDE.prototype.uploadImage = function (file, onSuccess, onError) { onErrorSup(fillErrorMessage(self.options.errorMessages.importError)); return; } - if (this.status === 200 && response && !response.error && response.data && response.data.filePath) { - onSuccess(window.location.origin + '/' + response.data.filePath); + if ((this.status === 200 || this.status === 201) && response && !response.error && response.data && response.data.filePath) { + var filePath = response.data.filePath; + if (/https?:\/\//i.test(filePath)) { + onSuccess(filePath); + } else { + onSuccess(window.location.origin + '/' + filePath); + } + } else { if (response.error && response.error in self.options.errorMessages) { // preformatted error message onErrorSup(fillErrorMessage(self.options.errorMessages[response.error]));