@lykosjs/cloudinary 0.0.0-stage → 0.0.1
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/LICENSE +21 -0
- package/README.md +381 -2
- package/dist/cloudinary-manager.d.ts +17 -0
- package/dist/cloudinary-manager.js +51 -0
- package/dist/cloudinary-manager.js.map +1 -0
- package/dist/files/file-manager.d.ts +13 -0
- package/dist/files/file-manager.js +77 -0
- package/dist/files/file-manager.js.map +1 -0
- package/dist/files/file-type.d.ts +3 -0
- package/dist/files/file-type.js +10 -0
- package/dist/files/file-type.js.map +1 -0
- package/dist/files/types.d.ts +17 -0
- package/dist/files/types.js +5 -0
- package/dist/files/types.js.map +1 -0
- package/dist/images/image-manager.d.ts +26 -0
- package/dist/images/image-manager.js +210 -0
- package/dist/images/image-manager.js.map +1 -0
- package/dist/images/image-type.d.ts +6 -0
- package/dist/images/image-type.js +32 -0
- package/dist/images/image-type.js.map +1 -0
- package/dist/images/types.d.ts +43 -0
- package/dist/images/types.js +2 -0
- package/dist/images/types.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/shared/byte-utils.d.ts +1 -0
- package/dist/shared/byte-utils.js +2 -0
- package/dist/shared/byte-utils.js.map +1 -0
- package/dist/shared/concurrency.d.ts +12 -0
- package/dist/shared/concurrency.js +33 -0
- package/dist/shared/concurrency.js.map +1 -0
- package/dist/shared/destroy-batch.d.ts +10 -0
- package/dist/shared/destroy-batch.js +31 -0
- package/dist/shared/destroy-batch.js.map +1 -0
- package/dist/shared/destroy-resource.d.ts +5 -0
- package/dist/shared/destroy-resource.js +23 -0
- package/dist/shared/destroy-resource.js.map +1 -0
- package/dist/shared/error-message.d.ts +1 -0
- package/dist/shared/error-message.js +11 -0
- package/dist/shared/error-message.js.map +1 -0
- package/dist/shared/normalize-folder.d.ts +1 -0
- package/dist/shared/normalize-folder.js +22 -0
- package/dist/shared/normalize-folder.js.map +1 -0
- package/dist/shared/public-id.d.ts +10 -0
- package/dist/shared/public-id.js +49 -0
- package/dist/shared/public-id.js.map +1 -0
- package/dist/shared/upload-batch.d.ts +16 -0
- package/dist/shared/upload-batch.js +91 -0
- package/dist/shared/upload-batch.js.map +1 -0
- package/dist/shared/upload-stream.d.ts +13 -0
- package/dist/shared/upload-stream.js +36 -0
- package/dist/shared/upload-stream.js.map +1 -0
- package/dist/shared/validate-blob.d.ts +12 -0
- package/dist/shared/validate-blob.js +21 -0
- package/dist/shared/validate-blob.js.map +1 -0
- package/dist/types/config.d.ts +92 -0
- package/dist/types/config.js +54 -0
- package/dist/types/config.js.map +1 -0
- package/dist/videos/types.d.ts +20 -0
- package/dist/videos/types.js +2 -0
- package/dist/videos/types.js.map +1 -0
- package/dist/videos/video-manager.d.ts +13 -0
- package/dist/videos/video-manager.js +80 -0
- package/dist/videos/video-manager.js.map +1 -0
- package/dist/videos/video-type.d.ts +3 -0
- package/dist/videos/video-type.js +27 -0
- package/dist/videos/video-type.js.map +1 -0
- package/package.json +47 -4
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { HttpError } from 'lykosjs';
|
|
2
|
+
import { assertConcurrency, runWithConcurrency } from './concurrency';
|
|
3
|
+
/**
|
|
4
|
+
* Validates and uploads multiple files with limited concurrency.
|
|
5
|
+
*
|
|
6
|
+
* - Validates all files before starting uploads.
|
|
7
|
+
* - Stops scheduling new uploads after the first failure.
|
|
8
|
+
* - Waits for already running uploads to finish.
|
|
9
|
+
* - Removes successfully uploaded resources if an upload fails.
|
|
10
|
+
* - Preserves the original input order.
|
|
11
|
+
*/
|
|
12
|
+
export async function uploadBatch(files, concurrency, validate, upload, destroy) {
|
|
13
|
+
assertConcurrency(concurrency);
|
|
14
|
+
if (files.length === 0) {
|
|
15
|
+
throw new HttpError(400, 'At least one file is required');
|
|
16
|
+
}
|
|
17
|
+
// Reject sparse arrays and missing file entries.
|
|
18
|
+
for (let index = 0; index < files.length; index++) {
|
|
19
|
+
if (!(index in files) || files[index] == null) {
|
|
20
|
+
throw new HttpError(400, 'Invalid file entry in upload batch');
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
// Validate all files before starting uploads.
|
|
24
|
+
const validationFailures = [];
|
|
25
|
+
await runWithConcurrency(files.length, concurrency, async (index) => {
|
|
26
|
+
const file = files[index];
|
|
27
|
+
if (!file)
|
|
28
|
+
return;
|
|
29
|
+
try {
|
|
30
|
+
await validate(file);
|
|
31
|
+
}
|
|
32
|
+
catch (reason) {
|
|
33
|
+
validationFailures.push({ index, reason });
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
if (validationFailures.length > 0) {
|
|
37
|
+
validationFailures.sort((a, b) => a.index - b.index);
|
|
38
|
+
const firstFailure = validationFailures[0];
|
|
39
|
+
if (firstFailure) {
|
|
40
|
+
throw firstFailure.reason;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// Upload files while preserving their original indexes.
|
|
44
|
+
const results = new Array(files.length);
|
|
45
|
+
const uploadFailure = {
|
|
46
|
+
current: null,
|
|
47
|
+
};
|
|
48
|
+
await runWithConcurrency(files.length, concurrency, async (index) => {
|
|
49
|
+
const file = files[index];
|
|
50
|
+
if (!file)
|
|
51
|
+
return;
|
|
52
|
+
try {
|
|
53
|
+
results[index] = await upload(file);
|
|
54
|
+
}
|
|
55
|
+
catch (reason) {
|
|
56
|
+
const currentFailure = uploadFailure.current;
|
|
57
|
+
if (!currentFailure || index < currentFailure.index) {
|
|
58
|
+
uploadFailure.current = { index, reason };
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}, () => uploadFailure.current !== null);
|
|
62
|
+
const uploaded = results.filter((item) => item !== undefined);
|
|
63
|
+
const failure = uploadFailure.current;
|
|
64
|
+
if (!failure) {
|
|
65
|
+
return uploaded;
|
|
66
|
+
}
|
|
67
|
+
// Roll back successfully uploaded resources.
|
|
68
|
+
const cleanupFailures = [];
|
|
69
|
+
await runWithConcurrency(uploaded.length, concurrency, async (index) => {
|
|
70
|
+
const item = uploaded[index];
|
|
71
|
+
if (!item)
|
|
72
|
+
return;
|
|
73
|
+
try {
|
|
74
|
+
await destroy(item.publicId);
|
|
75
|
+
}
|
|
76
|
+
catch (reason) {
|
|
77
|
+
cleanupFailures.push({
|
|
78
|
+
publicId: item.publicId,
|
|
79
|
+
reason,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
if (cleanupFailures.length > 0) {
|
|
84
|
+
const cleanupErrors = cleanupFailures.map(({ publicId, reason }) => new Error(`Failed to remove resource "${publicId}"`, {
|
|
85
|
+
cause: reason,
|
|
86
|
+
}));
|
|
87
|
+
throw new AggregateError([failure.reason, ...cleanupErrors], 'Upload failed and some uploaded resources could not be removed');
|
|
88
|
+
}
|
|
89
|
+
throw failure.reason;
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=upload-batch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upload-batch.js","sourceRoot":"","sources":["../../src/shared/upload-batch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AACnC,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAarE;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,KAAsB,EACtB,WAAmB,EACnB,QAAyB,EACzB,MAA6B,EAC7B,OAAwB;IAExB,iBAAiB,CAAC,WAAW,CAAC,CAAA;IAE9B,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,MAAM,IAAI,SAAS,CAAC,GAAG,EAAE,+BAA+B,CAAC,CAAA;IAC3D,CAAC;IAED,iDAAiD;IACjD,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;QAClD,IAAI,CAAC,CAAC,KAAK,I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CAAC;QAC/B,MAAM,aAAa,GAAG,eAAe,CAAC,GAAG,CACvC,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,CACvB,IAAI,KAAK,CAAC,8BAA8B,QAAQ,GAAG,EAAE;YACnD,KAAK,EAAE,MAAM;SACd,CAAC,CACL,CAAA;QAED,MAAM,IAAI,cAAc,CACtB,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,aAAa,CAAC,EAClC,gEAAgE,CACjE,CAAA;IACH,CAAC;IAED,MAAM,OAAO,CAAC,MAAM,CAAA;AACtB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { UploadApiOptions, UploadApiResponse } from 'cloudinary';
|
|
2
|
+
interface CloudinaryCredentials {
|
|
3
|
+
cloud_name: string;
|
|
4
|
+
api_key: string;
|
|
5
|
+
api_secret: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Uploads a Blob to Cloudinary through a stream.
|
|
9
|
+
*
|
|
10
|
+
* This avoids loading the entire file into a Buffer.
|
|
11
|
+
*/
|
|
12
|
+
export declare function uploadBlobStream(file: Blob, credentials: CloudinaryCredentials, options: UploadApiOptions): Promise<UploadApiResponse>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { v2 as cloudinary } from 'cloudinary';
|
|
2
|
+
import { Readable } from 'node:stream';
|
|
3
|
+
import { HttpError } from 'lykosjs';
|
|
4
|
+
/**
|
|
5
|
+
* Uploads a Blob to Cloudinary through a stream.
|
|
6
|
+
*
|
|
7
|
+
* This avoids loading the entire file into a Buffer.
|
|
8
|
+
*/
|
|
9
|
+
export function uploadBlobStream(file, credentials, options) {
|
|
10
|
+
return new Promise((resolve, reject) => {
|
|
11
|
+
const uploadStream = cloudinary.uploader.upload_stream({
|
|
12
|
+
...credentials,
|
|
13
|
+
...options,
|
|
14
|
+
}, (error, result) => {
|
|
15
|
+
if (error) {
|
|
16
|
+
reject(new HttpError(502, error.message || 'Cloudinary upload failed'));
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (!result) {
|
|
20
|
+
reject(new HttpError(502, 'Cloudinary returned an empty upload response'));
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
resolve(result);
|
|
24
|
+
});
|
|
25
|
+
const source = Readable.fromWeb(file.stream());
|
|
26
|
+
source.on('error', (error) => {
|
|
27
|
+
uploadStream.destroy(error);
|
|
28
|
+
});
|
|
29
|
+
uploadStream.on('error', (error) => {
|
|
30
|
+
source.destroy();
|
|
31
|
+
reject(new HttpError(502, error.message || 'Cloudinary upload stream failed'));
|
|
32
|
+
});
|
|
33
|
+
source.pipe(uploadStream);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=upload-stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upload-stream.js","sourceRoot":"","sources":["../../src/shared/upload-stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,IAAI,UAAU,EAAE,MAAM,YAAY,CAAA;AAE7C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAEtC,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAQnC;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAC9B,IAAU,EACV,WAAkC,EAClC,OAAyB;IAEzB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,YAAY,GAAG,UAAU,CAAC,QAAQ,CAAC,aAAa,CACpD;YACE,GAAG,WAAW;YACd,GAAG,OAAO;SACX,EACD,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;YAChB,IAAI,KAAK,EAAE,CAAC;gBACV,MAAM,CAAC,IAAI,SAAS,CAAC,GAAG,EAAE,KAAK,CAAC,OAAO,IAAI,0BAA0B,CAAC,CAAC,CAAA;gBACvE,OAAM;YACR,CAAC;YAED,IAAI,CAAC,MAAM,EAAE,CAAC;gBACZ,MAAM,CAAC,IAAI,SAAS,CAAC,GAAG,EAAE,8CAA8C,CAAC,CAAC,CAAA;gBAC1E,OAAM;YACR,CAAC;YAED,OAAO,CAAC,MAAM,CAAC,CAAA;QACjB,CAAC,CACF,CAAA;QAED,MAAM,MAAM,GAAG,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,EAAmC,CAAC,CAAA;QAE/E,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;YAC3B,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;QAC7B,CAAC,CAAC,CAAA;QAEF,YAAY,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;YACjC,MAAM,CAAC,OAAO,EAAE,CAAA;YAChB,MAAM,CAAC,IAAI,SAAS,CAAC,GAAG,EAAE,KAAK,CAAC,OAAO,IAAI,iCAAiC,CAAC,CAAC,CAAA;QAChF,CAAC,CAAC,CAAA;QAEF,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;IAC3B,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface ValidateBlobOptions<TType extends string> {
|
|
2
|
+
maxFileSize: number;
|
|
3
|
+
allowedTypes: readonly TType[];
|
|
4
|
+
detect: (bytes: Uint8Array) => TType | null;
|
|
5
|
+
label: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Validates a Blob's size and detects its actual content type.
|
|
9
|
+
*
|
|
10
|
+
* Reads only the first 32 bytes instead of loading the entire file.
|
|
11
|
+
*/
|
|
12
|
+
export declare function validateBlob<TType extends string>(file: Blob, rules: ValidateBlobOptions<TType>): Promise<TType>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { HttpError } from 'lykosjs';
|
|
2
|
+
/**
|
|
3
|
+
* Validates a Blob's size and detects its actual content type.
|
|
4
|
+
*
|
|
5
|
+
* Reads only the first 32 bytes instead of loading the entire file.
|
|
6
|
+
*/
|
|
7
|
+
export async function validateBlob(file, rules) {
|
|
8
|
+
if (file.size === 0) {
|
|
9
|
+
throw new HttpError(400, 'File is empty');
|
|
10
|
+
}
|
|
11
|
+
if (file.size > rules.maxFileSize) {
|
|
12
|
+
throw new HttpError(413, `File is too large (max ${rules.maxFileSize} bytes)`);
|
|
13
|
+
}
|
|
14
|
+
const header = new Uint8Array(await file.slice(0, 32).arrayBuffer());
|
|
15
|
+
const type = rules.detect(header);
|
|
16
|
+
if (!type || !rules.allowedTypes.includes(type)) {
|
|
17
|
+
throw new HttpError(415, `Unsupported ${rules.label} type`);
|
|
18
|
+
}
|
|
19
|
+
return type;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=validate-blob.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate-blob.js","sourceRoot":"","sources":["../../src/shared/validate-blob.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AASnC;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,IAAU,EACV,KAAiC;IAEjC,IAAI,IAAI,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;QACpB,MAAM,IAAI,SAAS,CAAC,GAAG,EAAE,eAAe,CAAC,CAAA;IAC3C,CAAC;IAED,IAAI,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC;QAClC,MAAM,IAAI,SAAS,CAAC,GAAG,EAAE,0BAA0B,KAAK,CAAC,WAAW,SAAS,CAAC,CAAA;IAChF,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC,CAAA;IAEpE,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;IAEjC,IAAI,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QAChD,MAAM,IAAI,SAAS,CAAC,GAAG,EAAE,eAAe,KAAK,CAAC,KAAK,OAAO,CAAC,CAAA;IAC7D,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { ImageMimeType } from '../images/types';
|
|
2
|
+
import type { FileMimeType } from '../files/types';
|
|
3
|
+
import type { VideoMimeType } from '../videos/types';
|
|
4
|
+
/**
|
|
5
|
+
* Cloudinary account credentials and image upload configuration.
|
|
6
|
+
*/
|
|
7
|
+
export interface CloudinaryManagerConfig {
|
|
8
|
+
cloudName: string;
|
|
9
|
+
apiKey: string;
|
|
10
|
+
apiSecret: string;
|
|
11
|
+
/**
|
|
12
|
+
* Maximum allowed image size in bytes.
|
|
13
|
+
* Defaults to 5 MB.
|
|
14
|
+
*/
|
|
15
|
+
maxFileSize?: number;
|
|
16
|
+
/**
|
|
17
|
+
* MIME types accepted for image uploads.
|
|
18
|
+
*/
|
|
19
|
+
allowedTypes?: readonly ImageMimeType[];
|
|
20
|
+
}
|
|
21
|
+
export interface CloudinaryCredentials {
|
|
22
|
+
cloud_name: string;
|
|
23
|
+
api_key: string;
|
|
24
|
+
api_secret: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Default maximum image upload size: 5 MB.
|
|
28
|
+
*/
|
|
29
|
+
export declare const DEFAULT_MAX_FILE_SIZE: number;
|
|
30
|
+
/**
|
|
31
|
+
* Default image MIME types.
|
|
32
|
+
*/
|
|
33
|
+
export declare const DEFAULT_ALLOWED_TYPES: readonly ImageMimeType[];
|
|
34
|
+
/**
|
|
35
|
+
* Default maximum raw file upload size: 10 MB.
|
|
36
|
+
*/
|
|
37
|
+
export declare const DEFAULT_MAX_FILE_BYTES: number;
|
|
38
|
+
/**
|
|
39
|
+
* Default raw file MIME types.
|
|
40
|
+
*/
|
|
41
|
+
export declare const DEFAULT_ALLOWED_FILE_TYPES: readonly FileMimeType[];
|
|
42
|
+
/**
|
|
43
|
+
* Default maximum video upload size: 100 MB.
|
|
44
|
+
*/
|
|
45
|
+
export declare const DEFAULT_MAX_VIDEO_BYTES: number;
|
|
46
|
+
/**
|
|
47
|
+
* Default video MIME types.
|
|
48
|
+
*/
|
|
49
|
+
export declare const DEFAULT_ALLOWED_VIDEO_TYPES: readonly VideoMimeType[];
|
|
50
|
+
/**
|
|
51
|
+
* Default concurrency for image and raw file batch uploads.
|
|
52
|
+
*/
|
|
53
|
+
export declare const DEFAULT_UPLOAD_CONCURRENCY = 3;
|
|
54
|
+
/**
|
|
55
|
+
* Default concurrency for video batch uploads.
|
|
56
|
+
*/
|
|
57
|
+
export declare const DEFAULT_VIDEO_CONCURRENCY = 2;
|
|
58
|
+
/**
|
|
59
|
+
* Default concurrency for batch deletions.
|
|
60
|
+
*/
|
|
61
|
+
export declare const DEFAULT_DESTROY_CONCURRENCY = 5;
|
|
62
|
+
/**
|
|
63
|
+
* Maximum allowed concurrency for batch operations.
|
|
64
|
+
*/
|
|
65
|
+
export declare const MAX_CONCURRENCY = 10;
|
|
66
|
+
export interface CloudinaryCredentials {
|
|
67
|
+
cloud_name: string;
|
|
68
|
+
api_key: string;
|
|
69
|
+
api_secret: string;
|
|
70
|
+
}
|
|
71
|
+
export interface CloudinaryManagerConfig {
|
|
72
|
+
cloudName: string;
|
|
73
|
+
apiKey: string;
|
|
74
|
+
apiSecret: string;
|
|
75
|
+
}
|
|
76
|
+
export interface CloudinaryManagerOptions {
|
|
77
|
+
images?: {
|
|
78
|
+
maxFileSize?: number;
|
|
79
|
+
allowedTypes?: readonly ImageMimeType[];
|
|
80
|
+
};
|
|
81
|
+
files?: {
|
|
82
|
+
maxFileSize?: number;
|
|
83
|
+
allowedTypes?: readonly FileMimeType[];
|
|
84
|
+
};
|
|
85
|
+
videos?: {
|
|
86
|
+
maxFileSize?: number;
|
|
87
|
+
allowedTypes?: readonly VideoMimeType[];
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
export interface DestroyManyOptions {
|
|
91
|
+
concurrency?: number;
|
|
92
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default maximum image upload size: 5 MB.
|
|
3
|
+
*/
|
|
4
|
+
export const DEFAULT_MAX_FILE_SIZE = 5 * 1024 * 1024;
|
|
5
|
+
/**
|
|
6
|
+
* Default image MIME types.
|
|
7
|
+
*/
|
|
8
|
+
export const DEFAULT_ALLOWED_TYPES = [
|
|
9
|
+
'image/jpeg',
|
|
10
|
+
'image/png',
|
|
11
|
+
'image/gif',
|
|
12
|
+
'image/webp',
|
|
13
|
+
'image/avif'
|
|
14
|
+
];
|
|
15
|
+
/**
|
|
16
|
+
* Default maximum raw file upload size: 10 MB.
|
|
17
|
+
*/
|
|
18
|
+
export const DEFAULT_MAX_FILE_BYTES = 10 * 1024 * 1024;
|
|
19
|
+
/**
|
|
20
|
+
* Default raw file MIME types.
|
|
21
|
+
*/
|
|
22
|
+
export const DEFAULT_ALLOWED_FILE_TYPES = [
|
|
23
|
+
'application/pdf',
|
|
24
|
+
'application/zip'
|
|
25
|
+
];
|
|
26
|
+
/**
|
|
27
|
+
* Default maximum video upload size: 100 MB.
|
|
28
|
+
*/
|
|
29
|
+
export const DEFAULT_MAX_VIDEO_BYTES = 100 * 1024 * 1024;
|
|
30
|
+
/**
|
|
31
|
+
* Default video MIME types.
|
|
32
|
+
*/
|
|
33
|
+
export const DEFAULT_ALLOWED_VIDEO_TYPES = [
|
|
34
|
+
'video/mp4',
|
|
35
|
+
'video/webm',
|
|
36
|
+
'video/quicktime'
|
|
37
|
+
];
|
|
38
|
+
/**
|
|
39
|
+
* Default concurrency for image and raw file batch uploads.
|
|
40
|
+
*/
|
|
41
|
+
export const DEFAULT_UPLOAD_CONCURRENCY = 3;
|
|
42
|
+
/**
|
|
43
|
+
* Default concurrency for video batch uploads.
|
|
44
|
+
*/
|
|
45
|
+
export const DEFAULT_VIDEO_CONCURRENCY = 2;
|
|
46
|
+
/**
|
|
47
|
+
* Default concurrency for batch deletions.
|
|
48
|
+
*/
|
|
49
|
+
export const DEFAULT_DESTROY_CONCURRENCY = 5;
|
|
50
|
+
/**
|
|
51
|
+
* Maximum allowed concurrency for batch operations.
|
|
52
|
+
*/
|
|
53
|
+
export const MAX_CONCURRENCY = 10;
|
|
54
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/types/config.ts"],"names":[],"mappings":"AA8BA;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAA;AAEpD;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAA6B;IAC9D,YAAY;IACZ,WAAW;IACX,WAAW;IACX,YAAY;IACZ,YAAY;CACZ,CAAA;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAA;AAEtD;;GAEG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAA4B;IAClE,iBAAiB;IACjB,iBAAiB;CACjB,CAAA;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,CAAA;AAExD;;GAEG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAA6B;IACpE,WAAW;IACX,YAAY;IACZ,iBAAiB;CACjB,CAAA;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,CAAA;AAE3C;;GAEG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,CAAA;AAE1C;;GAEG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,CAAA;AAE5C;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,EAAE,CAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type VideoMimeType = 'video/mp4' | 'video/webm' | 'video/quicktime';
|
|
2
|
+
export interface UploadedVideo {
|
|
3
|
+
url: string;
|
|
4
|
+
publicId: string;
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
format: string;
|
|
8
|
+
bytes: number;
|
|
9
|
+
/** Duration in seconds. */
|
|
10
|
+
duration: number;
|
|
11
|
+
}
|
|
12
|
+
export interface UploadVideoOptions {
|
|
13
|
+
publicId?: string;
|
|
14
|
+
tags?: string[];
|
|
15
|
+
maxFileSize?: number;
|
|
16
|
+
allowedTypes?: readonly VideoMimeType[];
|
|
17
|
+
}
|
|
18
|
+
export interface UploadVideosManyOptions extends Omit<UploadVideoOptions, 'publicId'> {
|
|
19
|
+
concurrency?: number;
|
|
20
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/videos/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { CloudinaryCredentials, CloudinaryManagerOptions, DestroyManyOptions } from '../types/config';
|
|
2
|
+
import type { UploadedVideo, UploadVideoOptions, UploadVideosManyOptions } from './types';
|
|
3
|
+
export declare class VideoManager {
|
|
4
|
+
private readonly credentials;
|
|
5
|
+
private readonly maxFileSize;
|
|
6
|
+
private readonly allowedTypes;
|
|
7
|
+
constructor(credentials: CloudinaryCredentials, options?: CloudinaryManagerOptions['videos']);
|
|
8
|
+
uploadVideo(file: Blob, folder: string, options?: UploadVideoOptions): Promise<UploadedVideo>;
|
|
9
|
+
uploadVideosMany(files: readonly Blob[], folder: string, options?: UploadVideosManyOptions): Promise<UploadedVideo[]>;
|
|
10
|
+
destroyVideo(publicId: string): Promise<void>;
|
|
11
|
+
destroyVideosMany(publicIds: readonly string[], options?: DestroyManyOptions): Promise<void>;
|
|
12
|
+
private validateVideo;
|
|
13
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { HttpError } from 'lykosjs';
|
|
2
|
+
import { normalizeFolder } from '../shared/normalize-folder';
|
|
3
|
+
import { isValidPublicId } from '../shared/public-id';
|
|
4
|
+
import { validateBlob } from '../shared/validate-blob';
|
|
5
|
+
import { uploadBlobStream } from '../shared/upload-stream';
|
|
6
|
+
import { uploadBatch } from '../shared/upload-batch';
|
|
7
|
+
import { destroyBatch } from '../shared/destroy-batch';
|
|
8
|
+
import { assertConcurrency } from '../shared/concurrency';
|
|
9
|
+
import { DEFAULT_ALLOWED_VIDEO_TYPES, DEFAULT_DESTROY_CONCURRENCY, DEFAULT_MAX_VIDEO_BYTES, DEFAULT_VIDEO_CONCURRENCY, } from '../types/config';
|
|
10
|
+
import { detectVideoType } from './video-type';
|
|
11
|
+
import { v2 as cloudinary } from 'cloudinary';
|
|
12
|
+
export class VideoManager {
|
|
13
|
+
credentials;
|
|
14
|
+
maxFileSize;
|
|
15
|
+
allowedTypes;
|
|
16
|
+
constructor(credentials, options = {}) {
|
|
17
|
+
this.credentials = credentials;
|
|
18
|
+
this.maxFileSize = options.maxFileSize ?? DEFAULT_MAX_VIDEO_BYTES;
|
|
19
|
+
this.allowedTypes = options.allowedTypes ?? DEFAULT_ALLOWED_VIDEO_TYPES;
|
|
20
|
+
}
|
|
21
|
+
async uploadVideo(file, folder, options = {}) {
|
|
22
|
+
const targetFolder = normalizeFolder(folder);
|
|
23
|
+
if (options.publicId !== undefined && !isValidPublicId(options.publicId)) {
|
|
24
|
+
throw new HttpError(400, 'Invalid public ID');
|
|
25
|
+
}
|
|
26
|
+
await this.validateVideo(file, options);
|
|
27
|
+
const result = await uploadBlobStream(file, this.credentials, {
|
|
28
|
+
folder: targetFolder,
|
|
29
|
+
resource_type: 'video',
|
|
30
|
+
...(options.publicId ? { public_id: options.publicId } : {}),
|
|
31
|
+
...(options.tags?.length ? { tags: options.tags } : {}),
|
|
32
|
+
});
|
|
33
|
+
return {
|
|
34
|
+
url: result.secure_url,
|
|
35
|
+
publicId: result.public_id,
|
|
36
|
+
width: result.width,
|
|
37
|
+
height: result.height,
|
|
38
|
+
format: result.format,
|
|
39
|
+
bytes: result.bytes,
|
|
40
|
+
duration: typeof result.duration === 'number' ? result.duration : 0,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
async uploadVideosMany(files, folder, options = {}) {
|
|
44
|
+
if (files.length === 0) {
|
|
45
|
+
throw new HttpError(400, 'At least one file is required');
|
|
46
|
+
}
|
|
47
|
+
const { concurrency = DEFAULT_VIDEO_CONCURRENCY, ...uploadOptions } = options;
|
|
48
|
+
assertConcurrency(concurrency);
|
|
49
|
+
normalizeFolder(folder);
|
|
50
|
+
return uploadBatch(files, concurrency, (file) => this.validateVideo(file, uploadOptions), (file) => this.uploadVideo(file, folder, uploadOptions), (publicId) => this.destroyVideo(publicId));
|
|
51
|
+
}
|
|
52
|
+
async destroyVideo(publicId) {
|
|
53
|
+
if (!publicId || typeof publicId !== 'string' || !publicId.trim()) {
|
|
54
|
+
throw new HttpError(400, 'Public ID is required');
|
|
55
|
+
}
|
|
56
|
+
const result = await cloudinary.uploader.destroy(publicId, {
|
|
57
|
+
...this.credentials,
|
|
58
|
+
resource_type: 'video',
|
|
59
|
+
invalidate: true,
|
|
60
|
+
});
|
|
61
|
+
if (result.result === 'not found') {
|
|
62
|
+
throw new HttpError(404, 'Video not found');
|
|
63
|
+
}
|
|
64
|
+
if (result.result !== 'ok') {
|
|
65
|
+
throw new HttpError(502, 'Failed to destroy video');
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
async destroyVideosMany(publicIds, options = {}) {
|
|
69
|
+
await destroyBatch(publicIds, options.concurrency ?? DEFAULT_DESTROY_CONCURRENCY, (publicId) => this.destroyVideo(publicId));
|
|
70
|
+
}
|
|
71
|
+
validateVideo(file, options) {
|
|
72
|
+
return validateBlob(file, {
|
|
73
|
+
maxFileSize: options.maxFileSize ?? this.maxFileSize,
|
|
74
|
+
allowedTypes: options.allowedTypes ?? this.allowedTypes,
|
|
75
|
+
detect: detectVideoType,
|
|
76
|
+
label: 'video',
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=video-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"video-manager.js","sourceRoot":"","sources":["../../src/videos/video-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAEnC,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AAEzD,OAAO,EACL,2BAA2B,EAC3B,2BAA2B,EAC3B,uBAAuB,EACvB,yBAAyB,GAC1B,MAAM,iBAAiB,CAAA;AAQxB,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAQ9C,OAAO,EAAE,EAAE,IAAI,UAAU,EAAE,MAAM,YAAY,CAAA;AAE7C,MAAM,OAAO,YAAY;IACN,WAAW,CAAuB;IAClC,WAAW,CAAQ;IACnB,YAAY,CAA0B;IAEvD,YACE,WAAkC,EAClC,OAAO,GAAuC,EAAE;QAEhD,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;QAE9B,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,uBAAuB,CAAA;QAEjE,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,2BAA2B,CAAA;IACzE,CAAC;IAED,KAAK,CAAC,WAAW,CACf,IAAU,EACV,MAAc,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KAAK,CAAC,iBAAiB,CACrB,SAA4B,EAC5B,OAAO,GAAuB,EAAE;QAEhC,MAAM,YAAY,CAAC,SAAS,EAAE,OAAO,CAAC,WAAW,IAAI,2BAA2B,EAAE,CAAC,QAAQ,EAAE,EAAE,CAC7F,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,CAC5B,CAAA;IACH,CAAC;IAEO,aAAa,CAAC,IAAU,EAAE,OAA2B;QAC3D,OAAO,YAAY,CAAC,IAAI,EAAE;YACxB,WAAW,EAAE,OAAO,CAAC,WAAW,IAAI,IAAI,CAAC,WAAW;YACpD,YAAY,EAAE,OAAO,CAAC,YAAY,IAAI,IAAI,CAAC,YAAY;YACvD,MAAM,EAAE,eAAe;YACvB,KAAK,EAAE,OAAO;SACf,CAAC,CAAA;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { startsWith } from '../shared/byte-utils';
|
|
2
|
+
/** Detects the real video type from the first bytes. */
|
|
3
|
+
export function detectVideoType(bytes) {
|
|
4
|
+
// WebM / Matroska (EBML header)
|
|
5
|
+
if (startsWith(bytes, [0x1a, 0x45, 0xdf, 0xa3]))
|
|
6
|
+
return 'video/webm';
|
|
7
|
+
// MP4 / MOV: "ftyp" at offset 4, brand at offset 8
|
|
8
|
+
if (startsWith(bytes, [0x66, 0x74, 0x79, 0x70], 4) && bytes.length >= 12) {
|
|
9
|
+
const brand = String.fromCharCode(...bytes.slice(8, 12));
|
|
10
|
+
if (IMAGE_BRANDS.has(brand))
|
|
11
|
+
return null;
|
|
12
|
+
return brand === 'qt ' ? 'video/quicktime' : 'video/mp4';
|
|
13
|
+
}
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
// ISO base media brands that belong to images, not video.
|
|
17
|
+
const IMAGE_BRANDS = new Set([
|
|
18
|
+
'avif',
|
|
19
|
+
'avis',
|
|
20
|
+
'heic',
|
|
21
|
+
'heix',
|
|
22
|
+
'heim',
|
|
23
|
+
'heis',
|
|
24
|
+
'mif1',
|
|
25
|
+
'msf1'
|
|
26
|
+
]);
|
|
27
|
+
//# sourceMappingURL=video-type.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"video-type.js","sourceRoot":"","sources":["../../src/videos/video-type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAGjD,wDAAwD;AACxD,MAAM,UAAU,eAAe,CAAC,KAAiB;IAChD,gCAAgC;IAChC,IAAI,UAAU,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;QAAE,OAAO,YAAY,CAAA;IAEpE,mDAAmD;IACnD,IAAI,UAAU,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,IAAI,EAAE,EAAE,CAAC;QAC1E,MAAM,KAAK,GAAG,MAAM,CAAC,YAAY,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA;QACxD,IAAI,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC;YAAE,OAAO,IAAI,CAAA;QACxC,OAAO,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,WAAW,CAAA;IAC1D,CAAC;IAED,OAAO,IAAI,CAAA;AACZ,CAAC;AAED,0DAA0D;AAC1D,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC;IAC5B,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;CACN,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lykosjs/cloudinary",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "A type-safe Cloudinary integration for uploading, managing, and deleting images, files, and videos in LykosJS applications",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Zen Allaham <zenallaham09@gmail.com> (https://zenallaham.com)",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"README.md",
|
|
19
|
+
"LICENSE"
|
|
20
|
+
],
|
|
21
|
+
"sideEffects": false,
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "tsc -p tsconfig.build.json",
|
|
24
|
+
"typecheck": "tsc --noEmit",
|
|
25
|
+
"test": "bun test",
|
|
26
|
+
"prepublishOnly": "bun run typecheck && bun test && bun run build"
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"lykosjs",
|
|
30
|
+
"cloudinary",
|
|
31
|
+
"image-upload",
|
|
32
|
+
"upload",
|
|
33
|
+
"images"
|
|
34
|
+
],
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"cloudinary": "^2.5.1"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"lykosjs": "^0.0.2"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@types/bun": "latest",
|
|
46
|
+
"lykosjs": "^0.0.2",
|
|
47
|
+
"typescript": "^7.0.2"
|
|
48
|
+
}
|
|
49
|
+
}
|