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