mirror of
https://github.com/rr-/szurubooru.git
synced 2025-07-17 08:26:24 +00:00
client/api: merge URL and Blob based file uploads
This commit is contained in:
@ -63,6 +63,7 @@ class Api extends events.EventTarget {
|
||||
|
||||
_process(url, requestFactory, data, files, options) {
|
||||
options = options || {};
|
||||
data = Object.assign({}, data);
|
||||
const [fullUrl, query] = this._getFullUrl(url);
|
||||
|
||||
let abortFunction = null;
|
||||
@ -74,14 +75,19 @@ class Api extends events.EventTarget {
|
||||
if (query) {
|
||||
req.query(query);
|
||||
}
|
||||
if (data) {
|
||||
req.attach('metadata', new Blob([JSON.stringify(data)]));
|
||||
}
|
||||
if (files) {
|
||||
for (let key of Object.keys(files)) {
|
||||
req.attach(key, files[key] || new Blob());
|
||||
const value = files[key];
|
||||
if (value.constructor === String) {
|
||||
data[key + 'Url'] = value;
|
||||
} else {
|
||||
req.attach(key, value || new Blob());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (data) {
|
||||
req.attach('metadata', new Blob([JSON.stringify(data)]));
|
||||
}
|
||||
try {
|
||||
if (this.userName && this.userPassword) {
|
||||
req.auth(
|
||||
|
Reference in New Issue
Block a user