@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
|
@@ -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/esm/index.node.mjs
CHANGED
|
@@ -426,7 +426,7 @@ const getUrl = (base, path, query) => {
|
|
|
426
426
|
return url.toString();
|
|
427
427
|
};
|
|
428
428
|
|
|
429
|
-
var version = '6.
|
|
429
|
+
var version = '6.8.0';
|
|
430
430
|
|
|
431
431
|
const LIBRARY_NAME = 'UploadcareUploadClient';
|
|
432
432
|
const LIBRARY_VERSION = version;
|
|
@@ -778,9 +778,9 @@ function multipartComplete(uuid, { publicKey, baseURL = defaultSettings.baseURL,
|
|
|
778
778
|
}), { retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes });
|
|
779
779
|
}
|
|
780
780
|
|
|
781
|
-
function isReadyPoll({
|
|
781
|
+
function isReadyPoll(uuid, { publicKey, baseURL, source, integration, userAgent, retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes, signal, onProgress }) {
|
|
782
782
|
return poll({
|
|
783
|
-
check: (signal) => info(
|
|
783
|
+
check: (signal) => info(uuid, {
|
|
784
784
|
publicKey,
|
|
785
785
|
baseURL,
|
|
786
786
|
signal,
|
|
@@ -800,6 +800,9 @@ function isReadyPoll({ file, publicKey, baseURL, source, integration, userAgent,
|
|
|
800
800
|
});
|
|
801
801
|
}
|
|
802
802
|
|
|
803
|
+
function isGroupFileInfo(fileInfo) {
|
|
804
|
+
return 'defaultEffects' in fileInfo;
|
|
805
|
+
}
|
|
803
806
|
class UploadcareFile {
|
|
804
807
|
uuid;
|
|
805
808
|
name = null;
|
|
@@ -815,6 +818,7 @@ class UploadcareFile {
|
|
|
815
818
|
contentInfo = null;
|
|
816
819
|
metadata = null;
|
|
817
820
|
s3Bucket = null;
|
|
821
|
+
defaultEffects = null;
|
|
818
822
|
constructor(fileInfo, { baseCDN = defaultSettings.baseCDN, fileName } = {}) {
|
|
819
823
|
const { uuid, s3Bucket } = fileInfo;
|
|
820
824
|
const cdnUrl = getUrl(baseCDN, `${uuid}/`);
|
|
@@ -835,6 +839,9 @@ class UploadcareFile {
|
|
|
835
839
|
this.metadata = fileInfo.metadata || null;
|
|
836
840
|
this.s3Bucket = s3Bucket || null;
|
|
837
841
|
this.s3Url = s3Url;
|
|
842
|
+
if (isGroupFileInfo(fileInfo)) {
|
|
843
|
+
this.defaultEffects = fileInfo.defaultEffects;
|
|
844
|
+
}
|
|
838
845
|
}
|
|
839
846
|
}
|
|
840
847
|
|
|
@@ -857,8 +864,7 @@ const uploadDirect = (file, { publicKey, fileName, baseURL, secureSignature, sec
|
|
|
857
864
|
metadata
|
|
858
865
|
})
|
|
859
866
|
.then(({ file }) => {
|
|
860
|
-
return isReadyPoll({
|
|
861
|
-
file,
|
|
867
|
+
return isReadyPoll(file, {
|
|
862
868
|
publicKey,
|
|
863
869
|
baseURL,
|
|
864
870
|
source,
|
|
@@ -1221,8 +1227,7 @@ const uploadFromUrl = (sourceUrl, { publicKey, fileName, baseURL, baseCDN, check
|
|
|
1221
1227
|
throw result;
|
|
1222
1228
|
return result;
|
|
1223
1229
|
})
|
|
1224
|
-
.then((result) => isReadyPoll({
|
|
1225
|
-
file: result.uuid,
|
|
1230
|
+
.then((result) => isReadyPoll(result.uuid, {
|
|
1226
1231
|
publicKey,
|
|
1227
1232
|
baseURL,
|
|
1228
1233
|
integration,
|
|
@@ -1400,8 +1405,7 @@ const uploadMultipart = async (file, { publicKey, fileName, fileSize, baseURL, s
|
|
|
1400
1405
|
return fileInfo;
|
|
1401
1406
|
}
|
|
1402
1407
|
else {
|
|
1403
|
-
return isReadyPoll({
|
|
1404
|
-
file: fileInfo.uuid,
|
|
1408
|
+
return isReadyPoll(fileInfo.uuid, {
|
|
1405
1409
|
publicKey,
|
|
1406
1410
|
baseURL,
|
|
1407
1411
|
source,
|
|
@@ -1513,14 +1517,16 @@ class UploadcareGroup {
|
|
|
1513
1517
|
files;
|
|
1514
1518
|
createdAt;
|
|
1515
1519
|
storedAt = null;
|
|
1516
|
-
constructor(groupInfo,
|
|
1520
|
+
constructor(groupInfo, { baseCDN = defaultSettings.baseCDN } = {}) {
|
|
1517
1521
|
this.uuid = groupInfo.id;
|
|
1518
1522
|
this.filesCount = groupInfo.filesCount;
|
|
1519
|
-
|
|
1523
|
+
const groupFiles = groupInfo.files.filter(Boolean);
|
|
1524
|
+
this.totalSize = Object.values(groupFiles).reduce((acc, file) => acc + file.size, 0);
|
|
1520
1525
|
this.isStored = !!groupInfo.datetimeStored;
|
|
1521
|
-
this.isImage = !!Object.values(
|
|
1526
|
+
this.isImage = !!Object.values(groupFiles).filter((file) => file.isImage)
|
|
1527
|
+
.length;
|
|
1522
1528
|
this.cdnUrl = groupInfo.cdnUrl;
|
|
1523
|
-
this.files =
|
|
1529
|
+
this.files = groupFiles.map((fileInfo) => new UploadcareFile(fileInfo, { baseCDN }));
|
|
1524
1530
|
this.createdAt = groupInfo.datetimeCreated;
|
|
1525
1531
|
this.storedAt = groupInfo.datetimeStored;
|
|
1526
1532
|
}
|
|
@@ -1578,27 +1584,34 @@ function uploadFileGroup(data, { publicKey, fileName, baseURL = defaultSettings.
|
|
|
1578
1584
|
onProgress({ isComputable: true, value: normalize(progressValues) });
|
|
1579
1585
|
};
|
|
1580
1586
|
};
|
|
1581
|
-
return Promise.all(data.map((file, index) =>
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1587
|
+
return Promise.all(data.map((file, index) => {
|
|
1588
|
+
if (isFileData(file) || isUrl(file)) {
|
|
1589
|
+
return uploadFile(file, {
|
|
1590
|
+
publicKey,
|
|
1591
|
+
fileName,
|
|
1592
|
+
baseURL,
|
|
1593
|
+
secureSignature,
|
|
1594
|
+
secureExpire,
|
|
1595
|
+
store,
|
|
1596
|
+
signal,
|
|
1597
|
+
onProgress: createProgressHandler(filesCount, index),
|
|
1598
|
+
source,
|
|
1599
|
+
integration,
|
|
1600
|
+
userAgent,
|
|
1601
|
+
retryThrottledRequestMaxTimes,
|
|
1602
|
+
retryNetworkErrorMaxTimes,
|
|
1603
|
+
contentType,
|
|
1604
|
+
multipartChunkSize,
|
|
1605
|
+
baseCDN,
|
|
1606
|
+
checkForUrlDuplicates,
|
|
1607
|
+
saveUrlForRecurrentUploads
|
|
1608
|
+
}).then((fileInfo) => fileInfo.uuid);
|
|
1609
|
+
}
|
|
1610
|
+
else {
|
|
1611
|
+
// Do not request file info by uuid before creating group because this isn't necessary
|
|
1612
|
+
return file;
|
|
1613
|
+
}
|
|
1614
|
+
})).then((uuids) => {
|
|
1602
1615
|
return group(uuids, {
|
|
1603
1616
|
publicKey,
|
|
1604
1617
|
baseURL,
|
|
@@ -1612,7 +1625,7 @@ function uploadFileGroup(data, { publicKey, fileName, baseURL = defaultSettings.
|
|
|
1612
1625
|
retryThrottledRequestMaxTimes,
|
|
1613
1626
|
retryNetworkErrorMaxTimes
|
|
1614
1627
|
})
|
|
1615
|
-
.then((groupInfo) => new UploadcareGroup(groupInfo,
|
|
1628
|
+
.then((groupInfo) => new UploadcareGroup(groupInfo, { baseCDN }))
|
|
1616
1629
|
.then((group) => {
|
|
1617
1630
|
onProgress && onProgress({ isComputable: true, value: 1 });
|
|
1618
1631
|
return group;
|
|
@@ -1680,35 +1693,39 @@ class UploadClient {
|
|
|
1680
1693
|
const settings = this.getSettings();
|
|
1681
1694
|
return uploadFileGroup(data, populateOptionsWithSettings(options, settings));
|
|
1682
1695
|
}
|
|
1696
|
+
isReadyPoll(uuid, options = {}) {
|
|
1697
|
+
const settings = this.getSettings();
|
|
1698
|
+
return isReadyPoll(uuid, populateOptionsWithSettings(options, settings));
|
|
1699
|
+
}
|
|
1683
1700
|
}
|
|
1684
1701
|
|
|
1685
1702
|
class Queue {
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1703
|
+
_concurrency = 1;
|
|
1704
|
+
_pending = [];
|
|
1705
|
+
_running = 0;
|
|
1706
|
+
_resolvers = new Map();
|
|
1707
|
+
_rejectors = new Map();
|
|
1691
1708
|
constructor(concurrency) {
|
|
1692
|
-
this
|
|
1709
|
+
this._concurrency = concurrency;
|
|
1693
1710
|
}
|
|
1694
|
-
|
|
1695
|
-
const tasksLeft = this
|
|
1711
|
+
_run() {
|
|
1712
|
+
const tasksLeft = this._concurrency - this._running;
|
|
1696
1713
|
for (let i = 0; i < tasksLeft; i++) {
|
|
1697
|
-
const task = this
|
|
1714
|
+
const task = this._pending.shift();
|
|
1698
1715
|
if (!task) {
|
|
1699
1716
|
return;
|
|
1700
1717
|
}
|
|
1701
|
-
const resolver = this
|
|
1702
|
-
const rejector = this
|
|
1718
|
+
const resolver = this._resolvers.get(task);
|
|
1719
|
+
const rejector = this._rejectors.get(task);
|
|
1703
1720
|
if (!resolver || !rejector)
|
|
1704
1721
|
throw new Error('Unexpected behavior: resolver or rejector is undefined');
|
|
1705
|
-
this
|
|
1722
|
+
this._running += 1;
|
|
1706
1723
|
task()
|
|
1707
1724
|
.finally(() => {
|
|
1708
|
-
this
|
|
1709
|
-
this
|
|
1710
|
-
this
|
|
1711
|
-
this
|
|
1725
|
+
this._resolvers.delete(task);
|
|
1726
|
+
this._rejectors.delete(task);
|
|
1727
|
+
this._running -= 1;
|
|
1728
|
+
this._run();
|
|
1712
1729
|
})
|
|
1713
1730
|
.then((value) => resolver(value))
|
|
1714
1731
|
.catch((error) => rejector(error));
|
|
@@ -1716,25 +1733,25 @@ class Queue {
|
|
|
1716
1733
|
}
|
|
1717
1734
|
add(task) {
|
|
1718
1735
|
return new Promise((resolve, reject) => {
|
|
1719
|
-
this
|
|
1720
|
-
this
|
|
1721
|
-
this
|
|
1722
|
-
this
|
|
1736
|
+
this._resolvers.set(task, resolve);
|
|
1737
|
+
this._rejectors.set(task, reject);
|
|
1738
|
+
this._pending.push(task);
|
|
1739
|
+
this._run();
|
|
1723
1740
|
});
|
|
1724
1741
|
}
|
|
1725
1742
|
get pending() {
|
|
1726
|
-
return this
|
|
1743
|
+
return this._pending.length;
|
|
1727
1744
|
}
|
|
1728
1745
|
get running() {
|
|
1729
|
-
return this
|
|
1746
|
+
return this._running;
|
|
1730
1747
|
}
|
|
1731
1748
|
set concurrency(value) {
|
|
1732
|
-
this
|
|
1733
|
-
this
|
|
1749
|
+
this._concurrency = value;
|
|
1750
|
+
this._run();
|
|
1734
1751
|
}
|
|
1735
1752
|
get concurrency() {
|
|
1736
|
-
return this
|
|
1753
|
+
return this._concurrency;
|
|
1737
1754
|
}
|
|
1738
1755
|
}
|
|
1739
1756
|
|
|
1740
|
-
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 };
|
|
1757
|
+
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 };
|
|
@@ -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;
|
|
@@ -403,7 +403,7 @@ const getUrl = (base, path, query) => {
|
|
|
403
403
|
return url.toString();
|
|
404
404
|
};
|
|
405
405
|
|
|
406
|
-
var version = '6.
|
|
406
|
+
var version = '6.8.0';
|
|
407
407
|
|
|
408
408
|
const LIBRARY_NAME = 'UploadcareUploadClient';
|
|
409
409
|
const LIBRARY_VERSION = version;
|
|
@@ -755,9 +755,9 @@ function multipartComplete(uuid, { publicKey, baseURL = defaultSettings.baseURL,
|
|
|
755
755
|
}), { retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes });
|
|
756
756
|
}
|
|
757
757
|
|
|
758
|
-
function isReadyPoll({
|
|
758
|
+
function isReadyPoll(uuid, { publicKey, baseURL, source, integration, userAgent, retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes, signal, onProgress }) {
|
|
759
759
|
return poll({
|
|
760
|
-
check: (signal) => info(
|
|
760
|
+
check: (signal) => info(uuid, {
|
|
761
761
|
publicKey,
|
|
762
762
|
baseURL,
|
|
763
763
|
signal,
|
|
@@ -777,6 +777,9 @@ function isReadyPoll({ file, publicKey, baseURL, source, integration, userAgent,
|
|
|
777
777
|
});
|
|
778
778
|
}
|
|
779
779
|
|
|
780
|
+
function isGroupFileInfo(fileInfo) {
|
|
781
|
+
return 'defaultEffects' in fileInfo;
|
|
782
|
+
}
|
|
780
783
|
class UploadcareFile {
|
|
781
784
|
uuid;
|
|
782
785
|
name = null;
|
|
@@ -792,6 +795,7 @@ class UploadcareFile {
|
|
|
792
795
|
contentInfo = null;
|
|
793
796
|
metadata = null;
|
|
794
797
|
s3Bucket = null;
|
|
798
|
+
defaultEffects = null;
|
|
795
799
|
constructor(fileInfo, { baseCDN = defaultSettings.baseCDN, fileName } = {}) {
|
|
796
800
|
const { uuid, s3Bucket } = fileInfo;
|
|
797
801
|
const cdnUrl = getUrl(baseCDN, `${uuid}/`);
|
|
@@ -812,6 +816,9 @@ class UploadcareFile {
|
|
|
812
816
|
this.metadata = fileInfo.metadata || null;
|
|
813
817
|
this.s3Bucket = s3Bucket || null;
|
|
814
818
|
this.s3Url = s3Url;
|
|
819
|
+
if (isGroupFileInfo(fileInfo)) {
|
|
820
|
+
this.defaultEffects = fileInfo.defaultEffects;
|
|
821
|
+
}
|
|
815
822
|
}
|
|
816
823
|
}
|
|
817
824
|
|
|
@@ -834,8 +841,7 @@ const uploadDirect = (file, { publicKey, fileName, baseURL, secureSignature, sec
|
|
|
834
841
|
metadata
|
|
835
842
|
})
|
|
836
843
|
.then(({ file }) => {
|
|
837
|
-
return isReadyPoll({
|
|
838
|
-
file,
|
|
844
|
+
return isReadyPoll(file, {
|
|
839
845
|
publicKey,
|
|
840
846
|
baseURL,
|
|
841
847
|
source,
|
|
@@ -1200,8 +1206,7 @@ const uploadFromUrl = (sourceUrl, { publicKey, fileName, baseURL, baseCDN, check
|
|
|
1200
1206
|
throw result;
|
|
1201
1207
|
return result;
|
|
1202
1208
|
})
|
|
1203
|
-
.then((result) => isReadyPoll({
|
|
1204
|
-
file: result.uuid,
|
|
1209
|
+
.then((result) => isReadyPoll(result.uuid, {
|
|
1205
1210
|
publicKey,
|
|
1206
1211
|
baseURL,
|
|
1207
1212
|
integration,
|
|
@@ -1396,8 +1401,7 @@ const uploadMultipart = async (file, { publicKey, fileName, fileSize, baseURL, s
|
|
|
1396
1401
|
return fileInfo;
|
|
1397
1402
|
}
|
|
1398
1403
|
else {
|
|
1399
|
-
return isReadyPoll({
|
|
1400
|
-
file: fileInfo.uuid,
|
|
1404
|
+
return isReadyPoll(fileInfo.uuid, {
|
|
1401
1405
|
publicKey,
|
|
1402
1406
|
baseURL,
|
|
1403
1407
|
source,
|
|
@@ -1509,14 +1513,16 @@ class UploadcareGroup {
|
|
|
1509
1513
|
files;
|
|
1510
1514
|
createdAt;
|
|
1511
1515
|
storedAt = null;
|
|
1512
|
-
constructor(groupInfo,
|
|
1516
|
+
constructor(groupInfo, { baseCDN = defaultSettings.baseCDN } = {}) {
|
|
1513
1517
|
this.uuid = groupInfo.id;
|
|
1514
1518
|
this.filesCount = groupInfo.filesCount;
|
|
1515
|
-
|
|
1519
|
+
const groupFiles = groupInfo.files.filter(Boolean);
|
|
1520
|
+
this.totalSize = Object.values(groupFiles).reduce((acc, file) => acc + file.size, 0);
|
|
1516
1521
|
this.isStored = !!groupInfo.datetimeStored;
|
|
1517
|
-
this.isImage = !!Object.values(
|
|
1522
|
+
this.isImage = !!Object.values(groupFiles).filter((file) => file.isImage)
|
|
1523
|
+
.length;
|
|
1518
1524
|
this.cdnUrl = groupInfo.cdnUrl;
|
|
1519
|
-
this.files =
|
|
1525
|
+
this.files = groupFiles.map((fileInfo) => new UploadcareFile(fileInfo, { baseCDN }));
|
|
1520
1526
|
this.createdAt = groupInfo.datetimeCreated;
|
|
1521
1527
|
this.storedAt = groupInfo.datetimeStored;
|
|
1522
1528
|
}
|
|
@@ -1574,27 +1580,34 @@ function uploadFileGroup(data, { publicKey, fileName, baseURL = defaultSettings.
|
|
|
1574
1580
|
onProgress({ isComputable: true, value: normalize(progressValues) });
|
|
1575
1581
|
};
|
|
1576
1582
|
};
|
|
1577
|
-
return Promise.all(data.map((file, index) =>
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1583
|
+
return Promise.all(data.map((file, index) => {
|
|
1584
|
+
if (isFileData(file) || isUrl(file)) {
|
|
1585
|
+
return uploadFile(file, {
|
|
1586
|
+
publicKey,
|
|
1587
|
+
fileName,
|
|
1588
|
+
baseURL,
|
|
1589
|
+
secureSignature,
|
|
1590
|
+
secureExpire,
|
|
1591
|
+
store,
|
|
1592
|
+
signal,
|
|
1593
|
+
onProgress: createProgressHandler(filesCount, index),
|
|
1594
|
+
source,
|
|
1595
|
+
integration,
|
|
1596
|
+
userAgent,
|
|
1597
|
+
retryThrottledRequestMaxTimes,
|
|
1598
|
+
retryNetworkErrorMaxTimes,
|
|
1599
|
+
contentType,
|
|
1600
|
+
multipartChunkSize,
|
|
1601
|
+
baseCDN,
|
|
1602
|
+
checkForUrlDuplicates,
|
|
1603
|
+
saveUrlForRecurrentUploads
|
|
1604
|
+
}).then((fileInfo) => fileInfo.uuid);
|
|
1605
|
+
}
|
|
1606
|
+
else {
|
|
1607
|
+
// Do not request file info by uuid before creating group because this isn't necessary
|
|
1608
|
+
return file;
|
|
1609
|
+
}
|
|
1610
|
+
})).then((uuids) => {
|
|
1598
1611
|
return group(uuids, {
|
|
1599
1612
|
publicKey,
|
|
1600
1613
|
baseURL,
|
|
@@ -1608,7 +1621,7 @@ function uploadFileGroup(data, { publicKey, fileName, baseURL = defaultSettings.
|
|
|
1608
1621
|
retryThrottledRequestMaxTimes,
|
|
1609
1622
|
retryNetworkErrorMaxTimes
|
|
1610
1623
|
})
|
|
1611
|
-
.then((groupInfo) => new UploadcareGroup(groupInfo,
|
|
1624
|
+
.then((groupInfo) => new UploadcareGroup(groupInfo, { baseCDN }))
|
|
1612
1625
|
.then((group) => {
|
|
1613
1626
|
onProgress && onProgress({ isComputable: true, value: 1 });
|
|
1614
1627
|
return group;
|
|
@@ -1676,35 +1689,39 @@ class UploadClient {
|
|
|
1676
1689
|
const settings = this.getSettings();
|
|
1677
1690
|
return uploadFileGroup(data, populateOptionsWithSettings(options, settings));
|
|
1678
1691
|
}
|
|
1692
|
+
isReadyPoll(uuid, options = {}) {
|
|
1693
|
+
const settings = this.getSettings();
|
|
1694
|
+
return isReadyPoll(uuid, populateOptionsWithSettings(options, settings));
|
|
1695
|
+
}
|
|
1679
1696
|
}
|
|
1680
1697
|
|
|
1681
1698
|
class Queue {
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1699
|
+
_concurrency = 1;
|
|
1700
|
+
_pending = [];
|
|
1701
|
+
_running = 0;
|
|
1702
|
+
_resolvers = new Map();
|
|
1703
|
+
_rejectors = new Map();
|
|
1687
1704
|
constructor(concurrency) {
|
|
1688
|
-
this
|
|
1705
|
+
this._concurrency = concurrency;
|
|
1689
1706
|
}
|
|
1690
|
-
|
|
1691
|
-
const tasksLeft = this
|
|
1707
|
+
_run() {
|
|
1708
|
+
const tasksLeft = this._concurrency - this._running;
|
|
1692
1709
|
for (let i = 0; i < tasksLeft; i++) {
|
|
1693
|
-
const task = this
|
|
1710
|
+
const task = this._pending.shift();
|
|
1694
1711
|
if (!task) {
|
|
1695
1712
|
return;
|
|
1696
1713
|
}
|
|
1697
|
-
const resolver = this
|
|
1698
|
-
const rejector = this
|
|
1714
|
+
const resolver = this._resolvers.get(task);
|
|
1715
|
+
const rejector = this._rejectors.get(task);
|
|
1699
1716
|
if (!resolver || !rejector)
|
|
1700
1717
|
throw new Error('Unexpected behavior: resolver or rejector is undefined');
|
|
1701
|
-
this
|
|
1718
|
+
this._running += 1;
|
|
1702
1719
|
task()
|
|
1703
1720
|
.finally(() => {
|
|
1704
|
-
this
|
|
1705
|
-
this
|
|
1706
|
-
this
|
|
1707
|
-
this
|
|
1721
|
+
this._resolvers.delete(task);
|
|
1722
|
+
this._rejectors.delete(task);
|
|
1723
|
+
this._running -= 1;
|
|
1724
|
+
this._run();
|
|
1708
1725
|
})
|
|
1709
1726
|
.then((value) => resolver(value))
|
|
1710
1727
|
.catch((error) => rejector(error));
|
|
@@ -1712,25 +1729,25 @@ class Queue {
|
|
|
1712
1729
|
}
|
|
1713
1730
|
add(task) {
|
|
1714
1731
|
return new Promise((resolve, reject) => {
|
|
1715
|
-
this
|
|
1716
|
-
this
|
|
1717
|
-
this
|
|
1718
|
-
this
|
|
1732
|
+
this._resolvers.set(task, resolve);
|
|
1733
|
+
this._rejectors.set(task, reject);
|
|
1734
|
+
this._pending.push(task);
|
|
1735
|
+
this._run();
|
|
1719
1736
|
});
|
|
1720
1737
|
}
|
|
1721
1738
|
get pending() {
|
|
1722
|
-
return this
|
|
1739
|
+
return this._pending.length;
|
|
1723
1740
|
}
|
|
1724
1741
|
get running() {
|
|
1725
|
-
return this
|
|
1742
|
+
return this._running;
|
|
1726
1743
|
}
|
|
1727
1744
|
set concurrency(value) {
|
|
1728
|
-
this
|
|
1729
|
-
this
|
|
1745
|
+
this._concurrency = value;
|
|
1746
|
+
this._run();
|
|
1730
1747
|
}
|
|
1731
1748
|
get concurrency() {
|
|
1732
|
-
return this
|
|
1749
|
+
return this._concurrency;
|
|
1733
1750
|
}
|
|
1734
1751
|
}
|
|
1735
1752
|
|
|
1736
|
-
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 };
|
|
1753
|
+
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 };
|