@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
|
@@ -405,7 +405,7 @@ const getUrl = (base, path, query) => {
|
|
|
405
405
|
return url.toString();
|
|
406
406
|
};
|
|
407
407
|
|
|
408
|
-
var version = '6.
|
|
408
|
+
var version = '6.8.0';
|
|
409
409
|
|
|
410
410
|
const LIBRARY_NAME = 'UploadcareUploadClient';
|
|
411
411
|
const LIBRARY_VERSION = version;
|
|
@@ -757,9 +757,9 @@ function multipartComplete(uuid, { publicKey, baseURL = defaultSettings.baseURL,
|
|
|
757
757
|
}), { retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes });
|
|
758
758
|
}
|
|
759
759
|
|
|
760
|
-
function isReadyPoll({
|
|
760
|
+
function isReadyPoll(uuid, { publicKey, baseURL, source, integration, userAgent, retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes, signal, onProgress }) {
|
|
761
761
|
return poll({
|
|
762
|
-
check: (signal) => info(
|
|
762
|
+
check: (signal) => info(uuid, {
|
|
763
763
|
publicKey,
|
|
764
764
|
baseURL,
|
|
765
765
|
signal,
|
|
@@ -779,6 +779,9 @@ function isReadyPoll({ file, publicKey, baseURL, source, integration, userAgent,
|
|
|
779
779
|
});
|
|
780
780
|
}
|
|
781
781
|
|
|
782
|
+
function isGroupFileInfo(fileInfo) {
|
|
783
|
+
return 'defaultEffects' in fileInfo;
|
|
784
|
+
}
|
|
782
785
|
class UploadcareFile {
|
|
783
786
|
uuid;
|
|
784
787
|
name = null;
|
|
@@ -794,6 +797,7 @@ class UploadcareFile {
|
|
|
794
797
|
contentInfo = null;
|
|
795
798
|
metadata = null;
|
|
796
799
|
s3Bucket = null;
|
|
800
|
+
defaultEffects = null;
|
|
797
801
|
constructor(fileInfo, { baseCDN = defaultSettings.baseCDN, fileName } = {}) {
|
|
798
802
|
const { uuid, s3Bucket } = fileInfo;
|
|
799
803
|
const cdnUrl = getUrl(baseCDN, `${uuid}/`);
|
|
@@ -814,6 +818,9 @@ class UploadcareFile {
|
|
|
814
818
|
this.metadata = fileInfo.metadata || null;
|
|
815
819
|
this.s3Bucket = s3Bucket || null;
|
|
816
820
|
this.s3Url = s3Url;
|
|
821
|
+
if (isGroupFileInfo(fileInfo)) {
|
|
822
|
+
this.defaultEffects = fileInfo.defaultEffects;
|
|
823
|
+
}
|
|
817
824
|
}
|
|
818
825
|
}
|
|
819
826
|
|
|
@@ -836,8 +843,7 @@ const uploadDirect = (file, { publicKey, fileName, baseURL, secureSignature, sec
|
|
|
836
843
|
metadata
|
|
837
844
|
})
|
|
838
845
|
.then(({ file }) => {
|
|
839
|
-
return isReadyPoll({
|
|
840
|
-
file,
|
|
846
|
+
return isReadyPoll(file, {
|
|
841
847
|
publicKey,
|
|
842
848
|
baseURL,
|
|
843
849
|
source,
|
|
@@ -1202,8 +1208,7 @@ const uploadFromUrl = (sourceUrl, { publicKey, fileName, baseURL, baseCDN, check
|
|
|
1202
1208
|
throw result;
|
|
1203
1209
|
return result;
|
|
1204
1210
|
})
|
|
1205
|
-
.then((result) => isReadyPoll({
|
|
1206
|
-
file: result.uuid,
|
|
1211
|
+
.then((result) => isReadyPoll(result.uuid, {
|
|
1207
1212
|
publicKey,
|
|
1208
1213
|
baseURL,
|
|
1209
1214
|
integration,
|
|
@@ -1398,8 +1403,7 @@ const uploadMultipart = async (file, { publicKey, fileName, fileSize, baseURL, s
|
|
|
1398
1403
|
return fileInfo;
|
|
1399
1404
|
}
|
|
1400
1405
|
else {
|
|
1401
|
-
return isReadyPoll({
|
|
1402
|
-
file: fileInfo.uuid,
|
|
1406
|
+
return isReadyPoll(fileInfo.uuid, {
|
|
1403
1407
|
publicKey,
|
|
1404
1408
|
baseURL,
|
|
1405
1409
|
source,
|
|
@@ -1511,14 +1515,16 @@ class UploadcareGroup {
|
|
|
1511
1515
|
files;
|
|
1512
1516
|
createdAt;
|
|
1513
1517
|
storedAt = null;
|
|
1514
|
-
constructor(groupInfo,
|
|
1518
|
+
constructor(groupInfo, { baseCDN = defaultSettings.baseCDN } = {}) {
|
|
1515
1519
|
this.uuid = groupInfo.id;
|
|
1516
1520
|
this.filesCount = groupInfo.filesCount;
|
|
1517
|
-
|
|
1521
|
+
const groupFiles = groupInfo.files.filter(Boolean);
|
|
1522
|
+
this.totalSize = Object.values(groupFiles).reduce((acc, file) => acc + file.size, 0);
|
|
1518
1523
|
this.isStored = !!groupInfo.datetimeStored;
|
|
1519
|
-
this.isImage = !!Object.values(
|
|
1524
|
+
this.isImage = !!Object.values(groupFiles).filter((file) => file.isImage)
|
|
1525
|
+
.length;
|
|
1520
1526
|
this.cdnUrl = groupInfo.cdnUrl;
|
|
1521
|
-
this.files =
|
|
1527
|
+
this.files = groupFiles.map((fileInfo) => new UploadcareFile(fileInfo, { baseCDN }));
|
|
1522
1528
|
this.createdAt = groupInfo.datetimeCreated;
|
|
1523
1529
|
this.storedAt = groupInfo.datetimeStored;
|
|
1524
1530
|
}
|
|
@@ -1576,27 +1582,34 @@ function uploadFileGroup(data, { publicKey, fileName, baseURL = defaultSettings.
|
|
|
1576
1582
|
onProgress({ isComputable: true, value: normalize(progressValues) });
|
|
1577
1583
|
};
|
|
1578
1584
|
};
|
|
1579
|
-
return Promise.all(data.map((file, index) =>
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1585
|
+
return Promise.all(data.map((file, index) => {
|
|
1586
|
+
if (isFileData(file) || isUrl(file)) {
|
|
1587
|
+
return uploadFile(file, {
|
|
1588
|
+
publicKey,
|
|
1589
|
+
fileName,
|
|
1590
|
+
baseURL,
|
|
1591
|
+
secureSignature,
|
|
1592
|
+
secureExpire,
|
|
1593
|
+
store,
|
|
1594
|
+
signal,
|
|
1595
|
+
onProgress: createProgressHandler(filesCount, index),
|
|
1596
|
+
source,
|
|
1597
|
+
integration,
|
|
1598
|
+
userAgent,
|
|
1599
|
+
retryThrottledRequestMaxTimes,
|
|
1600
|
+
retryNetworkErrorMaxTimes,
|
|
1601
|
+
contentType,
|
|
1602
|
+
multipartChunkSize,
|
|
1603
|
+
baseCDN,
|
|
1604
|
+
checkForUrlDuplicates,
|
|
1605
|
+
saveUrlForRecurrentUploads
|
|
1606
|
+
}).then((fileInfo) => fileInfo.uuid);
|
|
1607
|
+
}
|
|
1608
|
+
else {
|
|
1609
|
+
// Do not request file info by uuid before creating group because this isn't necessary
|
|
1610
|
+
return file;
|
|
1611
|
+
}
|
|
1612
|
+
})).then((uuids) => {
|
|
1600
1613
|
return group(uuids, {
|
|
1601
1614
|
publicKey,
|
|
1602
1615
|
baseURL,
|
|
@@ -1610,7 +1623,7 @@ function uploadFileGroup(data, { publicKey, fileName, baseURL = defaultSettings.
|
|
|
1610
1623
|
retryThrottledRequestMaxTimes,
|
|
1611
1624
|
retryNetworkErrorMaxTimes
|
|
1612
1625
|
})
|
|
1613
|
-
.then((groupInfo) => new UploadcareGroup(groupInfo,
|
|
1626
|
+
.then((groupInfo) => new UploadcareGroup(groupInfo, { baseCDN }))
|
|
1614
1627
|
.then((group) => {
|
|
1615
1628
|
onProgress && onProgress({ isComputable: true, value: 1 });
|
|
1616
1629
|
return group;
|
|
@@ -1678,35 +1691,39 @@ class UploadClient {
|
|
|
1678
1691
|
const settings = this.getSettings();
|
|
1679
1692
|
return uploadFileGroup(data, populateOptionsWithSettings(options, settings));
|
|
1680
1693
|
}
|
|
1694
|
+
isReadyPoll(uuid, options = {}) {
|
|
1695
|
+
const settings = this.getSettings();
|
|
1696
|
+
return isReadyPoll(uuid, populateOptionsWithSettings(options, settings));
|
|
1697
|
+
}
|
|
1681
1698
|
}
|
|
1682
1699
|
|
|
1683
1700
|
class Queue {
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1701
|
+
_concurrency = 1;
|
|
1702
|
+
_pending = [];
|
|
1703
|
+
_running = 0;
|
|
1704
|
+
_resolvers = new Map();
|
|
1705
|
+
_rejectors = new Map();
|
|
1689
1706
|
constructor(concurrency) {
|
|
1690
|
-
this
|
|
1707
|
+
this._concurrency = concurrency;
|
|
1691
1708
|
}
|
|
1692
|
-
|
|
1693
|
-
const tasksLeft = this
|
|
1709
|
+
_run() {
|
|
1710
|
+
const tasksLeft = this._concurrency - this._running;
|
|
1694
1711
|
for (let i = 0; i < tasksLeft; i++) {
|
|
1695
|
-
const task = this
|
|
1712
|
+
const task = this._pending.shift();
|
|
1696
1713
|
if (!task) {
|
|
1697
1714
|
return;
|
|
1698
1715
|
}
|
|
1699
|
-
const resolver = this
|
|
1700
|
-
const rejector = this
|
|
1716
|
+
const resolver = this._resolvers.get(task);
|
|
1717
|
+
const rejector = this._rejectors.get(task);
|
|
1701
1718
|
if (!resolver || !rejector)
|
|
1702
1719
|
throw new Error('Unexpected behavior: resolver or rejector is undefined');
|
|
1703
|
-
this
|
|
1720
|
+
this._running += 1;
|
|
1704
1721
|
task()
|
|
1705
1722
|
.finally(() => {
|
|
1706
|
-
this
|
|
1707
|
-
this
|
|
1708
|
-
this
|
|
1709
|
-
this
|
|
1723
|
+
this._resolvers.delete(task);
|
|
1724
|
+
this._rejectors.delete(task);
|
|
1725
|
+
this._running -= 1;
|
|
1726
|
+
this._run();
|
|
1710
1727
|
})
|
|
1711
1728
|
.then((value) => resolver(value))
|
|
1712
1729
|
.catch((error) => rejector(error));
|
|
@@ -1714,24 +1731,24 @@ class Queue {
|
|
|
1714
1731
|
}
|
|
1715
1732
|
add(task) {
|
|
1716
1733
|
return new Promise((resolve, reject) => {
|
|
1717
|
-
this
|
|
1718
|
-
this
|
|
1719
|
-
this
|
|
1720
|
-
this
|
|
1734
|
+
this._resolvers.set(task, resolve);
|
|
1735
|
+
this._rejectors.set(task, reject);
|
|
1736
|
+
this._pending.push(task);
|
|
1737
|
+
this._run();
|
|
1721
1738
|
});
|
|
1722
1739
|
}
|
|
1723
1740
|
get pending() {
|
|
1724
|
-
return this
|
|
1741
|
+
return this._pending.length;
|
|
1725
1742
|
}
|
|
1726
1743
|
get running() {
|
|
1727
|
-
return this
|
|
1744
|
+
return this._running;
|
|
1728
1745
|
}
|
|
1729
1746
|
set concurrency(value) {
|
|
1730
|
-
this
|
|
1731
|
-
this
|
|
1747
|
+
this._concurrency = value;
|
|
1748
|
+
this._run();
|
|
1732
1749
|
}
|
|
1733
1750
|
get concurrency() {
|
|
1734
|
-
return this
|
|
1751
|
+
return this._concurrency;
|
|
1735
1752
|
}
|
|
1736
1753
|
}
|
|
1737
1754
|
|
|
@@ -1748,6 +1765,7 @@ exports.getUserAgent = getUserAgent$1;
|
|
|
1748
1765
|
exports.group = group;
|
|
1749
1766
|
exports.groupInfo = groupInfo;
|
|
1750
1767
|
exports.info = info;
|
|
1768
|
+
exports.isReadyPoll = isReadyPoll;
|
|
1751
1769
|
exports.multipartComplete = multipartComplete;
|
|
1752
1770
|
exports.multipartStart = multipartStart;
|
|
1753
1771
|
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;
|
|
@@ -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;
|
|
@@ -395,7 +395,7 @@ const getUrl = (base, path, query) => {
|
|
|
395
395
|
return url.toString();
|
|
396
396
|
};
|
|
397
397
|
|
|
398
|
-
var version = '6.
|
|
398
|
+
var version = '6.8.0';
|
|
399
399
|
|
|
400
400
|
const LIBRARY_NAME = 'UploadcareUploadClient';
|
|
401
401
|
const LIBRARY_VERSION = version;
|
|
@@ -747,9 +747,9 @@ function multipartComplete(uuid, { publicKey, baseURL = defaultSettings.baseURL,
|
|
|
747
747
|
}), { retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes });
|
|
748
748
|
}
|
|
749
749
|
|
|
750
|
-
function isReadyPoll({
|
|
750
|
+
function isReadyPoll(uuid, { publicKey, baseURL, source, integration, userAgent, retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes, signal, onProgress }) {
|
|
751
751
|
return poll({
|
|
752
|
-
check: (signal) => info(
|
|
752
|
+
check: (signal) => info(uuid, {
|
|
753
753
|
publicKey,
|
|
754
754
|
baseURL,
|
|
755
755
|
signal,
|
|
@@ -769,6 +769,9 @@ function isReadyPoll({ file, publicKey, baseURL, source, integration, userAgent,
|
|
|
769
769
|
});
|
|
770
770
|
}
|
|
771
771
|
|
|
772
|
+
function isGroupFileInfo(fileInfo) {
|
|
773
|
+
return 'defaultEffects' in fileInfo;
|
|
774
|
+
}
|
|
772
775
|
class UploadcareFile {
|
|
773
776
|
uuid;
|
|
774
777
|
name = null;
|
|
@@ -784,6 +787,7 @@ class UploadcareFile {
|
|
|
784
787
|
contentInfo = null;
|
|
785
788
|
metadata = null;
|
|
786
789
|
s3Bucket = null;
|
|
790
|
+
defaultEffects = null;
|
|
787
791
|
constructor(fileInfo, { baseCDN = defaultSettings.baseCDN, fileName } = {}) {
|
|
788
792
|
const { uuid, s3Bucket } = fileInfo;
|
|
789
793
|
const cdnUrl = getUrl(baseCDN, `${uuid}/`);
|
|
@@ -804,6 +808,9 @@ class UploadcareFile {
|
|
|
804
808
|
this.metadata = fileInfo.metadata || null;
|
|
805
809
|
this.s3Bucket = s3Bucket || null;
|
|
806
810
|
this.s3Url = s3Url;
|
|
811
|
+
if (isGroupFileInfo(fileInfo)) {
|
|
812
|
+
this.defaultEffects = fileInfo.defaultEffects;
|
|
813
|
+
}
|
|
807
814
|
}
|
|
808
815
|
}
|
|
809
816
|
|
|
@@ -826,8 +833,7 @@ const uploadDirect = (file, { publicKey, fileName, baseURL, secureSignature, sec
|
|
|
826
833
|
metadata
|
|
827
834
|
})
|
|
828
835
|
.then(({ file }) => {
|
|
829
|
-
return isReadyPoll({
|
|
830
|
-
file,
|
|
836
|
+
return isReadyPoll(file, {
|
|
831
837
|
publicKey,
|
|
832
838
|
baseURL,
|
|
833
839
|
source,
|
|
@@ -1192,8 +1198,7 @@ const uploadFromUrl = (sourceUrl, { publicKey, fileName, baseURL, baseCDN, check
|
|
|
1192
1198
|
throw result;
|
|
1193
1199
|
return result;
|
|
1194
1200
|
})
|
|
1195
|
-
.then((result) => isReadyPoll({
|
|
1196
|
-
file: result.uuid,
|
|
1201
|
+
.then((result) => isReadyPoll(result.uuid, {
|
|
1197
1202
|
publicKey,
|
|
1198
1203
|
baseURL,
|
|
1199
1204
|
integration,
|
|
@@ -1368,8 +1373,7 @@ const uploadMultipart = async (file, { publicKey, fileName, fileSize, baseURL, s
|
|
|
1368
1373
|
return fileInfo;
|
|
1369
1374
|
}
|
|
1370
1375
|
else {
|
|
1371
|
-
return isReadyPoll({
|
|
1372
|
-
file: fileInfo.uuid,
|
|
1376
|
+
return isReadyPoll(fileInfo.uuid, {
|
|
1373
1377
|
publicKey,
|
|
1374
1378
|
baseURL,
|
|
1375
1379
|
source,
|
|
@@ -1481,14 +1485,16 @@ class UploadcareGroup {
|
|
|
1481
1485
|
files;
|
|
1482
1486
|
createdAt;
|
|
1483
1487
|
storedAt = null;
|
|
1484
|
-
constructor(groupInfo,
|
|
1488
|
+
constructor(groupInfo, { baseCDN = defaultSettings.baseCDN } = {}) {
|
|
1485
1489
|
this.uuid = groupInfo.id;
|
|
1486
1490
|
this.filesCount = groupInfo.filesCount;
|
|
1487
|
-
|
|
1491
|
+
const groupFiles = groupInfo.files.filter(Boolean);
|
|
1492
|
+
this.totalSize = Object.values(groupFiles).reduce((acc, file) => acc + file.size, 0);
|
|
1488
1493
|
this.isStored = !!groupInfo.datetimeStored;
|
|
1489
|
-
this.isImage = !!Object.values(
|
|
1494
|
+
this.isImage = !!Object.values(groupFiles).filter((file) => file.isImage)
|
|
1495
|
+
.length;
|
|
1490
1496
|
this.cdnUrl = groupInfo.cdnUrl;
|
|
1491
|
-
this.files =
|
|
1497
|
+
this.files = groupFiles.map((fileInfo) => new UploadcareFile(fileInfo, { baseCDN }));
|
|
1492
1498
|
this.createdAt = groupInfo.datetimeCreated;
|
|
1493
1499
|
this.storedAt = groupInfo.datetimeStored;
|
|
1494
1500
|
}
|
|
@@ -1546,27 +1552,34 @@ function uploadFileGroup(data, { publicKey, fileName, baseURL = defaultSettings.
|
|
|
1546
1552
|
onProgress({ isComputable: true, value: normalize(progressValues) });
|
|
1547
1553
|
};
|
|
1548
1554
|
};
|
|
1549
|
-
return Promise.all(data.map((file, index) =>
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1555
|
+
return Promise.all(data.map((file, index) => {
|
|
1556
|
+
if (isFileData(file) || isUrl(file)) {
|
|
1557
|
+
return uploadFile(file, {
|
|
1558
|
+
publicKey,
|
|
1559
|
+
fileName,
|
|
1560
|
+
baseURL,
|
|
1561
|
+
secureSignature,
|
|
1562
|
+
secureExpire,
|
|
1563
|
+
store,
|
|
1564
|
+
signal,
|
|
1565
|
+
onProgress: createProgressHandler(filesCount, index),
|
|
1566
|
+
source,
|
|
1567
|
+
integration,
|
|
1568
|
+
userAgent,
|
|
1569
|
+
retryThrottledRequestMaxTimes,
|
|
1570
|
+
retryNetworkErrorMaxTimes,
|
|
1571
|
+
contentType,
|
|
1572
|
+
multipartChunkSize,
|
|
1573
|
+
baseCDN,
|
|
1574
|
+
checkForUrlDuplicates,
|
|
1575
|
+
saveUrlForRecurrentUploads
|
|
1576
|
+
}).then((fileInfo) => fileInfo.uuid);
|
|
1577
|
+
}
|
|
1578
|
+
else {
|
|
1579
|
+
// Do not request file info by uuid before creating group because this isn't necessary
|
|
1580
|
+
return file;
|
|
1581
|
+
}
|
|
1582
|
+
})).then((uuids) => {
|
|
1570
1583
|
return group(uuids, {
|
|
1571
1584
|
publicKey,
|
|
1572
1585
|
baseURL,
|
|
@@ -1580,7 +1593,7 @@ function uploadFileGroup(data, { publicKey, fileName, baseURL = defaultSettings.
|
|
|
1580
1593
|
retryThrottledRequestMaxTimes,
|
|
1581
1594
|
retryNetworkErrorMaxTimes
|
|
1582
1595
|
})
|
|
1583
|
-
.then((groupInfo) => new UploadcareGroup(groupInfo,
|
|
1596
|
+
.then((groupInfo) => new UploadcareGroup(groupInfo, { baseCDN }))
|
|
1584
1597
|
.then((group) => {
|
|
1585
1598
|
onProgress && onProgress({ isComputable: true, value: 1 });
|
|
1586
1599
|
return group;
|
|
@@ -1648,35 +1661,39 @@ class UploadClient {
|
|
|
1648
1661
|
const settings = this.getSettings();
|
|
1649
1662
|
return uploadFileGroup(data, populateOptionsWithSettings(options, settings));
|
|
1650
1663
|
}
|
|
1664
|
+
isReadyPoll(uuid, options = {}) {
|
|
1665
|
+
const settings = this.getSettings();
|
|
1666
|
+
return isReadyPoll(uuid, populateOptionsWithSettings(options, settings));
|
|
1667
|
+
}
|
|
1651
1668
|
}
|
|
1652
1669
|
|
|
1653
1670
|
class Queue {
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1671
|
+
_concurrency = 1;
|
|
1672
|
+
_pending = [];
|
|
1673
|
+
_running = 0;
|
|
1674
|
+
_resolvers = new Map();
|
|
1675
|
+
_rejectors = new Map();
|
|
1659
1676
|
constructor(concurrency) {
|
|
1660
|
-
this
|
|
1677
|
+
this._concurrency = concurrency;
|
|
1661
1678
|
}
|
|
1662
|
-
|
|
1663
|
-
const tasksLeft = this
|
|
1679
|
+
_run() {
|
|
1680
|
+
const tasksLeft = this._concurrency - this._running;
|
|
1664
1681
|
for (let i = 0; i < tasksLeft; i++) {
|
|
1665
|
-
const task = this
|
|
1682
|
+
const task = this._pending.shift();
|
|
1666
1683
|
if (!task) {
|
|
1667
1684
|
return;
|
|
1668
1685
|
}
|
|
1669
|
-
const resolver = this
|
|
1670
|
-
const rejector = this
|
|
1686
|
+
const resolver = this._resolvers.get(task);
|
|
1687
|
+
const rejector = this._rejectors.get(task);
|
|
1671
1688
|
if (!resolver || !rejector)
|
|
1672
1689
|
throw new Error('Unexpected behavior: resolver or rejector is undefined');
|
|
1673
|
-
this
|
|
1690
|
+
this._running += 1;
|
|
1674
1691
|
task()
|
|
1675
1692
|
.finally(() => {
|
|
1676
|
-
this
|
|
1677
|
-
this
|
|
1678
|
-
this
|
|
1679
|
-
this
|
|
1693
|
+
this._resolvers.delete(task);
|
|
1694
|
+
this._rejectors.delete(task);
|
|
1695
|
+
this._running -= 1;
|
|
1696
|
+
this._run();
|
|
1680
1697
|
})
|
|
1681
1698
|
.then((value) => resolver(value))
|
|
1682
1699
|
.catch((error) => rejector(error));
|
|
@@ -1684,25 +1701,25 @@ class Queue {
|
|
|
1684
1701
|
}
|
|
1685
1702
|
add(task) {
|
|
1686
1703
|
return new Promise((resolve, reject) => {
|
|
1687
|
-
this
|
|
1688
|
-
this
|
|
1689
|
-
this
|
|
1690
|
-
this
|
|
1704
|
+
this._resolvers.set(task, resolve);
|
|
1705
|
+
this._rejectors.set(task, reject);
|
|
1706
|
+
this._pending.push(task);
|
|
1707
|
+
this._run();
|
|
1691
1708
|
});
|
|
1692
1709
|
}
|
|
1693
1710
|
get pending() {
|
|
1694
|
-
return this
|
|
1711
|
+
return this._pending.length;
|
|
1695
1712
|
}
|
|
1696
1713
|
get running() {
|
|
1697
|
-
return this
|
|
1714
|
+
return this._running;
|
|
1698
1715
|
}
|
|
1699
1716
|
set concurrency(value) {
|
|
1700
|
-
this
|
|
1701
|
-
this
|
|
1717
|
+
this._concurrency = value;
|
|
1718
|
+
this._run();
|
|
1702
1719
|
}
|
|
1703
1720
|
get concurrency() {
|
|
1704
|
-
return this
|
|
1721
|
+
return this._concurrency;
|
|
1705
1722
|
}
|
|
1706
1723
|
}
|
|
1707
1724
|
|
|
1708
|
-
export { Queue, UploadClient, UploadClientError, UploadcareFile, UploadcareGroup, UploadcareNetworkError, base, fromUrl, fromUrlStatus, getUserAgent$1 as getUserAgent, group, groupInfo, info, multipartComplete, multipartStart, multipartUpload, uploadDirect, uploadFile, uploadFileGroup, uploadFromUploaded, uploadFromUrl, uploadMultipart };
|
|
1725
|
+
export { Queue, UploadClient, UploadClientError, UploadcareFile, UploadcareGroup, UploadcareNetworkError, base, fromUrl, fromUrlStatus, getUserAgent$1 as getUserAgent, group, groupInfo, info, isReadyPoll, multipartComplete, multipartStart, multipartUpload, uploadDirect, uploadFile, uploadFileGroup, uploadFromUploaded, uploadFromUrl, uploadMultipart };
|