Skip to content

Commit

Permalink
Update actiontext JavaScript
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelfranca committed Oct 27, 2023
1 parent c93a989 commit d0ed4c8
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions actiontext/app/assets/javascripts/actiontext.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand Down Expand Up @@ -604,19 +607,20 @@ 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) => {
if (error) {
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) {
Expand Down

0 comments on commit d0ed4c8

Please sign in to comment.