@driveflux/upload 1.4.4 → 1.4.6
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.d.ts.map +1 -1
- package/dist/uppy.js +373 -139
- package/package.json +3 -3
package/dist/uppy.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uppy.d.ts","sourceRoot":"","sources":["../src/uppy.ts"],"names":[],"mappings":"AAGA,OAAuB,EAEtB,KAAK,qBAAqB,EAC1B,MAAM,cAAc,CAAA;AACrB,OAAO,IAAI,EAAE,EACZ,KAAK,YAAY,EACjB,KAAK,QAAQ,EAEb,MAAM,YAAY,CAAA;AACnB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAI7D,KAAK,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IAC5C,MAAM,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AACD,KAAK,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IAC5C,QAAQ,EAAE,MAAM,CAAA;CAChB,CAAA;AACD,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAA;AACnD,MAAM,WAAW,eAAe,CAC/B,KAAK,SAAS,WAAW,GAAG,WAAW,EACvC,KAAK,SAAS,WAAW,GAAG,WAAW;IAEvC,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,YAAY,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,CAAA;IACpC,mBAAmB,CAAC,EAAE,CACrB,IAAI,EAAE,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,KACxB,OAAO,CAAC,qBAAqB,CAAC,CAAA;IACnC;;OAEG;IACH,eAAe,CAAC,EAAE,YAAY,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,gBAAgB,CAAC,CAAA;IAC9D;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,MAAM,CAAA;IACrD;;OAEG;IACH,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,EAAE,KAAK,IAAI,CAAA;IACzD,OAAO,CAAC,EAAE,YAAY,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC,cAAc,CAAC,CAAA;IAChE,KAAK,EAAE,WAAW,CAAA;IAClB;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;CACnB;AAgCD,eAAO,MAAM,OAAO,GACnB,KAAK,SAAS,WAAW,
|
|
1
|
+
{"version":3,"file":"uppy.d.ts","sourceRoot":"","sources":["../src/uppy.ts"],"names":[],"mappings":"AAGA,OAAuB,EAEtB,KAAK,qBAAqB,EAC1B,MAAM,cAAc,CAAA;AACrB,OAAO,IAAI,EAAE,EACZ,KAAK,YAAY,EACjB,KAAK,QAAQ,EAEb,MAAM,YAAY,CAAA;AACnB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAI7D,KAAK,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IAC5C,MAAM,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AACD,KAAK,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IAC5C,QAAQ,EAAE,MAAM,CAAA;CAChB,CAAA;AACD,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAA;AACnD,MAAM,WAAW,eAAe,CAC/B,KAAK,SAAS,WAAW,GAAG,WAAW,EACvC,KAAK,SAAS,WAAW,GAAG,WAAW;IAEvC,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,YAAY,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,CAAA;IACpC,mBAAmB,CAAC,EAAE,CACrB,IAAI,EAAE,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,KACxB,OAAO,CAAC,qBAAqB,CAAC,CAAA;IACnC;;OAEG;IACH,eAAe,CAAC,EAAE,YAAY,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,gBAAgB,CAAC,CAAA;IAC9D;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,MAAM,CAAA;IACrD;;OAEG;IACH,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,EAAE,KAAK,IAAI,CAAA;IACzD,OAAO,CAAC,EAAE,YAAY,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC,cAAc,CAAC,CAAA;IAChE,KAAK,EAAE,WAAW,CAAA;IAClB;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;CACnB;AAgCD,eAAO,MAAM,OAAO,GACnB,KAAK,SAAS,WAAW,GAAG,WAAW,EACvC,KAAK,SAAS,WAAW,GAAG,WAAW,EAEvC,SAAS,eAAe,CAAC,KAAK,EAAE,KAAK,CAAC,EACtC,oBAAoB,OAAO,uBAkQ3B,CAAA"}
|
package/dist/uppy.js
CHANGED
|
@@ -1,3 +1,179 @@
|
|
|
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
|
+
}
|
|
1
177
|
import { config } from '@driveflux/config/frontend';
|
|
2
178
|
import { enhancedFetch } from '@driveflux/fetch';
|
|
3
179
|
import { useToastResult } from '@driveflux/ui/toast';
|
|
@@ -5,159 +181,202 @@ import AwsS3Multipart from '@uppy/aws-s3';
|
|
|
5
181
|
import Uppy from '@uppy/core';
|
|
6
182
|
import isEqual from 'lodash/isEqual.js';
|
|
7
183
|
import { useCallback, useEffect, useMemo, useRef } from 'react';
|
|
8
|
-
|
|
184
|
+
var defaultOptions = {
|
|
9
185
|
autoProceed: true,
|
|
10
186
|
restrictions: {
|
|
11
|
-
maxFileSize: 10000000,
|
|
12
|
-
maxTotalFileSize: 100000000,
|
|
187
|
+
maxFileSize: 10000000,
|
|
188
|
+
maxTotalFileSize: 100000000,
|
|
13
189
|
maxNumberOfFiles: 20,
|
|
14
|
-
allowedFileTypes: [
|
|
190
|
+
allowedFileTypes: [
|
|
191
|
+
'image/*',
|
|
192
|
+
'application/pdf'
|
|
193
|
+
],
|
|
15
194
|
minFileSize: 1000,
|
|
16
195
|
minNumberOfFiles: 1,
|
|
17
|
-
requiredMetaFields: []
|
|
196
|
+
requiredMetaFields: []
|
|
18
197
|
},
|
|
19
|
-
getUploadParameters: null,
|
|
20
|
-
realm: null
|
|
198
|
+
getUploadParameters: null,
|
|
199
|
+
realm: null
|
|
21
200
|
};
|
|
22
|
-
|
|
23
|
-
|
|
201
|
+
var initUppy = function(uppyOptions, s3PluginOptions) {
|
|
202
|
+
var uppy = new Uppy(uppyOptions);
|
|
24
203
|
// @ts-expect-error
|
|
25
204
|
uppy.use(AwsS3Multipart, s3PluginOptions);
|
|
26
205
|
return uppy;
|
|
27
206
|
};
|
|
28
|
-
export
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
...defaultOptions,
|
|
37
|
-
...options,
|
|
38
|
-
restrictions: {
|
|
39
|
-
...defaultOptions.restrictions,
|
|
40
|
-
...options.restrictions,
|
|
41
|
-
},
|
|
42
|
-
};
|
|
207
|
+
export var useUppy = function(options, isUnauthenticated) {
|
|
208
|
+
var previousOptions = useRef(_object_spread_props(_object_spread({}, defaultOptions, options), {
|
|
209
|
+
restrictions: defaultOptions.restrictions
|
|
210
|
+
}));
|
|
211
|
+
var finalOptions = useMemo(function() {
|
|
212
|
+
var newOptions = _object_spread_props(_object_spread({}, defaultOptions, options), {
|
|
213
|
+
restrictions: _object_spread({}, defaultOptions.restrictions, options.restrictions)
|
|
214
|
+
});
|
|
43
215
|
if (isEqual(newOptions, previousOptions.current)) {
|
|
44
216
|
return previousOptions.current;
|
|
45
217
|
}
|
|
46
218
|
previousOptions.current = newOptions;
|
|
47
219
|
return newOptions;
|
|
48
|
-
}, [
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
220
|
+
}, [
|
|
221
|
+
options
|
|
222
|
+
]);
|
|
223
|
+
var _finalOptions_autoProceed = finalOptions.autoProceed, autoProceed = _finalOptions_autoProceed === void 0 ? true : _finalOptions_autoProceed, restrictions = finalOptions.restrictions, getUploadParameters = finalOptions.getUploadParameters, onUploadSuccess = finalOptions.onUploadSuccess, onComplete = finalOptions.onComplete, prefixFile = finalOptions.prefixFile, onError = finalOptions.onError, realm = finalOptions.realm;
|
|
224
|
+
var uploadUrlsMap = useRef(new Map());
|
|
225
|
+
var publicAcl = typeof options.publicAcl === 'boolean' ? options.publicAcl : realm === 'site';
|
|
226
|
+
var _useToastResult = useToastResult(), toastResult = _useToastResult.toastResult, toastError = _useToastResult.toastError;
|
|
227
|
+
var uppyOptions = useMemo(function() {
|
|
228
|
+
return {
|
|
229
|
+
autoProceed: autoProceed,
|
|
230
|
+
restrictions: restrictions
|
|
231
|
+
};
|
|
232
|
+
}, [
|
|
56
233
|
autoProceed,
|
|
57
|
-
restrictions
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
return
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
234
|
+
restrictions
|
|
235
|
+
]);
|
|
236
|
+
var s3PluginOptions = useMemo(function() {
|
|
237
|
+
return {
|
|
238
|
+
id: 'AwsS3',
|
|
239
|
+
getUploadParameters: function getUploadParameters1(file) {
|
|
240
|
+
return _async_to_generator(function() {
|
|
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
|
+
})();
|
|
106
316
|
}
|
|
107
|
-
|
|
108
|
-
|
|
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
|
-
}), [
|
|
317
|
+
};
|
|
318
|
+
}, [
|
|
121
319
|
getUploadParameters,
|
|
122
320
|
realm,
|
|
123
321
|
toastResult,
|
|
124
322
|
toastError,
|
|
125
323
|
publicAcl,
|
|
126
|
-
isUnauthenticated
|
|
324
|
+
isUnauthenticated
|
|
127
325
|
]);
|
|
128
|
-
|
|
129
|
-
// @ts-expect-error options partial
|
|
326
|
+
var uppyInstance = useRef(// @ts-expect-error options partial
|
|
130
327
|
initUppy(uppyOptions, s3PluginOptions));
|
|
131
|
-
|
|
328
|
+
var uppy = uppyInstance.current;
|
|
132
329
|
// biome-ignore lint/correctness/useExhaustiveDependencies: <explanation>
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
330
|
+
var resyncMap = useCallback(function() {
|
|
331
|
+
var newMap = new Map();
|
|
332
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
333
|
+
try {
|
|
334
|
+
for(var _iterator = uppy.getFiles()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
335
|
+
var file = _step.value;
|
|
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
|
+
}
|
|
139
353
|
}
|
|
140
354
|
}
|
|
141
355
|
// Resync the map
|
|
142
356
|
uploadUrlsMap.current = newMap;
|
|
143
357
|
}, []);
|
|
144
358
|
// biome-ignore lint/correctness/useExhaustiveDependencies: <explanation>
|
|
145
|
-
useEffect(()
|
|
359
|
+
useEffect(function() {
|
|
360
|
+
var _uppy_getPlugin;
|
|
146
361
|
uppy.setOptions(uppyOptions);
|
|
147
|
-
uppy.getPlugin('AwsS3')
|
|
148
|
-
}, [
|
|
149
|
-
|
|
150
|
-
|
|
362
|
+
(_uppy_getPlugin = uppy.getPlugin('AwsS3')) === null || _uppy_getPlugin === void 0 ? void 0 : _uppy_getPlugin.setOptions(s3PluginOptions);
|
|
363
|
+
}, [
|
|
364
|
+
uppyOptions,
|
|
365
|
+
s3PluginOptions
|
|
366
|
+
]);
|
|
367
|
+
useEffect(function() {
|
|
368
|
+
var handleFileAdded = function(file) {
|
|
151
369
|
resyncMap();
|
|
152
370
|
if (prefixFile) {
|
|
153
371
|
// @ts-expect-error
|
|
154
|
-
uppy.setMeta({
|
|
372
|
+
uppy.setMeta({
|
|
373
|
+
prefix: prefixFile(file)
|
|
374
|
+
});
|
|
155
375
|
}
|
|
156
376
|
};
|
|
157
377
|
uppy.on('file-added', handleFileAdded);
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
(file ? uploadUrlsMap.current.get(file.id) : undefined);
|
|
378
|
+
var handleUploadSuccess = function(file, response) {
|
|
379
|
+
var uploadURL = response.uploadURL || (file ? uploadUrlsMap.current.get(file.id) : undefined);
|
|
161
380
|
if (!response.uploadURL) {
|
|
162
381
|
response.uploadURL = uploadURL;
|
|
163
382
|
}
|
|
@@ -165,51 +384,67 @@ export const useUppy = (options, isUnauthenticated) => {
|
|
|
165
384
|
if (!uploadURL) {
|
|
166
385
|
toastError({
|
|
167
386
|
title: 'Error while uploading file',
|
|
168
|
-
description:
|
|
387
|
+
description: "The uploader didn't return a valid uploadURL for file ".concat(file === null || file === void 0 ? void 0 : file.name)
|
|
169
388
|
});
|
|
170
389
|
return;
|
|
171
390
|
}
|
|
172
|
-
onUploadSuccess(file, {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
});
|
|
391
|
+
onUploadSuccess(file, _object_spread_props(_object_spread({}, response), {
|
|
392
|
+
uploadURL: uploadURL
|
|
393
|
+
}));
|
|
176
394
|
}
|
|
177
395
|
};
|
|
178
396
|
uppy.on('upload-success', handleUploadSuccess);
|
|
179
|
-
|
|
180
|
-
|
|
397
|
+
var handleComplete = function(result) {
|
|
398
|
+
var realUploaded = [];
|
|
181
399
|
if (!result.successful) {
|
|
182
400
|
return;
|
|
183
401
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
402
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
403
|
+
try {
|
|
404
|
+
// Populate upload URL if any
|
|
405
|
+
for(var _iterator = result.successful[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
406
|
+
var uploaded = _step.value;
|
|
407
|
+
var _uploaded_response;
|
|
408
|
+
var uploadURL = ((_uploaded_response = uploaded.response) === null || _uploaded_response === void 0 ? void 0 : _uploaded_response.uploadURL) || uploadUrlsMap.current.get(uploaded.id);
|
|
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
|
|
191
418
|
});
|
|
192
|
-
|
|
419
|
+
uploaded.uploadURL = uploadURL;
|
|
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
|
+
}
|
|
193
434
|
}
|
|
194
|
-
uploaded.response = {
|
|
195
|
-
...uploaded.response,
|
|
196
|
-
uploadURL,
|
|
197
|
-
};
|
|
198
|
-
uploaded.uploadURL = uploadURL;
|
|
199
|
-
realUploaded.push(uploaded);
|
|
200
435
|
}
|
|
201
436
|
if (onComplete) {
|
|
202
437
|
onComplete(realUploaded);
|
|
203
438
|
}
|
|
204
439
|
};
|
|
205
440
|
uppy.on('complete', handleComplete);
|
|
206
|
-
|
|
441
|
+
var handleError = function(file, error, response) {
|
|
207
442
|
if (onError) {
|
|
208
443
|
onError(file, error, response);
|
|
209
444
|
}
|
|
210
445
|
};
|
|
211
446
|
uppy.on('upload-error', handleError);
|
|
212
|
-
return ()
|
|
447
|
+
return function() {
|
|
213
448
|
uppy.off('file-added', handleFileAdded);
|
|
214
449
|
uppy.off('upload-success', handleUploadSuccess);
|
|
215
450
|
uppy.off('complete', handleComplete);
|
|
@@ -222,8 +457,7 @@ export const useUppy = (options, isUnauthenticated) => {
|
|
|
222
457
|
onUploadSuccess,
|
|
223
458
|
resyncMap,
|
|
224
459
|
prefixFile,
|
|
225
|
-
toastError
|
|
460
|
+
toastError
|
|
226
461
|
]);
|
|
227
462
|
return uppy;
|
|
228
463
|
};
|
|
229
|
-
//# sourceMappingURL=uppy.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@driveflux/upload",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
"dist"
|
|
13
13
|
],
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@driveflux/config": "1.8.
|
|
15
|
+
"@driveflux/config": "1.8.2",
|
|
16
16
|
"@driveflux/fetch": "6.4.0",
|
|
17
|
-
"@driveflux/ui": "1.4.
|
|
17
|
+
"@driveflux/ui": "1.4.1",
|
|
18
18
|
"@uppy/aws-s3": "4.1.0",
|
|
19
19
|
"@uppy/core": "4.2.2",
|
|
20
20
|
"lodash": "^4.17.21"
|