@uploadcare/upload-client 6.6.1 → 6.8.0
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/cjs/index.browser.cjs +78 -60
- package/dist/cjs/index.browser.d.cts +29 -5
- package/dist/cjs/index.node.cjs +78 -60
- package/dist/cjs/index.node.d.cts +29 -5
- package/dist/cjs/index.react-native.cjs +78 -60
- package/dist/cjs/index.react-native.d.cts +29 -5
- package/dist/esm/index.browser.d.mts +29 -5
- package/dist/esm/index.browser.mjs +78 -61
- package/dist/esm/index.node.d.mts +29 -5
- package/dist/esm/index.node.mjs +78 -61
- package/dist/esm/index.react-native.d.mts +29 -5
- package/dist/esm/index.react-native.mjs +78 -61
- package/dist/index.d.ts +29 -5
- package/package.json +3 -3
|
@@ -397,7 +397,7 @@ const getUrl = (base, path, query) => {
|
|
|
397
397
|
return url.toString();
|
|
398
398
|
};
|
|
399
399
|
|
|
400
|
-
var version = '6.
|
|
400
|
+
var version = '6.8.0';
|
|
401
401
|
|
|
402
402
|
const LIBRARY_NAME = 'UploadcareUploadClient';
|
|
403
403
|
const LIBRARY_VERSION = version;
|
|
@@ -749,9 +749,9 @@ function multipartComplete(uuid, { publicKey, baseURL = defaultSettings.baseURL,
|
|
|
749
749
|
}), { retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes });
|
|
750
750
|
}
|
|
751
751
|
|
|
752
|
-
function isReadyPoll({
|
|
752
|
+
function isReadyPoll(uuid, { publicKey, baseURL, source, integration, userAgent, retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes, signal, onProgress }) {
|
|
753
753
|
return poll({
|
|
754
|
-
check: (signal) => info(
|
|
754
|
+
check: (signal) => info(uuid, {
|
|
755
755
|
publicKey,
|
|
756
756
|
baseURL,
|
|
757
757
|
signal,
|
|
@@ -771,6 +771,9 @@ function isReadyPoll({ file, publicKey, baseURL, source, integration, userAgent,
|
|
|
771
771
|
});
|
|
772
772
|
}
|
|
773
773
|
|
|
774
|
+
function isGroupFileInfo(fileInfo) {
|
|
775
|
+
return 'defaultEffects' in fileInfo;
|
|
776
|
+
}
|
|
774
777
|
class UploadcareFile {
|
|
775
778
|
uuid;
|
|
776
779
|
name = null;
|
|
@@ -786,6 +789,7 @@ class UploadcareFile {
|
|
|
786
789
|
contentInfo = null;
|
|
787
790
|
metadata = null;
|
|
788
791
|
s3Bucket = null;
|
|
792
|
+
defaultEffects = null;
|
|
789
793
|
constructor(fileInfo, { baseCDN = defaultSettings.baseCDN, fileName } = {}) {
|
|
790
794
|
const { uuid, s3Bucket } = fileInfo;
|
|
791
795
|
const cdnUrl = getUrl(baseCDN, `${uuid}/`);
|
|
@@ -806,6 +810,9 @@ class UploadcareFile {
|
|
|
806
810
|
this.metadata = fileInfo.metadata || null;
|
|
807
811
|
this.s3Bucket = s3Bucket || null;
|
|
808
812
|
this.s3Url = s3Url;
|
|
813
|
+
if (isGroupFileInfo(fileInfo)) {
|
|
814
|
+
this.defaultEffects = fileInfo.defaultEffects;
|
|
815
|
+
}
|
|
809
816
|
}
|
|
810
817
|
}
|
|
811
818
|
|
|
@@ -828,8 +835,7 @@ const uploadDirect = (file, { publicKey, fileName, baseURL, secureSignature, sec
|
|
|
828
835
|
metadata
|
|
829
836
|
})
|
|
830
837
|
.then(({ file }) => {
|
|
831
|
-
return isReadyPoll({
|
|
832
|
-
file,
|
|
838
|
+
return isReadyPoll(file, {
|
|
833
839
|
publicKey,
|
|
834
840
|
baseURL,
|
|
835
841
|
source,
|
|
@@ -1194,8 +1200,7 @@ const uploadFromUrl = (sourceUrl, { publicKey, fileName, baseURL, baseCDN, check
|
|
|
1194
1200
|
throw result;
|
|
1195
1201
|
return result;
|
|
1196
1202
|
})
|
|
1197
|
-
.then((result) => isReadyPoll({
|
|
1198
|
-
file: result.uuid,
|
|
1203
|
+
.then((result) => isReadyPoll(result.uuid, {
|
|
1199
1204
|
publicKey,
|
|
1200
1205
|
baseURL,
|
|
1201
1206
|
integration,
|
|
@@ -1370,8 +1375,7 @@ const uploadMultipart = async (file, { publicKey, fileName, fileSize, baseURL, s
|
|
|
1370
1375
|
return fileInfo;
|
|
1371
1376
|
}
|
|
1372
1377
|
else {
|
|
1373
|
-
return isReadyPoll({
|
|
1374
|
-
file: fileInfo.uuid,
|
|
1378
|
+
return isReadyPoll(fileInfo.uuid, {
|
|
1375
1379
|
publicKey,
|
|
1376
1380
|
baseURL,
|
|
1377
1381
|
source,
|
|
@@ -1483,14 +1487,16 @@ class UploadcareGroup {
|
|
|
1483
1487
|
files;
|
|
1484
1488
|
createdAt;
|
|
1485
1489
|
storedAt = null;
|
|
1486
|
-
constructor(groupInfo,
|
|
1490
|
+
constructor(groupInfo, { baseCDN = defaultSettings.baseCDN } = {}) {
|
|
1487
1491
|
this.uuid = groupInfo.id;
|
|
1488
1492
|
this.filesCount = groupInfo.filesCount;
|
|
1489
|
-
|
|
1493
|
+
const groupFiles = groupInfo.files.filter(Boolean);
|
|
1494
|
+
this.totalSize = Object.values(groupFiles).reduce((acc, file) => acc + file.size, 0);
|
|
1490
1495
|
this.isStored = !!groupInfo.datetimeStored;
|
|
1491
|
-
this.isImage = !!Object.values(
|
|
1496
|
+
this.isImage = !!Object.values(groupFiles).filter((file) => file.isImage)
|
|
1497
|
+
.length;
|
|
1492
1498
|
this.cdnUrl = groupInfo.cdnUrl;
|
|
1493
|
-
this.files =
|
|
1499
|
+
this.files = groupFiles.map((fileInfo) => new UploadcareFile(fileInfo, { baseCDN }));
|
|
1494
1500
|
this.createdAt = groupInfo.datetimeCreated;
|
|
1495
1501
|
this.storedAt = groupInfo.datetimeStored;
|
|
1496
1502
|
}
|
|
@@ -1548,27 +1554,34 @@ function uploadFileGroup(data, { publicKey, fileName, baseURL = defaultSettings.
|
|
|
1548
1554
|
onProgress({ isComputable: true, value: normalize(progressValues) });
|
|
1549
1555
|
};
|
|
1550
1556
|
};
|
|
1551
|
-
return Promise.all(data.map((file, index) =>
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1557
|
+
return Promise.all(data.map((file, index) => {
|
|
1558
|
+
if (isFileData(file) || isUrl(file)) {
|
|
1559
|
+
return uploadFile(file, {
|
|
1560
|
+
publicKey,
|
|
1561
|
+
fileName,
|
|
1562
|
+
baseURL,
|
|
1563
|
+
secureSignature,
|
|
1564
|
+
secureExpire,
|
|
1565
|
+
store,
|
|
1566
|
+
signal,
|
|
1567
|
+
onProgress: createProgressHandler(filesCount, index),
|
|
1568
|
+
source,
|
|
1569
|
+
integration,
|
|
1570
|
+
userAgent,
|
|
1571
|
+
retryThrottledRequestMaxTimes,
|
|
1572
|
+
retryNetworkErrorMaxTimes,
|
|
1573
|
+
contentType,
|
|
1574
|
+
multipartChunkSize,
|
|
1575
|
+
baseCDN,
|
|
1576
|
+
checkForUrlDuplicates,
|
|
1577
|
+
saveUrlForRecurrentUploads
|
|
1578
|
+
}).then((fileInfo) => fileInfo.uuid);
|
|
1579
|
+
}
|
|
1580
|
+
else {
|
|
1581
|
+
// Do not request file info by uuid before creating group because this isn't necessary
|
|
1582
|
+
return file;
|
|
1583
|
+
}
|
|
1584
|
+
})).then((uuids) => {
|
|
1572
1585
|
return group(uuids, {
|
|
1573
1586
|
publicKey,
|
|
1574
1587
|
baseURL,
|
|
@@ -1582,7 +1595,7 @@ function uploadFileGroup(data, { publicKey, fileName, baseURL = defaultSettings.
|
|
|
1582
1595
|
retryThrottledRequestMaxTimes,
|
|
1583
1596
|
retryNetworkErrorMaxTimes
|
|
1584
1597
|
})
|
|
1585
|
-
.then((groupInfo) => new UploadcareGroup(groupInfo,
|
|
1598
|
+
.then((groupInfo) => new UploadcareGroup(groupInfo, { baseCDN }))
|
|
1586
1599
|
.then((group) => {
|
|
1587
1600
|
onProgress && onProgress({ isComputable: true, value: 1 });
|
|
1588
1601
|
return group;
|
|
@@ -1650,35 +1663,39 @@ class UploadClient {
|
|
|
1650
1663
|
const settings = this.getSettings();
|
|
1651
1664
|
return uploadFileGroup(data, populateOptionsWithSettings(options, settings));
|
|
1652
1665
|
}
|
|
1666
|
+
isReadyPoll(uuid, options = {}) {
|
|
1667
|
+
const settings = this.getSettings();
|
|
1668
|
+
return isReadyPoll(uuid, populateOptionsWithSettings(options, settings));
|
|
1669
|
+
}
|
|
1653
1670
|
}
|
|
1654
1671
|
|
|
1655
1672
|
class Queue {
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1673
|
+
_concurrency = 1;
|
|
1674
|
+
_pending = [];
|
|
1675
|
+
_running = 0;
|
|
1676
|
+
_resolvers = new Map();
|
|
1677
|
+
_rejectors = new Map();
|
|
1661
1678
|
constructor(concurrency) {
|
|
1662
|
-
this
|
|
1679
|
+
this._concurrency = concurrency;
|
|
1663
1680
|
}
|
|
1664
|
-
|
|
1665
|
-
const tasksLeft = this
|
|
1681
|
+
_run() {
|
|
1682
|
+
const tasksLeft = this._concurrency - this._running;
|
|
1666
1683
|
for (let i = 0; i < tasksLeft; i++) {
|
|
1667
|
-
const task = this
|
|
1684
|
+
const task = this._pending.shift();
|
|
1668
1685
|
if (!task) {
|
|
1669
1686
|
return;
|
|
1670
1687
|
}
|
|
1671
|
-
const resolver = this
|
|
1672
|
-
const rejector = this
|
|
1688
|
+
const resolver = this._resolvers.get(task);
|
|
1689
|
+
const rejector = this._rejectors.get(task);
|
|
1673
1690
|
if (!resolver || !rejector)
|
|
1674
1691
|
throw new Error('Unexpected behavior: resolver or rejector is undefined');
|
|
1675
|
-
this
|
|
1692
|
+
this._running += 1;
|
|
1676
1693
|
task()
|
|
1677
1694
|
.finally(() => {
|
|
1678
|
-
this
|
|
1679
|
-
this
|
|
1680
|
-
this
|
|
1681
|
-
this
|
|
1695
|
+
this._resolvers.delete(task);
|
|
1696
|
+
this._rejectors.delete(task);
|
|
1697
|
+
this._running -= 1;
|
|
1698
|
+
this._run();
|
|
1682
1699
|
})
|
|
1683
1700
|
.then((value) => resolver(value))
|
|
1684
1701
|
.catch((error) => rejector(error));
|
|
@@ -1686,24 +1703,24 @@ class Queue {
|
|
|
1686
1703
|
}
|
|
1687
1704
|
add(task) {
|
|
1688
1705
|
return new Promise((resolve, reject) => {
|
|
1689
|
-
this
|
|
1690
|
-
this
|
|
1691
|
-
this
|
|
1692
|
-
this
|
|
1706
|
+
this._resolvers.set(task, resolve);
|
|
1707
|
+
this._rejectors.set(task, reject);
|
|
1708
|
+
this._pending.push(task);
|
|
1709
|
+
this._run();
|
|
1693
1710
|
});
|
|
1694
1711
|
}
|
|
1695
1712
|
get pending() {
|
|
1696
|
-
return this
|
|
1713
|
+
return this._pending.length;
|
|
1697
1714
|
}
|
|
1698
1715
|
get running() {
|
|
1699
|
-
return this
|
|
1716
|
+
return this._running;
|
|
1700
1717
|
}
|
|
1701
1718
|
set concurrency(value) {
|
|
1702
|
-
this
|
|
1703
|
-
this
|
|
1719
|
+
this._concurrency = value;
|
|
1720
|
+
this._run();
|
|
1704
1721
|
}
|
|
1705
1722
|
get concurrency() {
|
|
1706
|
-
return this
|
|
1723
|
+
return this._concurrency;
|
|
1707
1724
|
}
|
|
1708
1725
|
}
|
|
1709
1726
|
|
|
@@ -1720,6 +1737,7 @@ exports.getUserAgent = getUserAgent$1;
|
|
|
1720
1737
|
exports.group = group;
|
|
1721
1738
|
exports.groupInfo = groupInfo;
|
|
1722
1739
|
exports.info = info;
|
|
1740
|
+
exports.isReadyPoll = isReadyPoll;
|
|
1723
1741
|
exports.multipartComplete = multipartComplete;
|
|
1724
1742
|
exports.multipartStart = multipartStart;
|
|
1725
1743
|
exports.multipartUpload = multipartUpload;
|
|
@@ -31,7 +31,7 @@ export type ImageInfo = {
|
|
|
31
31
|
height: number;
|
|
32
32
|
width: number;
|
|
33
33
|
geoLocation: GeoLocation | null;
|
|
34
|
-
datetimeOriginal: string;
|
|
34
|
+
datetimeOriginal: string | null;
|
|
35
35
|
format: string;
|
|
36
36
|
colorMode: string;
|
|
37
37
|
dpi: {
|
|
@@ -126,12 +126,15 @@ export type FileInfo = {
|
|
|
126
126
|
s3Bucket?: string;
|
|
127
127
|
metadata?: Metadata;
|
|
128
128
|
};
|
|
129
|
+
export type GroupFileInfo = FileInfo & {
|
|
130
|
+
defaultEffects: string;
|
|
131
|
+
};
|
|
129
132
|
export type GroupInfo = {
|
|
130
133
|
datetimeCreated: string;
|
|
131
134
|
datetimeStored: string | null;
|
|
132
135
|
filesCount: string;
|
|
133
136
|
cdnUrl: string;
|
|
134
|
-
files:
|
|
137
|
+
files: (GroupFileInfo | null)[];
|
|
135
138
|
url: string;
|
|
136
139
|
id: GroupId;
|
|
137
140
|
};
|
|
@@ -347,7 +350,8 @@ export declare class UploadcareFile {
|
|
|
347
350
|
readonly contentInfo: null | ContentInfo;
|
|
348
351
|
readonly metadata: null | Metadata;
|
|
349
352
|
readonly s3Bucket: null | string;
|
|
350
|
-
|
|
353
|
+
readonly defaultEffects: null | string;
|
|
354
|
+
constructor(fileInfo: FileInfo | GroupFileInfo, { baseCDN, fileName }?: {
|
|
351
355
|
baseCDN?: string;
|
|
352
356
|
fileName?: string;
|
|
353
357
|
});
|
|
@@ -449,12 +453,26 @@ export declare class UploadcareGroup {
|
|
|
449
453
|
readonly files: UploadcareFile[];
|
|
450
454
|
readonly createdAt: string;
|
|
451
455
|
readonly storedAt: string | null;
|
|
452
|
-
constructor(groupInfo: GroupInfo,
|
|
456
|
+
constructor(groupInfo: GroupInfo, { baseCDN }?: {
|
|
457
|
+
baseCDN?: string;
|
|
458
|
+
});
|
|
453
459
|
}
|
|
454
460
|
export type GroupFromOptions = {
|
|
455
461
|
jsonpCallback?: string;
|
|
456
462
|
};
|
|
457
463
|
export declare function uploadFileGroup(data: SupportedFileInput[] | Url[] | Uuid[], { publicKey, fileName, baseURL, secureSignature, secureExpire, store, signal, onProgress, source, integration, userAgent, retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes, contentType, multipartChunkSize, baseCDN, checkForUrlDuplicates, saveUrlForRecurrentUploads, jsonpCallback }: FileFromOptions & GroupFromOptions): Promise<UploadcareGroup>;
|
|
464
|
+
export type IsReadyPoolOptions = {
|
|
465
|
+
publicKey: string;
|
|
466
|
+
baseURL?: string;
|
|
467
|
+
source?: string;
|
|
468
|
+
integration?: string;
|
|
469
|
+
userAgent?: CustomUserAgent;
|
|
470
|
+
retryThrottledRequestMaxTimes?: number;
|
|
471
|
+
retryNetworkErrorMaxTimes?: number;
|
|
472
|
+
onProgress?: ProgressCallback<ComputableProgressInfo>;
|
|
473
|
+
signal?: AbortSignal;
|
|
474
|
+
};
|
|
475
|
+
export declare function isReadyPoll(uuid: Uuid, { publicKey, baseURL, source, integration, userAgent, retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes, signal, onProgress }: IsReadyPoolOptions): Promise<FileInfo>;
|
|
458
476
|
export declare class UploadClient {
|
|
459
477
|
private settings;
|
|
460
478
|
constructor(settings: Settings);
|
|
@@ -471,11 +489,17 @@ export declare class UploadClient {
|
|
|
471
489
|
multipartComplete(uuid: Uuid, options?: Partial<MultipartCompleteOptions>): Promise<FileInfo>;
|
|
472
490
|
uploadFile(data: SupportedFileInput | Url | Uuid, options?: Partial<FileFromOptions>): Promise<UploadcareFile>;
|
|
473
491
|
uploadFileGroup(data: SupportedFileInput[] | Url[] | Uuid[], options?: Partial<FileFromOptions & GroupFromOptions>): Promise<UploadcareGroup>;
|
|
492
|
+
isReadyPoll(uuid: Uuid, options?: Partial<IsReadyPoolOptions>): Promise<FileInfo>;
|
|
474
493
|
}
|
|
475
494
|
export type Task<T = unknown> = () => Promise<T>;
|
|
476
495
|
export declare class Queue {
|
|
477
|
-
|
|
496
|
+
private _concurrency;
|
|
497
|
+
private _pending;
|
|
498
|
+
private _running;
|
|
499
|
+
private _resolvers;
|
|
500
|
+
private _rejectors;
|
|
478
501
|
constructor(concurrency: number);
|
|
502
|
+
private _run;
|
|
479
503
|
add<T>(task: Task<T>): Promise<T>;
|
|
480
504
|
get pending(): number;
|
|
481
505
|
get running(): number;
|
package/dist/cjs/index.node.cjs
CHANGED
|
@@ -428,7 +428,7 @@ const getUrl = (base, path, query) => {
|
|
|
428
428
|
return url.toString();
|
|
429
429
|
};
|
|
430
430
|
|
|
431
|
-
var version = '6.
|
|
431
|
+
var version = '6.8.0';
|
|
432
432
|
|
|
433
433
|
const LIBRARY_NAME = 'UploadcareUploadClient';
|
|
434
434
|
const LIBRARY_VERSION = version;
|
|
@@ -780,9 +780,9 @@ function multipartComplete(uuid, { publicKey, baseURL = defaultSettings.baseURL,
|
|
|
780
780
|
}), { retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes });
|
|
781
781
|
}
|
|
782
782
|
|
|
783
|
-
function isReadyPoll({
|
|
783
|
+
function isReadyPoll(uuid, { publicKey, baseURL, source, integration, userAgent, retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes, signal, onProgress }) {
|
|
784
784
|
return poll({
|
|
785
|
-
check: (signal) => info(
|
|
785
|
+
check: (signal) => info(uuid, {
|
|
786
786
|
publicKey,
|
|
787
787
|
baseURL,
|
|
788
788
|
signal,
|
|
@@ -802,6 +802,9 @@ function isReadyPoll({ file, publicKey, baseURL, source, integration, userAgent,
|
|
|
802
802
|
});
|
|
803
803
|
}
|
|
804
804
|
|
|
805
|
+
function isGroupFileInfo(fileInfo) {
|
|
806
|
+
return 'defaultEffects' in fileInfo;
|
|
807
|
+
}
|
|
805
808
|
class UploadcareFile {
|
|
806
809
|
uuid;
|
|
807
810
|
name = null;
|
|
@@ -817,6 +820,7 @@ class UploadcareFile {
|
|
|
817
820
|
contentInfo = null;
|
|
818
821
|
metadata = null;
|
|
819
822
|
s3Bucket = null;
|
|
823
|
+
defaultEffects = null;
|
|
820
824
|
constructor(fileInfo, { baseCDN = defaultSettings.baseCDN, fileName } = {}) {
|
|
821
825
|
const { uuid, s3Bucket } = fileInfo;
|
|
822
826
|
const cdnUrl = getUrl(baseCDN, `${uuid}/`);
|
|
@@ -837,6 +841,9 @@ class UploadcareFile {
|
|
|
837
841
|
this.metadata = fileInfo.metadata || null;
|
|
838
842
|
this.s3Bucket = s3Bucket || null;
|
|
839
843
|
this.s3Url = s3Url;
|
|
844
|
+
if (isGroupFileInfo(fileInfo)) {
|
|
845
|
+
this.defaultEffects = fileInfo.defaultEffects;
|
|
846
|
+
}
|
|
840
847
|
}
|
|
841
848
|
}
|
|
842
849
|
|
|
@@ -859,8 +866,7 @@ const uploadDirect = (file, { publicKey, fileName, baseURL, secureSignature, sec
|
|
|
859
866
|
metadata
|
|
860
867
|
})
|
|
861
868
|
.then(({ file }) => {
|
|
862
|
-
return isReadyPoll({
|
|
863
|
-
file,
|
|
869
|
+
return isReadyPoll(file, {
|
|
864
870
|
publicKey,
|
|
865
871
|
baseURL,
|
|
866
872
|
source,
|
|
@@ -1223,8 +1229,7 @@ const uploadFromUrl = (sourceUrl, { publicKey, fileName, baseURL, baseCDN, check
|
|
|
1223
1229
|
throw result;
|
|
1224
1230
|
return result;
|
|
1225
1231
|
})
|
|
1226
|
-
.then((result) => isReadyPoll({
|
|
1227
|
-
file: result.uuid,
|
|
1232
|
+
.then((result) => isReadyPoll(result.uuid, {
|
|
1228
1233
|
publicKey,
|
|
1229
1234
|
baseURL,
|
|
1230
1235
|
integration,
|
|
@@ -1402,8 +1407,7 @@ const uploadMultipart = async (file, { publicKey, fileName, fileSize, baseURL, s
|
|
|
1402
1407
|
return fileInfo;
|
|
1403
1408
|
}
|
|
1404
1409
|
else {
|
|
1405
|
-
return isReadyPoll({
|
|
1406
|
-
file: fileInfo.uuid,
|
|
1410
|
+
return isReadyPoll(fileInfo.uuid, {
|
|
1407
1411
|
publicKey,
|
|
1408
1412
|
baseURL,
|
|
1409
1413
|
source,
|
|
@@ -1515,14 +1519,16 @@ class UploadcareGroup {
|
|
|
1515
1519
|
files;
|
|
1516
1520
|
createdAt;
|
|
1517
1521
|
storedAt = null;
|
|
1518
|
-
constructor(groupInfo,
|
|
1522
|
+
constructor(groupInfo, { baseCDN = defaultSettings.baseCDN } = {}) {
|
|
1519
1523
|
this.uuid = groupInfo.id;
|
|
1520
1524
|
this.filesCount = groupInfo.filesCount;
|
|
1521
|
-
|
|
1525
|
+
const groupFiles = groupInfo.files.filter(Boolean);
|
|
1526
|
+
this.totalSize = Object.values(groupFiles).reduce((acc, file) => acc + file.size, 0);
|
|
1522
1527
|
this.isStored = !!groupInfo.datetimeStored;
|
|
1523
|
-
this.isImage = !!Object.values(
|
|
1528
|
+
this.isImage = !!Object.values(groupFiles).filter((file) => file.isImage)
|
|
1529
|
+
.length;
|
|
1524
1530
|
this.cdnUrl = groupInfo.cdnUrl;
|
|
1525
|
-
this.files =
|
|
1531
|
+
this.files = groupFiles.map((fileInfo) => new UploadcareFile(fileInfo, { baseCDN }));
|
|
1526
1532
|
this.createdAt = groupInfo.datetimeCreated;
|
|
1527
1533
|
this.storedAt = groupInfo.datetimeStored;
|
|
1528
1534
|
}
|
|
@@ -1580,27 +1586,34 @@ function uploadFileGroup(data, { publicKey, fileName, baseURL = defaultSettings.
|
|
|
1580
1586
|
onProgress({ isComputable: true, value: normalize(progressValues) });
|
|
1581
1587
|
};
|
|
1582
1588
|
};
|
|
1583
|
-
return Promise.all(data.map((file, index) =>
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1589
|
+
return Promise.all(data.map((file, index) => {
|
|
1590
|
+
if (isFileData(file) || isUrl(file)) {
|
|
1591
|
+
return uploadFile(file, {
|
|
1592
|
+
publicKey,
|
|
1593
|
+
fileName,
|
|
1594
|
+
baseURL,
|
|
1595
|
+
secureSignature,
|
|
1596
|
+
secureExpire,
|
|
1597
|
+
store,
|
|
1598
|
+
signal,
|
|
1599
|
+
onProgress: createProgressHandler(filesCount, index),
|
|
1600
|
+
source,
|
|
1601
|
+
integration,
|
|
1602
|
+
userAgent,
|
|
1603
|
+
retryThrottledRequestMaxTimes,
|
|
1604
|
+
retryNetworkErrorMaxTimes,
|
|
1605
|
+
contentType,
|
|
1606
|
+
multipartChunkSize,
|
|
1607
|
+
baseCDN,
|
|
1608
|
+
checkForUrlDuplicates,
|
|
1609
|
+
saveUrlForRecurrentUploads
|
|
1610
|
+
}).then((fileInfo) => fileInfo.uuid);
|
|
1611
|
+
}
|
|
1612
|
+
else {
|
|
1613
|
+
// Do not request file info by uuid before creating group because this isn't necessary
|
|
1614
|
+
return file;
|
|
1615
|
+
}
|
|
1616
|
+
})).then((uuids) => {
|
|
1604
1617
|
return group(uuids, {
|
|
1605
1618
|
publicKey,
|
|
1606
1619
|
baseURL,
|
|
@@ -1614,7 +1627,7 @@ function uploadFileGroup(data, { publicKey, fileName, baseURL = defaultSettings.
|
|
|
1614
1627
|
retryThrottledRequestMaxTimes,
|
|
1615
1628
|
retryNetworkErrorMaxTimes
|
|
1616
1629
|
})
|
|
1617
|
-
.then((groupInfo) => new UploadcareGroup(groupInfo,
|
|
1630
|
+
.then((groupInfo) => new UploadcareGroup(groupInfo, { baseCDN }))
|
|
1618
1631
|
.then((group) => {
|
|
1619
1632
|
onProgress && onProgress({ isComputable: true, value: 1 });
|
|
1620
1633
|
return group;
|
|
@@ -1682,35 +1695,39 @@ class UploadClient {
|
|
|
1682
1695
|
const settings = this.getSettings();
|
|
1683
1696
|
return uploadFileGroup(data, populateOptionsWithSettings(options, settings));
|
|
1684
1697
|
}
|
|
1698
|
+
isReadyPoll(uuid, options = {}) {
|
|
1699
|
+
const settings = this.getSettings();
|
|
1700
|
+
return isReadyPoll(uuid, populateOptionsWithSettings(options, settings));
|
|
1701
|
+
}
|
|
1685
1702
|
}
|
|
1686
1703
|
|
|
1687
1704
|
class Queue {
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1705
|
+
_concurrency = 1;
|
|
1706
|
+
_pending = [];
|
|
1707
|
+
_running = 0;
|
|
1708
|
+
_resolvers = new Map();
|
|
1709
|
+
_rejectors = new Map();
|
|
1693
1710
|
constructor(concurrency) {
|
|
1694
|
-
this
|
|
1711
|
+
this._concurrency = concurrency;
|
|
1695
1712
|
}
|
|
1696
|
-
|
|
1697
|
-
const tasksLeft = this
|
|
1713
|
+
_run() {
|
|
1714
|
+
const tasksLeft = this._concurrency - this._running;
|
|
1698
1715
|
for (let i = 0; i < tasksLeft; i++) {
|
|
1699
|
-
const task = this
|
|
1716
|
+
const task = this._pending.shift();
|
|
1700
1717
|
if (!task) {
|
|
1701
1718
|
return;
|
|
1702
1719
|
}
|
|
1703
|
-
const resolver = this
|
|
1704
|
-
const rejector = this
|
|
1720
|
+
const resolver = this._resolvers.get(task);
|
|
1721
|
+
const rejector = this._rejectors.get(task);
|
|
1705
1722
|
if (!resolver || !rejector)
|
|
1706
1723
|
throw new Error('Unexpected behavior: resolver or rejector is undefined');
|
|
1707
|
-
this
|
|
1724
|
+
this._running += 1;
|
|
1708
1725
|
task()
|
|
1709
1726
|
.finally(() => {
|
|
1710
|
-
this
|
|
1711
|
-
this
|
|
1712
|
-
this
|
|
1713
|
-
this
|
|
1727
|
+
this._resolvers.delete(task);
|
|
1728
|
+
this._rejectors.delete(task);
|
|
1729
|
+
this._running -= 1;
|
|
1730
|
+
this._run();
|
|
1714
1731
|
})
|
|
1715
1732
|
.then((value) => resolver(value))
|
|
1716
1733
|
.catch((error) => rejector(error));
|
|
@@ -1718,24 +1735,24 @@ class Queue {
|
|
|
1718
1735
|
}
|
|
1719
1736
|
add(task) {
|
|
1720
1737
|
return new Promise((resolve, reject) => {
|
|
1721
|
-
this
|
|
1722
|
-
this
|
|
1723
|
-
this
|
|
1724
|
-
this
|
|
1738
|
+
this._resolvers.set(task, resolve);
|
|
1739
|
+
this._rejectors.set(task, reject);
|
|
1740
|
+
this._pending.push(task);
|
|
1741
|
+
this._run();
|
|
1725
1742
|
});
|
|
1726
1743
|
}
|
|
1727
1744
|
get pending() {
|
|
1728
|
-
return this
|
|
1745
|
+
return this._pending.length;
|
|
1729
1746
|
}
|
|
1730
1747
|
get running() {
|
|
1731
|
-
return this
|
|
1748
|
+
return this._running;
|
|
1732
1749
|
}
|
|
1733
1750
|
set concurrency(value) {
|
|
1734
|
-
this
|
|
1735
|
-
this
|
|
1751
|
+
this._concurrency = value;
|
|
1752
|
+
this._run();
|
|
1736
1753
|
}
|
|
1737
1754
|
get concurrency() {
|
|
1738
|
-
return this
|
|
1755
|
+
return this._concurrency;
|
|
1739
1756
|
}
|
|
1740
1757
|
}
|
|
1741
1758
|
|
|
@@ -1752,6 +1769,7 @@ exports.getUserAgent = getUserAgent$1;
|
|
|
1752
1769
|
exports.group = group;
|
|
1753
1770
|
exports.groupInfo = groupInfo;
|
|
1754
1771
|
exports.info = info;
|
|
1772
|
+
exports.isReadyPoll = isReadyPoll;
|
|
1755
1773
|
exports.multipartComplete = multipartComplete;
|
|
1756
1774
|
exports.multipartStart = multipartStart;
|
|
1757
1775
|
exports.multipartUpload = multipartUpload;
|
|
@@ -31,7 +31,7 @@ export type ImageInfo = {
|
|
|
31
31
|
height: number;
|
|
32
32
|
width: number;
|
|
33
33
|
geoLocation: GeoLocation | null;
|
|
34
|
-
datetimeOriginal: string;
|
|
34
|
+
datetimeOriginal: string | null;
|
|
35
35
|
format: string;
|
|
36
36
|
colorMode: string;
|
|
37
37
|
dpi: {
|
|
@@ -126,12 +126,15 @@ export type FileInfo = {
|
|
|
126
126
|
s3Bucket?: string;
|
|
127
127
|
metadata?: Metadata;
|
|
128
128
|
};
|
|
129
|
+
export type GroupFileInfo = FileInfo & {
|
|
130
|
+
defaultEffects: string;
|
|
131
|
+
};
|
|
129
132
|
export type GroupInfo = {
|
|
130
133
|
datetimeCreated: string;
|
|
131
134
|
datetimeStored: string | null;
|
|
132
135
|
filesCount: string;
|
|
133
136
|
cdnUrl: string;
|
|
134
|
-
files:
|
|
137
|
+
files: (GroupFileInfo | null)[];
|
|
135
138
|
url: string;
|
|
136
139
|
id: GroupId;
|
|
137
140
|
};
|
|
@@ -347,7 +350,8 @@ export declare class UploadcareFile {
|
|
|
347
350
|
readonly contentInfo: null | ContentInfo;
|
|
348
351
|
readonly metadata: null | Metadata;
|
|
349
352
|
readonly s3Bucket: null | string;
|
|
350
|
-
|
|
353
|
+
readonly defaultEffects: null | string;
|
|
354
|
+
constructor(fileInfo: FileInfo | GroupFileInfo, { baseCDN, fileName }?: {
|
|
351
355
|
baseCDN?: string;
|
|
352
356
|
fileName?: string;
|
|
353
357
|
});
|
|
@@ -449,12 +453,26 @@ export declare class UploadcareGroup {
|
|
|
449
453
|
readonly files: UploadcareFile[];
|
|
450
454
|
readonly createdAt: string;
|
|
451
455
|
readonly storedAt: string | null;
|
|
452
|
-
constructor(groupInfo: GroupInfo,
|
|
456
|
+
constructor(groupInfo: GroupInfo, { baseCDN }?: {
|
|
457
|
+
baseCDN?: string;
|
|
458
|
+
});
|
|
453
459
|
}
|
|
454
460
|
export type GroupFromOptions = {
|
|
455
461
|
jsonpCallback?: string;
|
|
456
462
|
};
|
|
457
463
|
export declare function uploadFileGroup(data: SupportedFileInput[] | Url[] | Uuid[], { publicKey, fileName, baseURL, secureSignature, secureExpire, store, signal, onProgress, source, integration, userAgent, retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes, contentType, multipartChunkSize, baseCDN, checkForUrlDuplicates, saveUrlForRecurrentUploads, jsonpCallback }: FileFromOptions & GroupFromOptions): Promise<UploadcareGroup>;
|
|
464
|
+
export type IsReadyPoolOptions = {
|
|
465
|
+
publicKey: string;
|
|
466
|
+
baseURL?: string;
|
|
467
|
+
source?: string;
|
|
468
|
+
integration?: string;
|
|
469
|
+
userAgent?: CustomUserAgent;
|
|
470
|
+
retryThrottledRequestMaxTimes?: number;
|
|
471
|
+
retryNetworkErrorMaxTimes?: number;
|
|
472
|
+
onProgress?: ProgressCallback<ComputableProgressInfo>;
|
|
473
|
+
signal?: AbortSignal;
|
|
474
|
+
};
|
|
475
|
+
export declare function isReadyPoll(uuid: Uuid, { publicKey, baseURL, source, integration, userAgent, retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes, signal, onProgress }: IsReadyPoolOptions): Promise<FileInfo>;
|
|
458
476
|
export declare class UploadClient {
|
|
459
477
|
private settings;
|
|
460
478
|
constructor(settings: Settings);
|
|
@@ -471,11 +489,17 @@ export declare class UploadClient {
|
|
|
471
489
|
multipartComplete(uuid: Uuid, options?: Partial<MultipartCompleteOptions>): Promise<FileInfo>;
|
|
472
490
|
uploadFile(data: SupportedFileInput | Url | Uuid, options?: Partial<FileFromOptions>): Promise<UploadcareFile>;
|
|
473
491
|
uploadFileGroup(data: SupportedFileInput[] | Url[] | Uuid[], options?: Partial<FileFromOptions & GroupFromOptions>): Promise<UploadcareGroup>;
|
|
492
|
+
isReadyPoll(uuid: Uuid, options?: Partial<IsReadyPoolOptions>): Promise<FileInfo>;
|
|
474
493
|
}
|
|
475
494
|
export type Task<T = unknown> = () => Promise<T>;
|
|
476
495
|
export declare class Queue {
|
|
477
|
-
|
|
496
|
+
private _concurrency;
|
|
497
|
+
private _pending;
|
|
498
|
+
private _running;
|
|
499
|
+
private _resolvers;
|
|
500
|
+
private _rejectors;
|
|
478
501
|
constructor(concurrency: number);
|
|
502
|
+
private _run;
|
|
479
503
|
add<T>(task: Task<T>): Promise<T>;
|
|
480
504
|
get pending(): number;
|
|
481
505
|
get running(): number;
|