@driveflux/upload 1.4.3 → 1.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/uppy.js +139 -373
- package/package.json +1 -1
package/dist/uppy.js
CHANGED
|
@@ -1,179 +1,3 @@
|
|
|
1
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
2
|
-
try {
|
|
3
|
-
var info = gen[key](arg);
|
|
4
|
-
var value = info.value;
|
|
5
|
-
} catch (error) {
|
|
6
|
-
reject(error);
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
if (info.done) {
|
|
10
|
-
resolve(value);
|
|
11
|
-
} else {
|
|
12
|
-
Promise.resolve(value).then(_next, _throw);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
function _async_to_generator(fn) {
|
|
16
|
-
return function() {
|
|
17
|
-
var self = this, args = arguments;
|
|
18
|
-
return new Promise(function(resolve, reject) {
|
|
19
|
-
var gen = fn.apply(self, args);
|
|
20
|
-
function _next(value) {
|
|
21
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
22
|
-
}
|
|
23
|
-
function _throw(err) {
|
|
24
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
25
|
-
}
|
|
26
|
-
_next(undefined);
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
function _define_property(obj, key, value) {
|
|
31
|
-
if (key in obj) {
|
|
32
|
-
Object.defineProperty(obj, key, {
|
|
33
|
-
value: value,
|
|
34
|
-
enumerable: true,
|
|
35
|
-
configurable: true,
|
|
36
|
-
writable: true
|
|
37
|
-
});
|
|
38
|
-
} else {
|
|
39
|
-
obj[key] = value;
|
|
40
|
-
}
|
|
41
|
-
return obj;
|
|
42
|
-
}
|
|
43
|
-
function _object_spread(target) {
|
|
44
|
-
for(var i = 1; i < arguments.length; i++){
|
|
45
|
-
var source = arguments[i] != null ? arguments[i] : {};
|
|
46
|
-
var ownKeys = Object.keys(source);
|
|
47
|
-
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
48
|
-
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
49
|
-
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
50
|
-
}));
|
|
51
|
-
}
|
|
52
|
-
ownKeys.forEach(function(key) {
|
|
53
|
-
_define_property(target, key, source[key]);
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
return target;
|
|
57
|
-
}
|
|
58
|
-
function ownKeys(object, enumerableOnly) {
|
|
59
|
-
var keys = Object.keys(object);
|
|
60
|
-
if (Object.getOwnPropertySymbols) {
|
|
61
|
-
var symbols = Object.getOwnPropertySymbols(object);
|
|
62
|
-
if (enumerableOnly) {
|
|
63
|
-
symbols = symbols.filter(function(sym) {
|
|
64
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
keys.push.apply(keys, symbols);
|
|
68
|
-
}
|
|
69
|
-
return keys;
|
|
70
|
-
}
|
|
71
|
-
function _object_spread_props(target, source) {
|
|
72
|
-
source = source != null ? source : {};
|
|
73
|
-
if (Object.getOwnPropertyDescriptors) {
|
|
74
|
-
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
75
|
-
} else {
|
|
76
|
-
ownKeys(Object(source)).forEach(function(key) {
|
|
77
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
return target;
|
|
81
|
-
}
|
|
82
|
-
function _ts_generator(thisArg, body) {
|
|
83
|
-
var f, y, t, g, _ = {
|
|
84
|
-
label: 0,
|
|
85
|
-
sent: function() {
|
|
86
|
-
if (t[0] & 1) throw t[1];
|
|
87
|
-
return t[1];
|
|
88
|
-
},
|
|
89
|
-
trys: [],
|
|
90
|
-
ops: []
|
|
91
|
-
};
|
|
92
|
-
return g = {
|
|
93
|
-
next: verb(0),
|
|
94
|
-
"throw": verb(1),
|
|
95
|
-
"return": verb(2)
|
|
96
|
-
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
97
|
-
return this;
|
|
98
|
-
}), g;
|
|
99
|
-
function verb(n) {
|
|
100
|
-
return function(v) {
|
|
101
|
-
return step([
|
|
102
|
-
n,
|
|
103
|
-
v
|
|
104
|
-
]);
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
function step(op) {
|
|
108
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
109
|
-
while(_)try {
|
|
110
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
111
|
-
if (y = 0, t) op = [
|
|
112
|
-
op[0] & 2,
|
|
113
|
-
t.value
|
|
114
|
-
];
|
|
115
|
-
switch(op[0]){
|
|
116
|
-
case 0:
|
|
117
|
-
case 1:
|
|
118
|
-
t = op;
|
|
119
|
-
break;
|
|
120
|
-
case 4:
|
|
121
|
-
_.label++;
|
|
122
|
-
return {
|
|
123
|
-
value: op[1],
|
|
124
|
-
done: false
|
|
125
|
-
};
|
|
126
|
-
case 5:
|
|
127
|
-
_.label++;
|
|
128
|
-
y = op[1];
|
|
129
|
-
op = [
|
|
130
|
-
0
|
|
131
|
-
];
|
|
132
|
-
continue;
|
|
133
|
-
case 7:
|
|
134
|
-
op = _.ops.pop();
|
|
135
|
-
_.trys.pop();
|
|
136
|
-
continue;
|
|
137
|
-
default:
|
|
138
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
139
|
-
_ = 0;
|
|
140
|
-
continue;
|
|
141
|
-
}
|
|
142
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
143
|
-
_.label = op[1];
|
|
144
|
-
break;
|
|
145
|
-
}
|
|
146
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
147
|
-
_.label = t[1];
|
|
148
|
-
t = op;
|
|
149
|
-
break;
|
|
150
|
-
}
|
|
151
|
-
if (t && _.label < t[2]) {
|
|
152
|
-
_.label = t[2];
|
|
153
|
-
_.ops.push(op);
|
|
154
|
-
break;
|
|
155
|
-
}
|
|
156
|
-
if (t[2]) _.ops.pop();
|
|
157
|
-
_.trys.pop();
|
|
158
|
-
continue;
|
|
159
|
-
}
|
|
160
|
-
op = body.call(thisArg, _);
|
|
161
|
-
} catch (e) {
|
|
162
|
-
op = [
|
|
163
|
-
6,
|
|
164
|
-
e
|
|
165
|
-
];
|
|
166
|
-
y = 0;
|
|
167
|
-
} finally{
|
|
168
|
-
f = t = 0;
|
|
169
|
-
}
|
|
170
|
-
if (op[0] & 5) throw op[1];
|
|
171
|
-
return {
|
|
172
|
-
value: op[0] ? op[1] : void 0,
|
|
173
|
-
done: true
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
1
|
import { config } from '@driveflux/config/frontend';
|
|
178
2
|
import { enhancedFetch } from '@driveflux/fetch';
|
|
179
3
|
import { useToastResult } from '@driveflux/ui/toast';
|
|
@@ -181,202 +5,159 @@ import AwsS3Multipart from '@uppy/aws-s3';
|
|
|
181
5
|
import Uppy from '@uppy/core';
|
|
182
6
|
import isEqual from 'lodash/isEqual.js';
|
|
183
7
|
import { useCallback, useEffect, useMemo, useRef } from 'react';
|
|
184
|
-
|
|
8
|
+
const defaultOptions = {
|
|
185
9
|
autoProceed: true,
|
|
186
10
|
restrictions: {
|
|
187
|
-
maxFileSize: 10000000,
|
|
188
|
-
maxTotalFileSize: 100000000,
|
|
11
|
+
maxFileSize: 10000000, // 10MB
|
|
12
|
+
maxTotalFileSize: 100000000, // 100MB
|
|
189
13
|
maxNumberOfFiles: 20,
|
|
190
|
-
allowedFileTypes: [
|
|
191
|
-
'image/*',
|
|
192
|
-
'application/pdf'
|
|
193
|
-
],
|
|
14
|
+
allowedFileTypes: ['image/*', 'application/pdf'],
|
|
194
15
|
minFileSize: 1000,
|
|
195
16
|
minNumberOfFiles: 1,
|
|
196
|
-
requiredMetaFields: []
|
|
17
|
+
requiredMetaFields: [],
|
|
197
18
|
},
|
|
198
|
-
getUploadParameters: null,
|
|
199
|
-
realm: null
|
|
19
|
+
getUploadParameters: null, // required
|
|
20
|
+
realm: null, // required
|
|
200
21
|
};
|
|
201
|
-
|
|
202
|
-
|
|
22
|
+
const initUppy = (uppyOptions, s3PluginOptions) => {
|
|
23
|
+
const uppy = new Uppy(uppyOptions);
|
|
203
24
|
// @ts-expect-error
|
|
204
25
|
uppy.use(AwsS3Multipart, s3PluginOptions);
|
|
205
26
|
return uppy;
|
|
206
27
|
};
|
|
207
|
-
export
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
28
|
+
export const useUppy = (options, isUnauthenticated) => {
|
|
29
|
+
const previousOptions = useRef({
|
|
30
|
+
...defaultOptions,
|
|
31
|
+
...options,
|
|
32
|
+
restrictions: defaultOptions.restrictions,
|
|
33
|
+
});
|
|
34
|
+
const finalOptions = useMemo(() => {
|
|
35
|
+
const newOptions = {
|
|
36
|
+
...defaultOptions,
|
|
37
|
+
...options,
|
|
38
|
+
restrictions: {
|
|
39
|
+
...defaultOptions.restrictions,
|
|
40
|
+
...options.restrictions,
|
|
41
|
+
},
|
|
42
|
+
};
|
|
215
43
|
if (isEqual(newOptions, previousOptions.current)) {
|
|
216
44
|
return previousOptions.current;
|
|
217
45
|
}
|
|
218
46
|
previousOptions.current = newOptions;
|
|
219
47
|
return newOptions;
|
|
220
|
-
}, [
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
return {
|
|
229
|
-
autoProceed: autoProceed,
|
|
230
|
-
restrictions: restrictions
|
|
231
|
-
};
|
|
232
|
-
}, [
|
|
48
|
+
}, [options]);
|
|
49
|
+
const { autoProceed = true, restrictions, getUploadParameters, onUploadSuccess, onComplete, prefixFile, onError, realm, } = finalOptions;
|
|
50
|
+
const uploadUrlsMap = useRef(new Map());
|
|
51
|
+
const publicAcl = typeof options.publicAcl === 'boolean'
|
|
52
|
+
? options.publicAcl
|
|
53
|
+
: realm === 'site';
|
|
54
|
+
const { toastResult, toastError } = useToastResult();
|
|
55
|
+
const uppyOptions = useMemo(() => ({
|
|
233
56
|
autoProceed,
|
|
234
|
-
restrictions
|
|
235
|
-
]);
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
return
|
|
241
|
-
var parts, prefix, filename, targetUrl, body, response, url;
|
|
242
|
-
return _ts_generator(this, function(_state) {
|
|
243
|
-
switch(_state.label){
|
|
244
|
-
case 0:
|
|
245
|
-
if (getUploadParameters) {
|
|
246
|
-
return [
|
|
247
|
-
2,
|
|
248
|
-
getUploadParameters(file)
|
|
249
|
-
];
|
|
250
|
-
}
|
|
251
|
-
if (!realm) {
|
|
252
|
-
toastError({
|
|
253
|
-
title: 'Error while uploading file',
|
|
254
|
-
description: 'No realm provided'
|
|
255
|
-
});
|
|
256
|
-
throw new Error('No realm provided');
|
|
257
|
-
}
|
|
258
|
-
if (!file.type) {
|
|
259
|
-
toastError({
|
|
260
|
-
title: 'Error while uploading file',
|
|
261
|
-
description: 'No file type provided'
|
|
262
|
-
});
|
|
263
|
-
throw new Error('No file type provided');
|
|
264
|
-
}
|
|
265
|
-
parts = [];
|
|
266
|
-
prefix = file.meta.prefix;
|
|
267
|
-
if (typeof prefix === 'string' && !!prefix.length) {
|
|
268
|
-
parts.push(prefix.replace(/\/$/, ''));
|
|
269
|
-
}
|
|
270
|
-
parts.push(file.name || 'unknown');
|
|
271
|
-
filename = parts.join('/');
|
|
272
|
-
targetUrl = "".concat(config.apiUrl, "/files/").concat(isUnauthenticated ? 'unauthenticated-sign-upload' : 'sign-upload');
|
|
273
|
-
body = {
|
|
274
|
-
filename: filename,
|
|
275
|
-
contentType: file.type,
|
|
276
|
-
realm: realm,
|
|
277
|
-
publicAcl: publicAcl,
|
|
278
|
-
isUnauthenticated: isUnauthenticated
|
|
279
|
-
};
|
|
280
|
-
return [
|
|
281
|
-
4,
|
|
282
|
-
enhancedFetch(targetUrl, {
|
|
283
|
-
method: 'POST',
|
|
284
|
-
body: JSON.stringify(body)
|
|
285
|
-
})
|
|
286
|
-
];
|
|
287
|
-
case 1:
|
|
288
|
-
response = _state.sent();
|
|
289
|
-
if (response.err) {
|
|
290
|
-
toastResult(response, {
|
|
291
|
-
error: {
|
|
292
|
-
title: 'Error while uploading file',
|
|
293
|
-
description: response.val.message
|
|
294
|
-
}
|
|
295
|
-
});
|
|
296
|
-
throw new Error(response.val.message || 'Error while uploading file');
|
|
297
|
-
}
|
|
298
|
-
// We remove the query string from the url and store it in the uploadUrlsMap
|
|
299
|
-
// this is because uppy may not return the url in the upload success callback
|
|
300
|
-
url = response.val.url.split('?')[0];
|
|
301
|
-
uploadUrlsMap.current.set(file.id, url);
|
|
302
|
-
return [
|
|
303
|
-
2,
|
|
304
|
-
{
|
|
305
|
-
method: 'PUT',
|
|
306
|
-
url: response.val.url,
|
|
307
|
-
fields: {},
|
|
308
|
-
headers: {
|
|
309
|
-
'Content-Type': file.type
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
];
|
|
313
|
-
}
|
|
314
|
-
});
|
|
315
|
-
})();
|
|
57
|
+
restrictions: restrictions,
|
|
58
|
+
}), [autoProceed, restrictions]);
|
|
59
|
+
const s3PluginOptions = useMemo(() => ({
|
|
60
|
+
id: 'AwsS3',
|
|
61
|
+
async getUploadParameters(file) {
|
|
62
|
+
if (getUploadParameters) {
|
|
63
|
+
return getUploadParameters(file);
|
|
316
64
|
}
|
|
317
|
-
|
|
318
|
-
|
|
65
|
+
if (!realm) {
|
|
66
|
+
toastError({
|
|
67
|
+
title: 'Error while uploading file',
|
|
68
|
+
description: 'No realm provided',
|
|
69
|
+
});
|
|
70
|
+
throw new Error('No realm provided');
|
|
71
|
+
}
|
|
72
|
+
if (!file.type) {
|
|
73
|
+
toastError({
|
|
74
|
+
title: 'Error while uploading file',
|
|
75
|
+
description: 'No file type provided',
|
|
76
|
+
});
|
|
77
|
+
throw new Error('No file type provided');
|
|
78
|
+
}
|
|
79
|
+
const parts = [];
|
|
80
|
+
const prefix = file.meta.prefix;
|
|
81
|
+
if (typeof prefix === 'string' && !!prefix.length) {
|
|
82
|
+
parts.push(prefix.replace(/\/$/, ''));
|
|
83
|
+
}
|
|
84
|
+
parts.push(file.name || 'unknown');
|
|
85
|
+
const filename = parts.join('/');
|
|
86
|
+
const targetUrl = `${config.apiUrl}/files/${isUnauthenticated ? 'unauthenticated-sign-upload' : 'sign-upload'}`;
|
|
87
|
+
const body = {
|
|
88
|
+
filename,
|
|
89
|
+
contentType: file.type,
|
|
90
|
+
realm,
|
|
91
|
+
publicAcl,
|
|
92
|
+
isUnauthenticated,
|
|
93
|
+
};
|
|
94
|
+
const response = await enhancedFetch(targetUrl, {
|
|
95
|
+
method: 'POST',
|
|
96
|
+
body: JSON.stringify(body),
|
|
97
|
+
});
|
|
98
|
+
if (response.err) {
|
|
99
|
+
toastResult(response, {
|
|
100
|
+
error: {
|
|
101
|
+
title: 'Error while uploading file',
|
|
102
|
+
description: response.val.message,
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
throw new Error(response.val.message || 'Error while uploading file');
|
|
106
|
+
}
|
|
107
|
+
// We remove the query string from the url and store it in the uploadUrlsMap
|
|
108
|
+
// this is because uppy may not return the url in the upload success callback
|
|
109
|
+
const url = response.val.url.split('?')[0];
|
|
110
|
+
uploadUrlsMap.current.set(file.id, url);
|
|
111
|
+
return {
|
|
112
|
+
method: 'PUT',
|
|
113
|
+
url: response.val.url,
|
|
114
|
+
fields: {},
|
|
115
|
+
headers: {
|
|
116
|
+
'Content-Type': file.type,
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
},
|
|
120
|
+
}), [
|
|
319
121
|
getUploadParameters,
|
|
320
122
|
realm,
|
|
321
123
|
toastResult,
|
|
322
124
|
toastError,
|
|
323
125
|
publicAcl,
|
|
324
|
-
isUnauthenticated
|
|
126
|
+
isUnauthenticated,
|
|
325
127
|
]);
|
|
326
|
-
|
|
128
|
+
const uppyInstance = useRef(
|
|
129
|
+
// @ts-expect-error options partial
|
|
327
130
|
initUppy(uppyOptions, s3PluginOptions));
|
|
328
|
-
|
|
131
|
+
const uppy = uppyInstance.current;
|
|
329
132
|
// biome-ignore lint/correctness/useExhaustiveDependencies: <explanation>
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
var oldUploadUrl = uploadUrlsMap.current.get(file.id);
|
|
337
|
-
if (oldUploadUrl) {
|
|
338
|
-
newMap.set(file.id, oldUploadUrl);
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
} catch (err) {
|
|
342
|
-
_didIteratorError = true;
|
|
343
|
-
_iteratorError = err;
|
|
344
|
-
} finally{
|
|
345
|
-
try {
|
|
346
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
347
|
-
_iterator.return();
|
|
348
|
-
}
|
|
349
|
-
} finally{
|
|
350
|
-
if (_didIteratorError) {
|
|
351
|
-
throw _iteratorError;
|
|
352
|
-
}
|
|
133
|
+
const resyncMap = useCallback(() => {
|
|
134
|
+
const newMap = new Map();
|
|
135
|
+
for (const file of uppy.getFiles()) {
|
|
136
|
+
const oldUploadUrl = uploadUrlsMap.current.get(file.id);
|
|
137
|
+
if (oldUploadUrl) {
|
|
138
|
+
newMap.set(file.id, oldUploadUrl);
|
|
353
139
|
}
|
|
354
140
|
}
|
|
355
141
|
// Resync the map
|
|
356
142
|
uploadUrlsMap.current = newMap;
|
|
357
143
|
}, []);
|
|
358
144
|
// biome-ignore lint/correctness/useExhaustiveDependencies: <explanation>
|
|
359
|
-
useEffect(
|
|
360
|
-
var _uppy_getPlugin;
|
|
145
|
+
useEffect(() => {
|
|
361
146
|
uppy.setOptions(uppyOptions);
|
|
362
|
-
|
|
363
|
-
}, [
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
]);
|
|
367
|
-
useEffect(function() {
|
|
368
|
-
var handleFileAdded = function(file) {
|
|
147
|
+
uppy.getPlugin('AwsS3')?.setOptions(s3PluginOptions);
|
|
148
|
+
}, [uppyOptions, s3PluginOptions]);
|
|
149
|
+
useEffect(() => {
|
|
150
|
+
const handleFileAdded = (file) => {
|
|
369
151
|
resyncMap();
|
|
370
152
|
if (prefixFile) {
|
|
371
153
|
// @ts-expect-error
|
|
372
|
-
uppy.setMeta({
|
|
373
|
-
prefix: prefixFile(file)
|
|
374
|
-
});
|
|
154
|
+
uppy.setMeta({ prefix: prefixFile(file) });
|
|
375
155
|
}
|
|
376
156
|
};
|
|
377
157
|
uppy.on('file-added', handleFileAdded);
|
|
378
|
-
|
|
379
|
-
|
|
158
|
+
const handleUploadSuccess = (file, response) => {
|
|
159
|
+
const uploadURL = response.uploadURL ||
|
|
160
|
+
(file ? uploadUrlsMap.current.get(file.id) : undefined);
|
|
380
161
|
if (!response.uploadURL) {
|
|
381
162
|
response.uploadURL = uploadURL;
|
|
382
163
|
}
|
|
@@ -384,67 +165,51 @@ export var useUppy = function(options, isUnauthenticated) {
|
|
|
384
165
|
if (!uploadURL) {
|
|
385
166
|
toastError({
|
|
386
167
|
title: 'Error while uploading file',
|
|
387
|
-
description:
|
|
168
|
+
description: `The uploader didn\'t return a valid uploadURL for file ${file?.name}`,
|
|
388
169
|
});
|
|
389
170
|
return;
|
|
390
171
|
}
|
|
391
|
-
onUploadSuccess(file,
|
|
392
|
-
|
|
393
|
-
|
|
172
|
+
onUploadSuccess(file, {
|
|
173
|
+
...response,
|
|
174
|
+
uploadURL,
|
|
175
|
+
});
|
|
394
176
|
}
|
|
395
177
|
};
|
|
396
178
|
uppy.on('upload-success', handleUploadSuccess);
|
|
397
|
-
|
|
398
|
-
|
|
179
|
+
const handleComplete = (result) => {
|
|
180
|
+
const realUploaded = [];
|
|
399
181
|
if (!result.successful) {
|
|
400
182
|
return;
|
|
401
183
|
}
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
if (!uploadURL) {
|
|
410
|
-
toastError({
|
|
411
|
-
title: 'Error while uploading file',
|
|
412
|
-
description: "The uploader didn't return a valid uploadURL for file ".concat(uploaded.name)
|
|
413
|
-
});
|
|
414
|
-
continue;
|
|
415
|
-
}
|
|
416
|
-
uploaded.response = _object_spread_props(_object_spread({}, uploaded.response), {
|
|
417
|
-
uploadURL: uploadURL
|
|
184
|
+
// Populate upload URL if any
|
|
185
|
+
for (const uploaded of result.successful) {
|
|
186
|
+
const uploadURL = uploaded.response?.uploadURL || uploadUrlsMap.current.get(uploaded.id);
|
|
187
|
+
if (!uploadURL) {
|
|
188
|
+
toastError({
|
|
189
|
+
title: 'Error while uploading file',
|
|
190
|
+
description: `The uploader didn\'t return a valid uploadURL for file ${uploaded.name}`,
|
|
418
191
|
});
|
|
419
|
-
|
|
420
|
-
realUploaded.push(uploaded);
|
|
421
|
-
}
|
|
422
|
-
} catch (err) {
|
|
423
|
-
_didIteratorError = true;
|
|
424
|
-
_iteratorError = err;
|
|
425
|
-
} finally{
|
|
426
|
-
try {
|
|
427
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
428
|
-
_iterator.return();
|
|
429
|
-
}
|
|
430
|
-
} finally{
|
|
431
|
-
if (_didIteratorError) {
|
|
432
|
-
throw _iteratorError;
|
|
433
|
-
}
|
|
192
|
+
continue;
|
|
434
193
|
}
|
|
194
|
+
uploaded.response = {
|
|
195
|
+
...uploaded.response,
|
|
196
|
+
uploadURL,
|
|
197
|
+
};
|
|
198
|
+
uploaded.uploadURL = uploadURL;
|
|
199
|
+
realUploaded.push(uploaded);
|
|
435
200
|
}
|
|
436
201
|
if (onComplete) {
|
|
437
202
|
onComplete(realUploaded);
|
|
438
203
|
}
|
|
439
204
|
};
|
|
440
205
|
uppy.on('complete', handleComplete);
|
|
441
|
-
|
|
206
|
+
const handleError = (file, error, response) => {
|
|
442
207
|
if (onError) {
|
|
443
208
|
onError(file, error, response);
|
|
444
209
|
}
|
|
445
210
|
};
|
|
446
211
|
uppy.on('upload-error', handleError);
|
|
447
|
-
return
|
|
212
|
+
return () => {
|
|
448
213
|
uppy.off('file-added', handleFileAdded);
|
|
449
214
|
uppy.off('upload-success', handleUploadSuccess);
|
|
450
215
|
uppy.off('complete', handleComplete);
|
|
@@ -457,7 +222,8 @@ export var useUppy = function(options, isUnauthenticated) {
|
|
|
457
222
|
onUploadSuccess,
|
|
458
223
|
resyncMap,
|
|
459
224
|
prefixFile,
|
|
460
|
-
toastError
|
|
225
|
+
toastError,
|
|
461
226
|
]);
|
|
462
227
|
return uppy;
|
|
463
228
|
};
|
|
229
|
+
//# sourceMappingURL=uppy.js.map
|