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

Added capabilities to have async header functions #823

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
39 changes: 21 additions & 18 deletions dist/filepond.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -1600,7 +1600,7 @@ const InteractionMethod = {
const getUniqueId = () =>
Math.random()
.toString(36)
.substr(2, 9);
.substring(2, 11);

const arrayRemove = (arr, index) => arr.splice(index, 1);

Expand Down Expand Up @@ -2626,24 +2626,27 @@ const sendRequest = (data, url, options) => {
xhr.timeout = options.timeout;
}

// add headers
Object.keys(options.headers).forEach(key => {
const value = unescape(encodeURIComponent(options.headers[key]));
xhr.setRequestHeader(key, value);
});
// execute async headers
Promise.resolve(options.headers).then(headers => {
// add headers
Object.keys(headers).forEach(key => {
const value = unescape(encodeURIComponent(headers[key]));
xhr.setRequestHeader(key, value);
});

// set type of response
if (options.responseType) {
xhr.responseType = options.responseType;
}
// set type of response
if (options.responseType) {
xhr.responseType = options.responseType;
}

// set credentials
if (options.withCredentials) {
xhr.withCredentials = true;
}
// set credentials
if (options.withCredentials) {
xhr.withCredentials = true;
}

// let's send our data
xhr.send(data);
// let's send our data
xhr.send(data);
});

return api;
};
Expand Down Expand Up @@ -3453,7 +3456,7 @@ const createFileProcessor = (processFn, options) => {
return api;
};

const getFilenameWithoutExtension = name => name.substr(0, name.lastIndexOf('.')) || name;
const getFilenameWithoutExtension = name => name.substring(0, name.lastIndexOf('.')) || name;

const createFileStub = source => {
let data = [source.name, source.size, source.type];
Expand Down Expand Up @@ -8063,7 +8066,7 @@ const write$9 = ({ root, props, actions }) => {
.filter(action => /^DID_SET_STYLE_/.test(action.type))
.filter(action => !isEmpty(action.data.value))
.map(({ type, data }) => {
const name = toCamels(type.substr(8).toLowerCase(), '_');
const name = toCamels(type.substring(8).toLowerCase(), '_');
root.element.dataset[name] = data.value;
root.invalidateLayout();
});
Expand Down
2 changes: 1 addition & 1 deletion dist/filepond.esm.min.js

Large diffs are not rendered by default.

39 changes: 21 additions & 18 deletions dist/filepond.js
Original file line number Diff line number Diff line change
Expand Up @@ -1875,7 +1875,7 @@
var getUniqueId = function getUniqueId() {
return Math.random()
.toString(36)
.substr(2, 9);
.substring(2, 11);
};

function _typeof(obj) {
Expand Down Expand Up @@ -4676,24 +4676,27 @@
xhr.timeout = options.timeout;
}

// add headers
Object.keys(options.headers).forEach(function(key) {
var value = unescape(encodeURIComponent(options.headers[key]));
xhr.setRequestHeader(key, value);
});
// execute async headers
Promise.resolve(options.headers).then(function(headers) {
// add headers
Object.keys(headers).forEach(function(key) {
var value = unescape(encodeURIComponent(headers[key]));
xhr.setRequestHeader(key, value);
});

// set type of response
if (options.responseType) {
xhr.responseType = options.responseType;
}
// set type of response
if (options.responseType) {
xhr.responseType = options.responseType;
}

// set credentials
if (options.withCredentials) {
xhr.withCredentials = true;
}
// set credentials
if (options.withCredentials) {
xhr.withCredentials = true;
}

// let's send our data
xhr.send(data);
// let's send our data
xhr.send(data);
});

return api;
};
Expand Down Expand Up @@ -5624,7 +5627,7 @@
};

var getFilenameWithoutExtension = function getFilenameWithoutExtension(name) {
return name.substr(0, name.lastIndexOf('.')) || name;
return name.substring(0, name.lastIndexOf('.')) || name;
};

var createFileStub = function createFileStub(source) {
Expand Down Expand Up @@ -10871,7 +10874,7 @@
.map(function(_ref4) {
var type = _ref4.type,
data = _ref4.data;
var name = toCamels(type.substr(8).toLowerCase(), '_');
var name = toCamels(type.substring(8).toLowerCase(), '_');
root.element.dataset[name] = data.value;
root.invalidateLayout();
});
Expand Down
2 changes: 1 addition & 1 deletion dist/filepond.min.js

Large diffs are not rendered by default.

21 changes: 19 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 20 additions & 16 deletions src/js/utils/sendRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,24 +107,28 @@ export const sendRequest = (data, url, options) => {
xhr.timeout = options.timeout;
}

// add headers
Object.keys(options.headers).forEach(key => {
const value = unescape(encodeURIComponent(options.headers[key]));
xhr.setRequestHeader(key, value);
});

// set type of response
if (options.responseType) {
xhr.responseType = options.responseType;
}
// execute async headers
Promise.resolve(options.headers).then(headers => {

// add headers
Object.keys(headers).forEach(key => {
const value = unescape(encodeURIComponent(headers[key]));
xhr.setRequestHeader(key, value);
});

// set type of response
if (options.responseType) {
xhr.responseType = options.responseType;
}

// set credentials
if (options.withCredentials) {
xhr.withCredentials = true;
}
// set credentials
if (options.withCredentials) {
xhr.withCredentials = true;
}

// let's send our data
xhr.send(data);
// let's send our data
xhr.send(data);
});

return api;
};