mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-31 21:19:21 +03:00
Added support for JavaScript FormData
As preparation for 2FA plugins and easier Fetch calls
This commit is contained in:
parent
5a0f6c2b9f
commit
0a69c6410d
5 changed files with 26 additions and 31 deletions
14
dev/bootstrap.js
vendored
14
dev/bootstrap.js
vendored
|
|
@ -94,10 +94,7 @@ export default App => {
|
|||
if (postData) {
|
||||
init.method = 'POST';
|
||||
init.headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';
|
||||
postData.XToken = Settings.app('token');
|
||||
// init.body = JSON.stringify(postData);
|
||||
const formData = new FormData(),
|
||||
buildFormData = (formData, data, parentKey) => {
|
||||
const buildFormData = (formData, data, parentKey) => {
|
||||
if (data && typeof data === 'object' && !(data instanceof Date || data instanceof File)) {
|
||||
Object.keys(data).forEach(key =>
|
||||
buildFormData(formData, data[key], parentKey ? `${parentKey}[${key}]` : key)
|
||||
|
|
@ -105,9 +102,14 @@ export default App => {
|
|||
} else {
|
||||
formData.set(parentKey, data == null ? '' : data);
|
||||
}
|
||||
return formData;
|
||||
};
|
||||
buildFormData(formData, postData);
|
||||
init.body = new URLSearchParams(formData);
|
||||
postData = (postData instanceof FormData)
|
||||
? postData
|
||||
: buildFormData(new FormData(), postData);
|
||||
postData.set('XToken', Settings.app('token'));
|
||||
// init.body = JSON.stringify(Object.fromEntries(postData));
|
||||
init.body = new URLSearchParams(postData);
|
||||
}
|
||||
|
||||
return fetch(resource, init).then(response => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue