@tradly/asset 1.0.19 → 1.0.21
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/core/MediaApiService.js +162 -154
- package/dist/esm/core/MediaApiService.js +162 -154
- package/dist/esm/native/FileUpload.native.js +49 -19
- package/dist/esm/native/Icons.native.js +44 -8
- package/dist/esm/native/ImagesSkeleton.native.js +18 -11
- package/dist/esm/native/MediaGallery.native.js +30 -23
- package/dist/esm/native/MediaPopup.native.js +3 -1
- package/dist/esm/native/MediaTab.native.js +4 -0
- package/dist/esm/native/VideosGallery.native.js +14 -6
- package/dist/native/FileUpload.native.js +49 -20
- package/dist/native/Icons.native.js +43 -7
- package/dist/native/ImagesSkeleton.native.js +16 -9
- package/dist/native/MediaGallery.native.js +24 -18
- package/dist/native/MediaPopup.native.js +3 -1
- package/dist/native/MediaTab.native.js +4 -0
- package/dist/native/VideosGallery.native.js +15 -7
- package/package.json +1 -1
|
@@ -158,26 +158,123 @@ var MediaApiService = /*#__PURE__*/function () {
|
|
|
158
158
|
return fetchMedia;
|
|
159
159
|
}()
|
|
160
160
|
/**
|
|
161
|
-
*
|
|
161
|
+
* Upload a single file to S3 using signed URL
|
|
162
|
+
* Handles both web File objects and React Native file URIs
|
|
162
163
|
*/
|
|
163
164
|
)
|
|
164
165
|
}, {
|
|
165
|
-
key: "
|
|
166
|
+
key: "uploadFileToS3",
|
|
166
167
|
value: (function () {
|
|
167
|
-
var
|
|
168
|
-
var
|
|
168
|
+
var _uploadFileToS = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(signedUrl, fileUriOrFile, mimeType) {
|
|
169
|
+
var blob, response, _response, uploadResponse, errorText, _t2;
|
|
169
170
|
return _regenerator().w(function (_context3) {
|
|
170
171
|
while (1) switch (_context3.p = _context3.n) {
|
|
172
|
+
case 0:
|
|
173
|
+
_context3.p = 0;
|
|
174
|
+
if (!(typeof fileUriOrFile === "string")) {
|
|
175
|
+
_context3.n = 4;
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
178
|
+
_context3.n = 1;
|
|
179
|
+
return fetch(fileUriOrFile);
|
|
180
|
+
case 1:
|
|
181
|
+
response = _context3.v;
|
|
182
|
+
if (response.ok) {
|
|
183
|
+
_context3.n = 2;
|
|
184
|
+
break;
|
|
185
|
+
}
|
|
186
|
+
throw new Error("Failed to fetch file: ".concat(response.status, " ").concat(response.statusText));
|
|
187
|
+
case 2:
|
|
188
|
+
_context3.n = 3;
|
|
189
|
+
return response.blob();
|
|
190
|
+
case 3:
|
|
191
|
+
blob = _context3.v;
|
|
192
|
+
_context3.n = 9;
|
|
193
|
+
break;
|
|
194
|
+
case 4:
|
|
195
|
+
if (!(fileUriOrFile && fileUriOrFile.uri)) {
|
|
196
|
+
_context3.n = 8;
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
_context3.n = 5;
|
|
200
|
+
return fetch(fileUriOrFile.uri);
|
|
201
|
+
case 5:
|
|
202
|
+
_response = _context3.v;
|
|
203
|
+
if (_response.ok) {
|
|
204
|
+
_context3.n = 6;
|
|
205
|
+
break;
|
|
206
|
+
}
|
|
207
|
+
throw new Error("Failed to fetch file: ".concat(_response.status, " ").concat(_response.statusText));
|
|
208
|
+
case 6:
|
|
209
|
+
_context3.n = 7;
|
|
210
|
+
return _response.blob();
|
|
211
|
+
case 7:
|
|
212
|
+
blob = _context3.v;
|
|
213
|
+
_context3.n = 9;
|
|
214
|
+
break;
|
|
215
|
+
case 8:
|
|
216
|
+
// Web: fileUriOrFile is already a File/Blob object
|
|
217
|
+
blob = fileUriOrFile;
|
|
218
|
+
case 9:
|
|
219
|
+
_context3.n = 10;
|
|
220
|
+
return fetch(signedUrl, {
|
|
221
|
+
method: "PUT",
|
|
222
|
+
body: blob,
|
|
223
|
+
headers: {
|
|
224
|
+
"Content-Type": mimeType
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
case 10:
|
|
228
|
+
uploadResponse = _context3.v;
|
|
229
|
+
if (uploadResponse.ok) {
|
|
230
|
+
_context3.n = 12;
|
|
231
|
+
break;
|
|
232
|
+
}
|
|
233
|
+
_context3.n = 11;
|
|
234
|
+
return uploadResponse.text().catch(function () {
|
|
235
|
+
return "";
|
|
236
|
+
});
|
|
237
|
+
case 11:
|
|
238
|
+
errorText = _context3.v;
|
|
239
|
+
throw new Error("S3 upload failed: ".concat(uploadResponse.status, " ").concat(uploadResponse.statusText).concat(errorText ? " - ".concat(errorText) : ""));
|
|
240
|
+
case 12:
|
|
241
|
+
_context3.n = 14;
|
|
242
|
+
break;
|
|
243
|
+
case 13:
|
|
244
|
+
_context3.p = 13;
|
|
245
|
+
_t2 = _context3.v;
|
|
246
|
+
throw new Error(_t2.message || "Failed to upload file to S3");
|
|
247
|
+
case 14:
|
|
248
|
+
return _context3.a(2);
|
|
249
|
+
}
|
|
250
|
+
}, _callee3, null, [[0, 13]]);
|
|
251
|
+
}));
|
|
252
|
+
function uploadFileToS3(_x3, _x4, _x5) {
|
|
253
|
+
return _uploadFileToS.apply(this, arguments);
|
|
254
|
+
}
|
|
255
|
+
return uploadFileToS3;
|
|
256
|
+
}()
|
|
257
|
+
/**
|
|
258
|
+
* Get S3 signed upload URLs from API
|
|
259
|
+
*/
|
|
260
|
+
)
|
|
261
|
+
}, {
|
|
262
|
+
key: "getS3SignedUrls",
|
|
263
|
+
value: (function () {
|
|
264
|
+
var _getS3SignedUrls = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(files, authKey) {
|
|
265
|
+
var auth_key, fileData, headers, _response$data$data, response, _t3;
|
|
266
|
+
return _regenerator().w(function (_context4) {
|
|
267
|
+
while (1) switch (_context4.p = _context4.n) {
|
|
171
268
|
case 0:
|
|
172
269
|
auth_key = authKey || this.authKey;
|
|
173
270
|
if (auth_key) {
|
|
174
|
-
|
|
271
|
+
_context4.n = 1;
|
|
175
272
|
break;
|
|
176
273
|
}
|
|
177
274
|
throw new Error("Authentication key is required for upload");
|
|
178
275
|
case 1:
|
|
179
276
|
if (this.apiBaseUrl) {
|
|
180
|
-
|
|
277
|
+
_context4.n = 2;
|
|
181
278
|
break;
|
|
182
279
|
}
|
|
183
280
|
throw new Error('API base URL is required. The package automatically detects it from ENVIRONMENT, or you can set apiBaseUrl in config: new MediaApiService({ apiBaseUrl: "https://api.tradly.app" })');
|
|
@@ -197,8 +294,8 @@ var MediaApiService = /*#__PURE__*/function () {
|
|
|
197
294
|
if (this.bearerToken) {
|
|
198
295
|
headers["Authorization"] = "Bearer ".concat(this.bearerToken);
|
|
199
296
|
}
|
|
200
|
-
|
|
201
|
-
|
|
297
|
+
_context4.p = 3;
|
|
298
|
+
_context4.n = 4;
|
|
202
299
|
return axios({
|
|
203
300
|
method: "POST",
|
|
204
301
|
url: "".concat(this.apiBaseUrl, "/v1/utils/S3signedUploadURL"),
|
|
@@ -208,28 +305,28 @@ var MediaApiService = /*#__PURE__*/function () {
|
|
|
208
305
|
}
|
|
209
306
|
});
|
|
210
307
|
case 4:
|
|
211
|
-
response =
|
|
308
|
+
response = _context4.v;
|
|
212
309
|
if (!response.data.error) {
|
|
213
|
-
|
|
310
|
+
_context4.n = 5;
|
|
214
311
|
break;
|
|
215
312
|
}
|
|
216
313
|
throw new Error(response.data.error);
|
|
217
314
|
case 5:
|
|
218
|
-
return
|
|
315
|
+
return _context4.a(2, response.data.result || ((_response$data$data = response.data.data) === null || _response$data$data === void 0 ? void 0 : _response$data$data.result) || response.data);
|
|
219
316
|
case 6:
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
console.error("Error getting S3 signed URLs:",
|
|
317
|
+
_context4.p = 6;
|
|
318
|
+
_t3 = _context4.v;
|
|
319
|
+
console.error("Error getting S3 signed URLs:", _t3);
|
|
223
320
|
if (this.onError) {
|
|
224
|
-
this.onError(
|
|
321
|
+
this.onError(_t3);
|
|
225
322
|
}
|
|
226
|
-
throw
|
|
323
|
+
throw _t3;
|
|
227
324
|
case 7:
|
|
228
|
-
return
|
|
325
|
+
return _context4.a(2);
|
|
229
326
|
}
|
|
230
|
-
},
|
|
327
|
+
}, _callee4, this, [[3, 6]]);
|
|
231
328
|
}));
|
|
232
|
-
function getS3SignedUrls(
|
|
329
|
+
function getS3SignedUrls(_x6, _x7) {
|
|
233
330
|
return _getS3SignedUrls.apply(this, arguments);
|
|
234
331
|
}
|
|
235
332
|
return getS3SignedUrls;
|
|
@@ -242,14 +339,14 @@ var MediaApiService = /*#__PURE__*/function () {
|
|
|
242
339
|
}, {
|
|
243
340
|
key: "uploadMedia",
|
|
244
341
|
value: (function () {
|
|
245
|
-
var _uploadMedia = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
246
|
-
var auth_key, all_files_uri, upload_files, upload_full_files, i, element, file_data, responseFiles, index, path, fileURI, originalFile,
|
|
247
|
-
return _regenerator().w(function (
|
|
248
|
-
while (1) switch (
|
|
342
|
+
var _uploadMedia = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(files, authKey) {
|
|
343
|
+
var auth_key, all_files_uri, upload_files, upload_full_files, i, element, cleanFileName, file_data, responseFiles, index, path, fileURI, originalFile, mimeType, fileInput, mediaData, _t4, _t5;
|
|
344
|
+
return _regenerator().w(function (_context5) {
|
|
345
|
+
while (1) switch (_context5.p = _context5.n) {
|
|
249
346
|
case 0:
|
|
250
347
|
auth_key = authKey || this.authKey;
|
|
251
348
|
if (auth_key) {
|
|
252
|
-
|
|
349
|
+
_context5.n = 1;
|
|
253
350
|
break;
|
|
254
351
|
}
|
|
255
352
|
throw new Error("Authentication key is required for upload");
|
|
@@ -260,7 +357,7 @@ var MediaApiService = /*#__PURE__*/function () {
|
|
|
260
357
|
i = 0;
|
|
261
358
|
case 2:
|
|
262
359
|
if (!(i < files.length)) {
|
|
263
|
-
|
|
360
|
+
_context5.n = 14;
|
|
264
361
|
break;
|
|
265
362
|
}
|
|
266
363
|
element = files[i]; // Check if file already has a path (from previous upload)
|
|
@@ -268,9 +365,11 @@ var MediaApiService = /*#__PURE__*/function () {
|
|
|
268
365
|
all_files_uri.push(element.path);
|
|
269
366
|
} else {
|
|
270
367
|
// Prepare file data for upload
|
|
368
|
+
// Clean file name: remove spaces (following user's pattern: fileName.replace(/ /g, ""))
|
|
369
|
+
cleanFileName = element.name.replace(/\s/g, "");
|
|
271
370
|
file_data = {
|
|
272
|
-
name:
|
|
273
|
-
type: element.type
|
|
371
|
+
name: cleanFileName,
|
|
372
|
+
type: element.type || "image/jpeg" // Default MIME type
|
|
274
373
|
};
|
|
275
374
|
upload_files.push(file_data);
|
|
276
375
|
upload_full_files.push(element);
|
|
@@ -278,138 +377,47 @@ var MediaApiService = /*#__PURE__*/function () {
|
|
|
278
377
|
|
|
279
378
|
// Upload files when we've processed all files
|
|
280
379
|
if (!(files.length === i + 1 && upload_files.length > 0)) {
|
|
281
|
-
|
|
380
|
+
_context5.n = 13;
|
|
282
381
|
break;
|
|
283
382
|
}
|
|
284
|
-
|
|
285
|
-
|
|
383
|
+
_context5.p = 3;
|
|
384
|
+
_context5.n = 4;
|
|
286
385
|
return this.getS3SignedUrls(upload_full_files, auth_key);
|
|
287
386
|
case 4:
|
|
288
|
-
responseFiles =
|
|
387
|
+
responseFiles = _context5.v;
|
|
289
388
|
index = 0;
|
|
290
389
|
case 5:
|
|
291
390
|
if (!(index < responseFiles.length)) {
|
|
292
|
-
|
|
391
|
+
_context5.n = 10;
|
|
293
392
|
break;
|
|
294
393
|
}
|
|
295
394
|
path = responseFiles[index].signedUrl;
|
|
296
395
|
fileURI = responseFiles[index].fileUri;
|
|
297
396
|
originalFile = upload_full_files[index];
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
//
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
uri = originalFile.uri;
|
|
307
|
-
_context4.p = 7;
|
|
308
|
-
// For React Native file:// URIs, fetch should work
|
|
309
|
-
// Convert file:// URI to blob for S3 upload
|
|
310
|
-
console.log("Fetching file from URI:", uri);
|
|
311
|
-
_context4.n = 8;
|
|
312
|
-
return fetch(uri);
|
|
313
|
-
case 8:
|
|
314
|
-
fileResponse = _context4.v;
|
|
315
|
-
if (fileResponse.ok) {
|
|
316
|
-
_context4.n = 9;
|
|
317
|
-
break;
|
|
318
|
-
}
|
|
319
|
-
throw new Error("Failed to fetch file: ".concat(fileResponse.status, " ").concat(fileResponse.statusText));
|
|
320
|
-
case 9:
|
|
321
|
-
if (!fileResponse.blob) {
|
|
322
|
-
_context4.n = 11;
|
|
323
|
-
break;
|
|
324
|
-
}
|
|
325
|
-
_context4.n = 10;
|
|
326
|
-
return fileResponse.blob();
|
|
327
|
-
case 10:
|
|
328
|
-
fileBody = _context4.v;
|
|
329
|
-
console.log("File converted to blob, size:", fileBody.size);
|
|
330
|
-
_context4.n = 14;
|
|
331
|
-
break;
|
|
332
|
-
case 11:
|
|
333
|
-
if (!fileResponse.arrayBuffer) {
|
|
334
|
-
_context4.n = 13;
|
|
335
|
-
break;
|
|
336
|
-
}
|
|
337
|
-
_context4.n = 12;
|
|
338
|
-
return fileResponse.arrayBuffer();
|
|
339
|
-
case 12:
|
|
340
|
-
arrayBuffer = _context4.v;
|
|
341
|
-
// Check if Blob constructor is available
|
|
342
|
-
if (typeof Blob !== "undefined") {
|
|
343
|
-
fileBody = new Blob([arrayBuffer], {
|
|
344
|
-
type: upload_files[index].type
|
|
345
|
-
});
|
|
346
|
-
} else {
|
|
347
|
-
// If Blob is not available, use arrayBuffer directly
|
|
348
|
-
fileBody = arrayBuffer;
|
|
349
|
-
}
|
|
350
|
-
_context4.n = 14;
|
|
351
|
-
break;
|
|
352
|
-
case 13:
|
|
353
|
-
// Last resort: use response directly (might not work for all cases)
|
|
354
|
-
fileBody = fileResponse;
|
|
355
|
-
case 14:
|
|
356
|
-
_context4.n = 16;
|
|
357
|
-
break;
|
|
358
|
-
case 15:
|
|
359
|
-
_context4.p = 15;
|
|
360
|
-
_t3 = _context4.v;
|
|
361
|
-
console.error("Error fetching file from URI:", _t3);
|
|
362
|
-
console.error("URI was:", uri);
|
|
363
|
-
console.error("File details:", {
|
|
364
|
-
name: originalFile.name,
|
|
365
|
-
type: originalFile.type
|
|
366
|
-
});
|
|
367
|
-
throw new Error("Failed to read file from URI: ".concat(uri, ". Error: ").concat(_t3.message, ". Make sure the file URI is accessible."));
|
|
368
|
-
case 16:
|
|
369
|
-
// Upload to S3 using PUT request
|
|
370
|
-
console.log("Uploading to S3:", path);
|
|
371
|
-
console.log("File type:", upload_files[index].type);
|
|
372
|
-
_context4.n = 17;
|
|
373
|
-
return fetch(path, {
|
|
374
|
-
method: "PUT",
|
|
375
|
-
headers: {
|
|
376
|
-
"Content-Type": upload_files[index].type
|
|
377
|
-
},
|
|
378
|
-
body: fileBody
|
|
379
|
-
});
|
|
380
|
-
case 17:
|
|
381
|
-
res = _context4.v;
|
|
382
|
-
if (!res.ok) {
|
|
383
|
-
_context4.n = 18;
|
|
384
|
-
break;
|
|
385
|
-
}
|
|
386
|
-
console.log("File ".concat(index + 1, " uploaded successfully"));
|
|
397
|
+
mimeType = upload_files[index].type;
|
|
398
|
+
_context5.p = 6;
|
|
399
|
+
// Upload file to S3 using the signed URL
|
|
400
|
+
// uploadFileToS3 handles both web File objects and React Native URIs
|
|
401
|
+
fileInput = originalFile.uri || originalFile;
|
|
402
|
+
_context5.n = 7;
|
|
403
|
+
return this.uploadFileToS3(path, fileInput, mimeType);
|
|
404
|
+
case 7:
|
|
387
405
|
all_files_uri.push(fileURI);
|
|
388
|
-
|
|
406
|
+
_context5.n = 9;
|
|
389
407
|
break;
|
|
390
|
-
case
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
return "";
|
|
394
|
-
});
|
|
395
|
-
case 19:
|
|
396
|
-
errorText = _context4.v;
|
|
397
|
-
console.error("Failed to upload file ".concat(index + 1, ":"), res.status, res.statusText, errorText);
|
|
398
|
-
throw new Error("S3 upload failed: ".concat(res.status, " ").concat(res.statusText));
|
|
399
|
-
case 20:
|
|
400
|
-
_context4.n = 22;
|
|
401
|
-
break;
|
|
402
|
-
case 21:
|
|
403
|
-
_context4.p = 21;
|
|
404
|
-
_t4 = _context4.v;
|
|
408
|
+
case 8:
|
|
409
|
+
_context5.p = 8;
|
|
410
|
+
_t4 = _context5.v;
|
|
405
411
|
console.error("Error uploading file ".concat(index + 1, ":"), _t4);
|
|
406
|
-
|
|
412
|
+
// Re-throw to stop the upload process
|
|
413
|
+
throw _t4;
|
|
414
|
+
case 9:
|
|
407
415
|
index++;
|
|
408
|
-
|
|
416
|
+
_context5.n = 5;
|
|
409
417
|
break;
|
|
410
|
-
case
|
|
418
|
+
case 10:
|
|
411
419
|
if (!(all_files_uri.length > 0)) {
|
|
412
|
-
|
|
420
|
+
_context5.n = 11;
|
|
413
421
|
break;
|
|
414
422
|
}
|
|
415
423
|
mediaData = all_files_uri.map(function (url, index) {
|
|
@@ -418,11 +426,11 @@ var MediaApiService = /*#__PURE__*/function () {
|
|
|
418
426
|
type: 1,
|
|
419
427
|
parent: 0,
|
|
420
428
|
url: url,
|
|
421
|
-
name: originalFile.name.replace(/\s/g, "
|
|
429
|
+
name: originalFile.name.replace(/\s/g, ""),
|
|
422
430
|
mime_type: originalFile.type
|
|
423
431
|
};
|
|
424
432
|
}); // Save to media API - POST /v1/media with { media: [...] }
|
|
425
|
-
|
|
433
|
+
_context5.n = 11;
|
|
426
434
|
return this.apiCall({
|
|
427
435
|
method: "POST",
|
|
428
436
|
path: "/v1/media",
|
|
@@ -430,27 +438,27 @@ var MediaApiService = /*#__PURE__*/function () {
|
|
|
430
438
|
media: mediaData
|
|
431
439
|
}
|
|
432
440
|
});
|
|
433
|
-
case
|
|
434
|
-
|
|
441
|
+
case 11:
|
|
442
|
+
_context5.n = 13;
|
|
435
443
|
break;
|
|
436
|
-
case
|
|
437
|
-
|
|
438
|
-
_t5 =
|
|
444
|
+
case 12:
|
|
445
|
+
_context5.p = 12;
|
|
446
|
+
_t5 = _context5.v;
|
|
439
447
|
console.error("Upload error:", _t5);
|
|
440
448
|
if (this.onError) {
|
|
441
449
|
this.onError(_t5);
|
|
442
450
|
}
|
|
443
451
|
throw _t5;
|
|
444
|
-
case
|
|
452
|
+
case 13:
|
|
445
453
|
i++;
|
|
446
|
-
|
|
454
|
+
_context5.n = 2;
|
|
447
455
|
break;
|
|
448
|
-
case
|
|
449
|
-
return
|
|
456
|
+
case 14:
|
|
457
|
+
return _context5.a(2, all_files_uri);
|
|
450
458
|
}
|
|
451
|
-
},
|
|
459
|
+
}, _callee5, this, [[6, 8], [3, 12]]);
|
|
452
460
|
}));
|
|
453
|
-
function uploadMedia(
|
|
461
|
+
function uploadMedia(_x8, _x9) {
|
|
454
462
|
return _uploadMedia.apply(this, arguments);
|
|
455
463
|
}
|
|
456
464
|
return uploadMedia;
|
|
@@ -2,6 +2,7 @@ function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present,
|
|
|
2
2
|
function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
|
|
3
3
|
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
|
4
4
|
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
|
|
5
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
5
6
|
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
6
7
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
7
8
|
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
@@ -80,6 +81,7 @@ var FileUpload = function FileUpload(_ref) {
|
|
|
80
81
|
picker = _ref.picker,
|
|
81
82
|
pickerOptions = _ref.pickerOptions,
|
|
82
83
|
icon = _ref.icon,
|
|
84
|
+
icons = _ref.icons,
|
|
83
85
|
_ref$theme = _ref.theme,
|
|
84
86
|
theme = _ref$theme === void 0 ? defaultTheme : _ref$theme,
|
|
85
87
|
containerStyle = _ref.containerStyle,
|
|
@@ -96,6 +98,26 @@ var FileUpload = function FileUpload(_ref) {
|
|
|
96
98
|
uploadProgress = _useState4[0],
|
|
97
99
|
setUploadProgress = _useState4[1];
|
|
98
100
|
|
|
101
|
+
// Determine which icon to use based on accept type and icons prop
|
|
102
|
+
var getIcon = function getIcon() {
|
|
103
|
+
// If icons object is provided, use it to select based on accept type
|
|
104
|
+
if (icons && _typeof(icons) === "object") {
|
|
105
|
+
var isImage = accept === null || accept === void 0 ? void 0 : accept.includes("image");
|
|
106
|
+
var isVideo = accept === null || accept === void 0 ? void 0 : accept.includes("video");
|
|
107
|
+
if (isImage && icons.image) {
|
|
108
|
+
return icons.image;
|
|
109
|
+
} else if (isVideo && icons.video) {
|
|
110
|
+
return icons.video;
|
|
111
|
+
} else if (icons.default) {
|
|
112
|
+
return icons.default;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Fallback to single icon prop (backward compatibility)
|
|
117
|
+
return icon;
|
|
118
|
+
};
|
|
119
|
+
var selectedIcon = getIcon();
|
|
120
|
+
|
|
99
121
|
// Convert file picker result to File-like object for apiService
|
|
100
122
|
var convertToFile = function convertToFile(pickerResult) {
|
|
101
123
|
// Handle different picker formats:
|
|
@@ -116,22 +138,39 @@ var FileUpload = function FileUpload(_ref) {
|
|
|
116
138
|
fileName = lastPart ? lastPart.split("?")[0] : null; // Remove query params if any
|
|
117
139
|
}
|
|
118
140
|
|
|
119
|
-
// Final fallback
|
|
141
|
+
// Final fallback - generate a meaningful filename
|
|
120
142
|
if (!fileName) {
|
|
121
143
|
// Try to guess from mimeType
|
|
122
144
|
var _mimeType = pickerResult.mimeType || pickerResult.type || "";
|
|
145
|
+
var timestamp = Date.now();
|
|
123
146
|
if (_mimeType.includes("image")) {
|
|
124
|
-
fileName = _mimeType.includes("jpeg") || _mimeType.includes("jpg") ? "
|
|
147
|
+
fileName = _mimeType.includes("jpeg") || _mimeType.includes("jpg") ? "image_".concat(timestamp, ".jpg") : _mimeType.includes("png") ? "image_".concat(timestamp, ".png") : _mimeType.includes("gif") ? "image_".concat(timestamp, ".gif") : _mimeType.includes("webp") ? "image_".concat(timestamp, ".webp") : "image_".concat(timestamp, ".jpg");
|
|
125
148
|
} else if (_mimeType.includes("video")) {
|
|
126
|
-
fileName = "
|
|
149
|
+
fileName = _mimeType.includes("mp4") ? "video_".concat(timestamp, ".mp4") : _mimeType.includes("mov") ? "video_".concat(timestamp, ".mov") : "video_".concat(timestamp, ".mp4");
|
|
127
150
|
} else {
|
|
128
|
-
fileName = "
|
|
151
|
+
fileName = "file_".concat(timestamp);
|
|
129
152
|
}
|
|
130
153
|
}
|
|
131
154
|
|
|
132
155
|
// Extract MIME type (handle different property names)
|
|
133
|
-
|
|
134
|
-
|
|
156
|
+
// Use a helper function to determine MIME type from filename if needed
|
|
157
|
+
var getMimeType = function getMimeType(name, fallbackType) {
|
|
158
|
+
var _name$split$pop;
|
|
159
|
+
if (fallbackType) return fallbackType;
|
|
160
|
+
var ext = (_name$split$pop = name.split(".").pop()) === null || _name$split$pop === void 0 ? void 0 : _name$split$pop.toLowerCase();
|
|
161
|
+
var mimeMap = {
|
|
162
|
+
jpg: "image/jpeg",
|
|
163
|
+
jpeg: "image/jpeg",
|
|
164
|
+
png: "image/png",
|
|
165
|
+
gif: "image/gif",
|
|
166
|
+
webp: "image/webp",
|
|
167
|
+
mp4: "video/mp4",
|
|
168
|
+
mov: "video/quicktime",
|
|
169
|
+
mp3: "audio/mpeg"
|
|
170
|
+
};
|
|
171
|
+
return mimeMap[ext] || "image/jpeg";
|
|
172
|
+
};
|
|
173
|
+
var mimeType = pickerResult.mimeType || pickerResult.type || getMimeType(fileName, null);
|
|
135
174
|
return {
|
|
136
175
|
uri: uri,
|
|
137
176
|
name: fileName,
|
|
@@ -153,16 +192,7 @@ var FileUpload = function FileUpload(_ref) {
|
|
|
153
192
|
setUploadProgress(0);
|
|
154
193
|
_context.p = 1;
|
|
155
194
|
// Convert picker results to File-like objects
|
|
156
|
-
filesToUpload = fileList.map(convertToFile); //
|
|
157
|
-
console.log("Files to upload:", filesToUpload.map(function (f) {
|
|
158
|
-
return {
|
|
159
|
-
uri: f.uri,
|
|
160
|
-
name: f.name,
|
|
161
|
-
type: f.type
|
|
162
|
-
};
|
|
163
|
-
}));
|
|
164
|
-
|
|
165
|
-
// Use the API service to upload files
|
|
195
|
+
filesToUpload = fileList.map(convertToFile); // Use the API service to upload files
|
|
166
196
|
// Note: uploadMedia will need to handle React Native file URIs
|
|
167
197
|
_context.n = 2;
|
|
168
198
|
return apiService.uploadMedia(filesToUpload, apiService.authKey);
|
|
@@ -297,20 +327,20 @@ var FileUpload = function FileUpload(_ref) {
|
|
|
297
327
|
borderRadius: theme.radius.md
|
|
298
328
|
}, buttonStyle],
|
|
299
329
|
disabled: isLoading,
|
|
300
|
-
children: [
|
|
330
|
+
children: [selectedIcon && /*#__PURE__*/_jsx(View, {
|
|
301
331
|
style: [styles.iconContainer, {
|
|
302
332
|
backgroundColor: theme.colors.uploadIconBackground,
|
|
303
333
|
borderRadius: theme.radius.xl,
|
|
304
334
|
marginBottom: theme.spacing.sm,
|
|
305
335
|
padding: theme.spacing.md
|
|
306
336
|
}, iconContainerStyle],
|
|
307
|
-
children:
|
|
337
|
+
children: selectedIcon
|
|
308
338
|
}), /*#__PURE__*/_jsx(Text, {
|
|
309
339
|
style: [styles.title, {
|
|
310
340
|
color: theme.colors.uploadText,
|
|
311
341
|
fontSize: theme.typography.body.fontSize,
|
|
312
342
|
fontWeight: theme.typography.body.fontWeight,
|
|
313
|
-
marginTop:
|
|
343
|
+
marginTop: selectedIcon ? theme.spacing.sm : 0
|
|
314
344
|
}, titleStyle],
|
|
315
345
|
children: title
|
|
316
346
|
})]
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import React from
|
|
2
|
-
import { View, Text, StyleSheet } from
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { View, Text, StyleSheet } from "react-native";
|
|
3
3
|
// Note: For better icons, you can use react-native-svg or react-native-vector-icons
|
|
4
4
|
// This is a simple implementation using Text/View
|
|
5
5
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
@@ -7,7 +7,7 @@ export var CloseIcon = function CloseIcon(_ref) {
|
|
|
7
7
|
var _ref$size = _ref.size,
|
|
8
8
|
size = _ref$size === void 0 ? 32 : _ref$size,
|
|
9
9
|
_ref$color = _ref.color,
|
|
10
|
-
color = _ref$color === void 0 ?
|
|
10
|
+
color = _ref$color === void 0 ? "#000000" : _ref$color;
|
|
11
11
|
return /*#__PURE__*/_jsx(View, {
|
|
12
12
|
style: [styles.closeIcon, {
|
|
13
13
|
width: size,
|
|
@@ -31,21 +31,57 @@ export var CameraIcon = function CameraIcon() {
|
|
|
31
31
|
})
|
|
32
32
|
});
|
|
33
33
|
};
|
|
34
|
+
export var VideoIcon = function VideoIcon() {
|
|
35
|
+
return /*#__PURE__*/_jsx(View, {
|
|
36
|
+
style: styles.videoIcon,
|
|
37
|
+
children: /*#__PURE__*/_jsx(Text, {
|
|
38
|
+
style: styles.videoIconText,
|
|
39
|
+
children: "\uD83C\uDFA5"
|
|
40
|
+
})
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
export var UploadIcon = function UploadIcon() {
|
|
44
|
+
return /*#__PURE__*/_jsx(View, {
|
|
45
|
+
style: styles.uploadIcon,
|
|
46
|
+
children: /*#__PURE__*/_jsx(Text, {
|
|
47
|
+
style: styles.uploadIconText,
|
|
48
|
+
children: "\uD83D\uDCE4"
|
|
49
|
+
})
|
|
50
|
+
});
|
|
51
|
+
};
|
|
34
52
|
var styles = StyleSheet.create({
|
|
35
53
|
closeIcon: {
|
|
36
|
-
justifyContent:
|
|
37
|
-
alignItems:
|
|
54
|
+
justifyContent: "center",
|
|
55
|
+
alignItems: "center"
|
|
38
56
|
},
|
|
39
57
|
closeIconText: {
|
|
40
|
-
fontWeight:
|
|
58
|
+
fontWeight: "bold"
|
|
41
59
|
},
|
|
42
60
|
cameraIcon: {
|
|
43
61
|
width: 22,
|
|
44
62
|
height: 18,
|
|
45
|
-
justifyContent:
|
|
46
|
-
alignItems:
|
|
63
|
+
justifyContent: "center",
|
|
64
|
+
alignItems: "center"
|
|
47
65
|
},
|
|
48
66
|
cameraIconText: {
|
|
49
67
|
fontSize: 18
|
|
68
|
+
},
|
|
69
|
+
videoIcon: {
|
|
70
|
+
width: 22,
|
|
71
|
+
height: 18,
|
|
72
|
+
justifyContent: "center",
|
|
73
|
+
alignItems: "center"
|
|
74
|
+
},
|
|
75
|
+
videoIconText: {
|
|
76
|
+
fontSize: 18
|
|
77
|
+
},
|
|
78
|
+
uploadIcon: {
|
|
79
|
+
width: 22,
|
|
80
|
+
height: 18,
|
|
81
|
+
justifyContent: "center",
|
|
82
|
+
alignItems: "center"
|
|
83
|
+
},
|
|
84
|
+
uploadIconText: {
|
|
85
|
+
fontSize: 18
|
|
50
86
|
}
|
|
51
87
|
});
|