From d0ed4c8ecc5580c4f6dfcd1d529bc3476fdd73be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Fri, 27 Oct 2023 13:50:49 +0000 Subject: [PATCH] Update actiontext JavaScript --- actiontext/app/assets/javascripts/actiontext.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/actiontext/app/assets/javascripts/actiontext.js b/actiontext/app/assets/javascripts/actiontext.js index e462ed4d14..d4b0b1f50f 100644 --- a/actiontext/app/assets/javascripts/actiontext.js +++ b/actiontext/app/assets/javascripts/actiontext.js @@ -508,7 +508,7 @@ function toArray(value) { } class BlobRecord { - constructor(file, checksum, url) { + constructor(file, checksum, url, customHeaders = {}) { this.file = file; this.attributes = { filename: file.name, @@ -522,6 +522,9 @@ class BlobRecord { this.xhr.setRequestHeader("Content-Type", "application/json"); this.xhr.setRequestHeader("Accept", "application/json"); this.xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest"); + Object.keys(customHeaders).forEach((headerKey => { + this.xhr.setRequestHeader(headerKey, customHeaders[headerKey]); + })); const csrfToken = getMetaValue("csrf-token"); if (csrfToken != undefined) { this.xhr.setRequestHeader("X-CSRF-Token", csrfToken); @@ -604,11 +607,12 @@ class BlobUpload { let id = 0; class DirectUpload { - constructor(file, url, delegate) { + constructor(file, url, delegate, customHeaders = {}) { this.id = ++id; this.file = file; this.url = url; this.delegate = delegate; + this.customHeaders = customHeaders; } create(callback) { FileChecksum.create(this.file, ((error, checksum) => { @@ -616,7 +620,7 @@ class DirectUpload { callback(error); return; } - const blob = new BlobRecord(this.file, checksum, this.url); + const blob = new BlobRecord(this.file, checksum, this.url, this.customHeaders); notify(this.delegate, "directUploadWillCreateBlobWithXHR", blob.xhr); blob.create((error => { if (error) {