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