@visulima/storage 1.0.9 → 1.0.10
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/CHANGELOG.md +7 -0
- package/dist/adapter/nuxt/module.d.ts +8 -8
- package/dist/ai/ai-sdk/index.d.ts +51 -59
- package/dist/ai/claude/index.d.ts +104 -119
- package/dist/ai/openai/index.d.ts +86 -99
- package/dist/ai/tanstack/index.d.ts +53 -61
- package/dist/handler/http/fetch/index.d.ts +201 -201
- package/dist/handler/http/hono/index.d.ts +59 -59
- package/dist/handler/http/nextjs/index.d.ts +54 -54
- package/dist/handler/http/node/index.d.ts +233 -246
- package/dist/handler/http/solid-start/index.d.ts +54 -54
- package/dist/index.d.ts +70 -70
- package/dist/index.js +1 -1
- package/dist/packem_shared/{AwsLightStorage-BK-WPL0h.js → AwsLightStorage-EsqkAtU5.js} +1 -1
- package/dist/packem_shared/{AzureStorage-1UvDIQZd.js → AzureStorage-DL-U7qFG.js} +1 -1
- package/dist/packem_shared/BoxMetaStorage-CHWrhgg2.js +1 -0
- package/dist/packem_shared/{BoxStorage-DbGqBLux.js → BoxStorage-B8_oCz27.js} +1 -1
- package/dist/packem_shared/BunS3MetaStorage-CHWrhgg2.js +1 -0
- package/dist/packem_shared/{BunS3Storage-DNvimm9e.js → BunS3Storage-_PVXu_na.js} +1 -1
- package/dist/packem_shared/BunnyMetaStorage-CHWrhgg2.js +1 -0
- package/dist/packem_shared/{BunnyStorage-C7d0opLL.js → BunnyStorage-BsoWjScH.js} +1 -1
- package/dist/packem_shared/CloudinaryMetaStorage-BI9YXcwU.js +1 -0
- package/dist/packem_shared/{CloudinaryStorage-Dc3XA2lP.js → CloudinaryStorage-BNwiLF9V.js} +1 -1
- package/dist/packem_shared/{DiskStorage-CI07TVNu.js → DiskStorage-D-NtQDms.js} +1 -1
- package/dist/packem_shared/{DiskStorageWithChecksum-vFCubS6K.js → DiskStorageWithChecksum-UnCtyEvs.js} +1 -1
- package/dist/packem_shared/DropboxMetaStorage-CHWrhgg2.js +1 -0
- package/dist/packem_shared/{DropboxStorage-CY9Ggu3m.js → DropboxStorage-BS9kj0nH.js} +1 -1
- package/dist/packem_shared/FirebaseMetaStorage-BI9YXcwU.js +1 -0
- package/dist/packem_shared/{FirebaseStorage-D6O9CJXN.js → FirebaseStorage-DNquii2p.js} +1 -1
- package/dist/packem_shared/FtpMetaStorage-CHWrhgg2.js +1 -0
- package/dist/packem_shared/{FtpStorage-DbEjbq8z.js → FtpStorage-Bd004--s.js} +1 -1
- package/dist/packem_shared/{GCSMetaStorage-DT8K6zdm.js → GCSMetaStorage-Bf4qDFB1.js} +1 -1
- package/dist/packem_shared/{GCStorage-6BHkFlEs.js → GCStorage-ChqEpgqR.js} +1 -1
- package/dist/packem_shared/GoogleDriveMetaStorage-xlHfKwmR.js +1 -0
- package/dist/packem_shared/{GoogleDriveStorage-Bklsz7Bh.js → GoogleDriveStorage-v1glykjd.js} +1 -1
- package/dist/packem_shared/{LocalMetaStorage-BhicZnNl.js → LocalMetaStorage-YWPBYEe7.js} +1 -1
- package/dist/packem_shared/NetlifyBlobMetaStorage-BI9YXcwU.js +1 -0
- package/dist/packem_shared/{NetlifyBlobStorage-CkpCCoN1.js → NetlifyBlobStorage-BPyEWSnx.js} +1 -1
- package/dist/packem_shared/OneDriveMetaStorage-xlHfKwmR.js +1 -0
- package/dist/packem_shared/{OneDriveStorage-CP6MvGAa.js → OneDriveStorage-BJ3Kzxc5.js} +1 -1
- package/dist/packem_shared/PocketBaseMetaStorage-DnrxOQhO.js +1 -0
- package/dist/packem_shared/{PocketBaseStorage-2qhbI2PW.js → PocketBaseStorage-DqKHbbvn.js} +1 -1
- package/dist/packem_shared/{S3Storage-YGeNk3Tt.js → S3Storage-BiI2k6d1.js} +1 -1
- package/dist/packem_shared/SftpMetaStorage-CHWrhgg2.js +1 -0
- package/dist/packem_shared/{SftpStorage-2Hz396Xr.js → SftpStorage-w8XdtZtw.js} +1 -1
- package/dist/packem_shared/SharePointMetaStorage-CHWrhgg2.js +1 -0
- package/dist/packem_shared/{SharePointStorage-CrX2Pk6C.js → SharePointStorage-DpDpI7Ln.js} +1 -1
- package/dist/packem_shared/SupabaseMetaStorage-xlHfKwmR.js +1 -0
- package/dist/packem_shared/{SupabaseStorage-Dc_DBX29.js → SupabaseStorage-B_ugUCs7.js} +1 -1
- package/dist/packem_shared/UploadThingMetaStorage-BI9YXcwU.js +1 -0
- package/dist/packem_shared/{UploadThingStorage-BChykYSe.js → UploadThingStorage-_H45IVqX.js} +1 -1
- package/dist/packem_shared/VercelBlobMetaStorage-CHWrhgg2.js +1 -0
- package/dist/packem_shared/{VercelBlobStorage-CsRyPfw3.js → VercelBlobStorage-U1YMKeHs.js} +1 -1
- package/dist/packem_shared/{approval.d-CMAYH9GF.d.ts → approval.d-C-d-t94D.d.ts} +6 -6
- package/dist/packem_shared/disk-storage-BwPk2IRa.js +1 -0
- package/dist/packem_shared/disk-storage-with-checksum.d-CQucFacO.d.ts +146 -0
- package/dist/packem_shared/{executors.d-BZP2rWo3.d.ts → executors.d-DeDH3Ilt.d.ts} +2 -2
- package/dist/packem_shared/files.d-D8H_ge9Y.d.ts +655 -0
- package/dist/packem_shared/{gcs-meta-storage-B7BnctnV.js → gcs-meta-storage-DQGu_cHq.js} +1 -1
- package/dist/packem_shared/local-meta-storage-DJDcuxf1.js +11 -0
- package/dist/packem_shared/{local-meta-storage.d-D9PBfkn6.d.ts → local-meta-storage.d-DuTEzyii.d.ts} +7 -7
- package/dist/packem_shared/media-transformer.d-CvMFjINm.d.ts +331 -0
- package/dist/packem_shared/{memory-storage.d-4EU1cMt1.d.ts → memory-storage.d-BRdTiY8y.d.ts} +32 -40
- package/dist/packem_shared/{s3-base-storage-BoTyhuzO.js → s3-base-storage-CMUui93V.js} +1 -1
- package/dist/packem_shared/{s3-base-storage.d-BQgP5B-t.d.ts → s3-base-storage.d-Cg7m4FuH.d.ts} +64 -70
- package/dist/packem_shared/storage.d-DIav_lF1.d.ts +1163 -0
- package/dist/packem_shared/tus-base.d-BiEg5t4t.d.ts +102 -0
- package/dist/packem_shared/{types.d-CrUWY4On.d.ts → types.d-CAAzKiI6.d.ts} +134 -134
- package/dist/packem_shared/types.d-DgHhkCAl.d.ts +104 -0
- package/dist/packem_shared/{types.d-CggTCgXr.d.ts → types.d-jAs_Rp_v.d.ts} +3 -3
- package/dist/storage/aws/clients/index.d.ts +388 -388
- package/dist/storage/aws/index.d.ts +109 -113
- package/dist/storage/aws/index.js +1 -1
- package/dist/storage/aws-light/index.d.ts +63 -67
- package/dist/storage/aws-light/index.js +1 -1
- package/dist/storage/azure/index.d.ts +133 -139
- package/dist/storage/azure/index.js +1 -1
- package/dist/storage/box/index.d.ts +88 -92
- package/dist/storage/box/index.js +1 -1
- package/dist/storage/bun-s3/index.d.ts +70 -76
- package/dist/storage/bun-s3/index.js +1 -1
- package/dist/storage/bunny/index.d.ts +51 -55
- package/dist/storage/bunny/index.js +1 -1
- package/dist/storage/cloudinary/index.d.ts +53 -59
- package/dist/storage/cloudinary/index.js +1 -1
- package/dist/storage/dropbox/index.d.ts +58 -62
- package/dist/storage/dropbox/index.js +1 -1
- package/dist/storage/firebase/index.d.ts +73 -79
- package/dist/storage/firebase/index.js +1 -1
- package/dist/storage/ftp/index.d.ts +37 -43
- package/dist/storage/ftp/index.js +1 -1
- package/dist/storage/gcs/index.d.ts +89 -95
- package/dist/storage/gcs/index.js +1 -1
- package/dist/storage/google-drive/index.d.ts +68 -72
- package/dist/storage/google-drive/index.js +1 -1
- package/dist/storage/local/index.d.ts +3 -3
- package/dist/storage/local/index.js +1 -1
- package/dist/storage/memory/index.d.ts +2 -2
- package/dist/storage/netlify-blob/index.d.ts +85 -93
- package/dist/storage/netlify-blob/index.js +1 -1
- package/dist/storage/onedrive/index.d.ts +43 -53
- package/dist/storage/onedrive/index.js +1 -1
- package/dist/storage/pocketbase/index.d.ts +66 -72
- package/dist/storage/pocketbase/index.js +1 -1
- package/dist/storage/sftp/index.d.ts +39 -45
- package/dist/storage/sftp/index.js +1 -1
- package/dist/storage/sharepoint/index.d.ts +95 -95
- package/dist/storage/sharepoint/index.js +1 -1
- package/dist/storage/supabase/index.d.ts +49 -55
- package/dist/storage/supabase/index.js +1 -1
- package/dist/storage/uploadthing/index.d.ts +33 -37
- package/dist/storage/uploadthing/index.js +1 -1
- package/dist/storage/vercel-blob/index.d.ts +109 -115
- package/dist/storage/vercel-blob/index.js +1 -1
- package/dist/transformer/audio-transformer.d.ts +96 -96
- package/dist/transformer/image-transformer.d.ts +422 -422
- package/dist/transformer/index.d.ts +34 -34
- package/dist/transformer/video-transformer.d.ts +111 -111
- package/package.json +1 -1
- package/dist/packem_shared/BoxMetaStorage-BSn6Qfnf.js +0 -1
- package/dist/packem_shared/BunS3MetaStorage-BSn6Qfnf.js +0 -1
- package/dist/packem_shared/BunnyMetaStorage-BSn6Qfnf.js +0 -1
- package/dist/packem_shared/CloudinaryMetaStorage-DPVnmNe5.js +0 -1
- package/dist/packem_shared/DropboxMetaStorage-BSn6Qfnf.js +0 -1
- package/dist/packem_shared/FirebaseMetaStorage-DPVnmNe5.js +0 -1
- package/dist/packem_shared/FtpMetaStorage-BSn6Qfnf.js +0 -1
- package/dist/packem_shared/GoogleDriveMetaStorage-Cbwa1CHV.js +0 -1
- package/dist/packem_shared/NetlifyBlobMetaStorage-DPVnmNe5.js +0 -1
- package/dist/packem_shared/OneDriveMetaStorage-Cbwa1CHV.js +0 -1
- package/dist/packem_shared/PocketBaseMetaStorage-DOTLwVE7.js +0 -1
- package/dist/packem_shared/SftpMetaStorage-BSn6Qfnf.js +0 -1
- package/dist/packem_shared/SharePointMetaStorage-BSn6Qfnf.js +0 -1
- package/dist/packem_shared/SupabaseMetaStorage-Cbwa1CHV.js +0 -1
- package/dist/packem_shared/UploadThingMetaStorage-DPVnmNe5.js +0 -1
- package/dist/packem_shared/VercelBlobMetaStorage-BSn6Qfnf.js +0 -1
- package/dist/packem_shared/disk-storage-CsQcYW3s.js +0 -1
- package/dist/packem_shared/disk-storage-with-checksum.d-B-VGEsfl.d.ts +0 -156
- package/dist/packem_shared/files.d-CH0iLBNC.d.ts +0 -655
- package/dist/packem_shared/local-meta-storage-iuJnu90B.js +0 -11
- package/dist/packem_shared/media-transformer.d-Quf4ai47.d.ts +0 -331
- package/dist/packem_shared/storage.d-CEM1upWM.d.ts +0 -1176
- package/dist/packem_shared/tus-base.d-DLzKE54M.d.ts +0 -106
- package/dist/packem_shared/types.d-Bon9GVVe.d.ts +0 -104
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
export { type d as AudioChannelMixOptions, type c as AudioResampleOptions, type e as AudioTransformOptions, type b as AudioTransformResult, type f as AudioTransformationStep, type A as AudioTransformerConfig, B as BaseTransformer, type C as CropOptions, type h as ImageFormat, type I as ImageTransformerConfig, type U as MediaTransformQuery, type a as MediaTransformResult, type W as MediaTransformationStep, type M as MediaTransformerConfig, type R as ResizeOptions, type g as RotateOptions, type i as TransformOptions, type T as TransformResult, type z as TransformationStep, type K as VideoCropOptions, type H as VideoResizeOptions, type N as VideoRotateOptions, type O as VideoTransformOptions, type F as VideoTransformResult, type Q as VideoTransformationStep, type V as VideoTransformerConfig } from "../packem_shared/types.d-
|
|
2
|
-
export { M as MediaTransformer } from "../packem_shared/media-transformer.d-
|
|
3
|
-
import { g as FileReturn } from "../packem_shared/storage.d-
|
|
1
|
+
export { type d as AudioChannelMixOptions, type c as AudioResampleOptions, type e as AudioTransformOptions, type b as AudioTransformResult, type f as AudioTransformationStep, type A as AudioTransformerConfig, B as BaseTransformer, type C as CropOptions, type h as ImageFormat, type I as ImageTransformerConfig, type U as MediaTransformQuery, type a as MediaTransformResult, type W as MediaTransformationStep, type M as MediaTransformerConfig, type R as ResizeOptions, type g as RotateOptions, type i as TransformOptions, type T as TransformResult, type z as TransformationStep, type K as VideoCropOptions, type H as VideoResizeOptions, type N as VideoRotateOptions, type O as VideoTransformOptions, type F as VideoTransformResult, type Q as VideoTransformationStep, type V as VideoTransformerConfig } from "../packem_shared/types.d-CAAzKiI6.js";
|
|
2
|
+
export { M as MediaTransformer } from "../packem_shared/media-transformer.d-CvMFjINm.js";
|
|
3
|
+
import { g as FileReturn } from "../packem_shared/storage.d-DIav_lF1.js";
|
|
4
4
|
import 'node:stream';
|
|
5
5
|
import 'node:crypto';
|
|
6
6
|
import 'node:http';
|
|
7
7
|
import 'lru-cache';
|
|
8
8
|
/**
|
|
9
|
-
* Check if a content type is valid for a specific media type.
|
|
10
|
-
* @param contentType MIME content type string to validate
|
|
11
|
-
* @param expectedType Expected media type ('image', 'video', or 'audio')
|
|
12
|
-
* @returns True if the content type is valid for the expected media type
|
|
13
|
-
*/
|
|
9
|
+
* Check if a content type is valid for a specific media type.
|
|
10
|
+
* @param contentType MIME content type string to validate
|
|
11
|
+
* @param expectedType Expected media type ('image', 'video', or 'audio')
|
|
12
|
+
* @returns True if the content type is valid for the expected media type
|
|
13
|
+
*/
|
|
14
14
|
declare const isValidMediaType: (contentType: string | undefined, expectedType: "image" | "video" | "audio") => boolean;
|
|
15
15
|
/**
|
|
16
|
-
* Get format (extension) from content type using mime package.
|
|
17
|
-
* @param contentType MIME content type string to extract format from
|
|
18
|
-
* @returns Format string or undefined if not found
|
|
19
|
-
*/
|
|
16
|
+
* Get format (extension) from content type using mime package.
|
|
17
|
+
* @param contentType MIME content type string to extract format from
|
|
18
|
+
* @returns Format string or undefined if not found
|
|
19
|
+
*/
|
|
20
20
|
declare const getFormatFromContentType: (contentType: string | undefined) => string | undefined;
|
|
21
21
|
/**
|
|
22
|
-
* Validate a media file for a specific type with size and format checks.
|
|
23
|
-
* @param file File to validate
|
|
24
|
-
* @param expectedType Expected media type ('image', 'video', or 'audio')
|
|
25
|
-
* @param config Validation configuration with optional maxSize and supportedFormats
|
|
26
|
-
* @param config.maxSize Maximum allowed file size in bytes
|
|
27
|
-
* @param config.supportedFormats Array of supported file formats
|
|
28
|
-
* @throws Error if validation fails (size exceeded, wrong type, or unsupported format)
|
|
29
|
-
*/
|
|
22
|
+
* Validate a media file for a specific type with size and format checks.
|
|
23
|
+
* @param file File to validate
|
|
24
|
+
* @param expectedType Expected media type ('image', 'video', or 'audio')
|
|
25
|
+
* @param config Validation configuration with optional maxSize and supportedFormats
|
|
26
|
+
* @param config.maxSize Maximum allowed file size in bytes
|
|
27
|
+
* @param config.supportedFormats Array of supported file formats
|
|
28
|
+
* @throws Error if validation fails (size exceeded, wrong type, or unsupported format)
|
|
29
|
+
*/
|
|
30
30
|
declare const validateMediaFile: (file: FileReturn, expectedType: "image" | "video" | "audio", config?: {
|
|
31
31
|
maxSize?: number;
|
|
32
32
|
supportedFormats?: string[];
|
|
33
33
|
}) => void;
|
|
34
34
|
/**
|
|
35
|
-
* Validate that a content type is known and supported by the mime package.
|
|
36
|
-
* @param contentType MIME content type string to check
|
|
37
|
-
* @returns True if the content type is known and has a registered extension
|
|
38
|
-
*/
|
|
35
|
+
* Validate that a content type is known and supported by the mime package.
|
|
36
|
+
* @param contentType MIME content type string to check
|
|
37
|
+
* @returns True if the content type is known and has a registered extension
|
|
38
|
+
*/
|
|
39
39
|
declare const isKnownContentType: (contentType: string | undefined) => boolean;
|
|
40
40
|
/**
|
|
41
|
-
* Custom error class for validation failures
|
|
42
|
-
*/
|
|
41
|
+
* Custom error class for validation failures
|
|
42
|
+
*/
|
|
43
43
|
declare class ValidationError extends Error {
|
|
44
44
|
readonly code: string;
|
|
45
45
|
readonly details: {
|
|
@@ -49,14 +49,14 @@ declare class ValidationError extends Error {
|
|
|
49
49
|
validParams: string[];
|
|
50
50
|
};
|
|
51
51
|
/**
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
52
|
+
* Creates a new ValidationError instance with detailed error information.
|
|
53
|
+
* @param message Human-readable error message describing the validation failure
|
|
54
|
+
* @param code Machine-readable error code for programmatic error handling
|
|
55
|
+
* @param mediaType The media type where validation failed ('image', 'video', or 'audio')
|
|
56
|
+
* @param invalidParameters Array of parameter names that were invalid
|
|
57
|
+
* @param validParameters Array of valid parameter names or values
|
|
58
|
+
* @param suggestions Optional array of suggested corrections or valid values
|
|
59
|
+
*/
|
|
60
60
|
constructor(message: string, code: string, mediaType: string, invalidParameters: string[], validParameters: string[], suggestions?: string[]);
|
|
61
61
|
}
|
|
62
62
|
export { ValidationError, getFormatFromContentType, isKnownContentType, isValidMediaType, validateMediaFile };
|
|
@@ -1,147 +1,147 @@
|
|
|
1
|
-
import { F as File, g as FileReturn, B as BaseStorage } from "../packem_shared/storage.d-
|
|
2
|
-
import { V as VideoTransformerConfig, F as VideoTransformResult, H as VideoResizeOptions, K as VideoCropOptions, N as VideoRotateOptions, O as VideoTransformOptions, Q as VideoTransformationStep, B as BaseTransformer } from "../packem_shared/types.d-
|
|
1
|
+
import { F as File, g as FileReturn, B as BaseStorage } from "../packem_shared/storage.d-DIav_lF1.js";
|
|
2
|
+
import { V as VideoTransformerConfig, F as VideoTransformResult, H as VideoResizeOptions, K as VideoCropOptions, N as VideoRotateOptions, O as VideoTransformOptions, Q as VideoTransformationStep, B as BaseTransformer } from "../packem_shared/types.d-CAAzKiI6.js";
|
|
3
3
|
import 'node:stream';
|
|
4
4
|
import 'node:crypto';
|
|
5
5
|
import 'node:http';
|
|
6
6
|
import 'lru-cache';
|
|
7
7
|
/**
|
|
8
|
-
* Video transformer that uses storage backends and Mediabunny library to retrieve and transform videos.
|
|
9
|
-
* @template TFile The file type used by this transformer.
|
|
10
|
-
* @template TFileReturn The return type for file retrieval operations.
|
|
11
|
-
*
|
|
12
|
-
* Supports video transformations with query parameters for on-demand video processing.
|
|
13
|
-
* @example
|
|
14
|
-
* ```ts
|
|
15
|
-
* const transformer = new VideoTransformer(storage, {
|
|
16
|
-
* maxVideoSize: 100 * 1024 * 1024, // 100MB
|
|
17
|
-
* cache: new Map()
|
|
18
|
-
* });
|
|
19
|
-
*
|
|
20
|
-
* // Programmatic usage - resize a video
|
|
21
|
-
* const result = await transformer.resize('video-id', {
|
|
22
|
-
* width: 1920,
|
|
23
|
-
* height: 1080,
|
|
24
|
-
* fit: 'contain'
|
|
25
|
-
* });
|
|
26
|
-
*
|
|
27
|
-
* // URL-based transformations
|
|
28
|
-
* // GET /files/video-id?width=1280&height=720&fit=cover&bitrate=2000000
|
|
29
|
-
* // GET /files/video-id?codec=vp9&bitrate=1000000
|
|
30
|
-
* ```
|
|
31
|
-
*
|
|
32
|
-
* ## Supported Query Parameters
|
|
33
|
-
*
|
|
34
|
-
* - `width`: Width in pixels (Number)
|
|
35
|
-
* - `height`: Height in pixels (Number)
|
|
36
|
-
* - `fit`: Resize fit mode - cover/contain/fill/inside/outside
|
|
37
|
-
* - `codec`: Video codec - avc/hevc/vp8/vp9/av1
|
|
38
|
-
* - `bitrate`: Video bitrate in bits per second (Number)
|
|
39
|
-
* - `frameRate`: Frame rate in Hz (Number)
|
|
40
|
-
* - `format`: Output format - mp4/webm/mkv/ogg
|
|
41
|
-
*/
|
|
8
|
+
* Video transformer that uses storage backends and Mediabunny library to retrieve and transform videos.
|
|
9
|
+
* @template TFile The file type used by this transformer.
|
|
10
|
+
* @template TFileReturn The return type for file retrieval operations.
|
|
11
|
+
*
|
|
12
|
+
* Supports video transformations with query parameters for on-demand video processing.
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const transformer = new VideoTransformer(storage, {
|
|
16
|
+
* maxVideoSize: 100 * 1024 * 1024, // 100MB
|
|
17
|
+
* cache: new Map()
|
|
18
|
+
* });
|
|
19
|
+
*
|
|
20
|
+
* // Programmatic usage - resize a video
|
|
21
|
+
* const result = await transformer.resize('video-id', {
|
|
22
|
+
* width: 1920,
|
|
23
|
+
* height: 1080,
|
|
24
|
+
* fit: 'contain'
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* // URL-based transformations
|
|
28
|
+
* // GET /files/video-id?width=1280&height=720&fit=cover&bitrate=2000000
|
|
29
|
+
* // GET /files/video-id?codec=vp9&bitrate=1000000
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* ## Supported Query Parameters
|
|
33
|
+
*
|
|
34
|
+
* - `width`: Width in pixels (Number)
|
|
35
|
+
* - `height`: Height in pixels (Number)
|
|
36
|
+
* - `fit`: Resize fit mode - cover/contain/fill/inside/outside
|
|
37
|
+
* - `codec`: Video codec - avc/hevc/vp8/vp9/av1
|
|
38
|
+
* - `bitrate`: Video bitrate in bits per second (Number)
|
|
39
|
+
* - `frameRate`: Frame rate in Hz (Number)
|
|
40
|
+
* - `format`: Output format - mp4/webm/mkv/ogg
|
|
41
|
+
*/
|
|
42
42
|
declare class VideoTransformer<TFile extends File = File, TFileReturn extends FileReturn = FileReturn> extends BaseTransformer<VideoTransformerConfig, VideoTransformResult<TFileReturn>, TFile, TFileReturn> {
|
|
43
43
|
/**
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
44
|
+
* Creates a new VideoTransformer instance.
|
|
45
|
+
* @param storage The storage backend for retrieving and storing video files.
|
|
46
|
+
* @param config Configuration options for video transformation including cache settings, codec defaults, and size limits.
|
|
47
|
+
*/
|
|
48
48
|
constructor(storage: BaseStorage<TFile, TFileReturn>, config?: VideoTransformerConfig);
|
|
49
49
|
/**
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
* Resizes a video to specified dimensions with optional fit mode.
|
|
51
|
+
* @param fileId Unique identifier of the video file to resize.
|
|
52
|
+
* @param options Resize options including width, height, and fit mode.
|
|
53
|
+
* @returns Promise resolving to transformed video result.
|
|
54
|
+
*/
|
|
55
55
|
resize(fileId: string, options: VideoResizeOptions): Promise<VideoTransformResult<TFileReturn>>;
|
|
56
56
|
/**
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
* Crops a video to the specified region.
|
|
58
|
+
* @param fileId Unique identifier of the video file to crop.
|
|
59
|
+
* @param options Crop options including region coordinates.
|
|
60
|
+
* @returns Promise resolving to transformed video result.
|
|
61
|
+
*/
|
|
62
62
|
crop(fileId: string, options: VideoCropOptions): Promise<VideoTransformResult<TFileReturn>>;
|
|
63
63
|
/**
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
64
|
+
* Rotates a video by the specified angle.
|
|
65
|
+
* @param fileId Unique identifier of the video file to rotate.
|
|
66
|
+
* @param options Rotation configuration with angle in degrees and optional background color.
|
|
67
|
+
* @returns Promise resolving to transformed video result.
|
|
68
|
+
*/
|
|
69
69
|
rotate(fileId: string, options: VideoRotateOptions): Promise<VideoTransformResult<TFileReturn>>;
|
|
70
70
|
/**
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
71
|
+
* Converts video format or codec.
|
|
72
|
+
* @param fileId Unique identifier of the video file to convert.
|
|
73
|
+
* @param format Target video format (e.g., "mp4", "webm", "mkv").
|
|
74
|
+
* @param options Video transformation options including quality, bitrate, and codec settings.
|
|
75
|
+
* @returns Promise resolving to transformed video result with updated format metadata.
|
|
76
|
+
*/
|
|
77
77
|
convertFormat(fileId: string, format: string, options?: VideoTransformOptions): Promise<VideoTransformResult<TFileReturn>>;
|
|
78
78
|
/**
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
79
|
+
* Transcodes video to different codec.
|
|
80
|
+
* @param fileId Unique identifier of the video file to transcode.
|
|
81
|
+
* @param codec Target video codec (e.g., "avc", "hevc", "vp9").
|
|
82
|
+
* @param options Additional transform options.
|
|
83
|
+
* @returns Promise resolving to transformed video result.
|
|
84
|
+
*/
|
|
85
85
|
transcode(fileId: string, codec: VideoTransformOptions["codec"], options?: Omit<VideoTransformOptions, "codec">): Promise<VideoTransformResult<TFileReturn>>;
|
|
86
86
|
/**
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
87
|
+
* Applies a custom transformation pipeline to a video.
|
|
88
|
+
* @param fileId Unique identifier of the video file to transform.
|
|
89
|
+
* @param steps Array of transformation steps to apply in sequence.
|
|
90
|
+
* @returns Promise resolving to transformed video result.
|
|
91
|
+
*/
|
|
92
92
|
transform(fileId: string, steps: VideoTransformationStep[]): Promise<VideoTransformResult<TFileReturn>>;
|
|
93
93
|
/**
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
94
|
+
* Applies multiple transformations in sequence using Mediabunny.
|
|
95
|
+
* @param buffer The original video buffer.
|
|
96
|
+
* @param steps Array of video transformation steps to apply.
|
|
97
|
+
* @returns Promise resolving to transformed video buffer.
|
|
98
|
+
* @private
|
|
99
|
+
*/
|
|
100
100
|
private applyTransformations;
|
|
101
101
|
/**
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
102
|
+
* Converts transformation steps to Mediabunny video options.
|
|
103
|
+
* @param steps Array of video transformation steps to convert.
|
|
104
|
+
* @returns Mediabunny video options object for conversion.
|
|
105
|
+
* @private
|
|
106
|
+
*/
|
|
107
107
|
private stepsToVideoOptions;
|
|
108
108
|
/**
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
109
|
+
* Determines output format based on transformation steps.
|
|
110
|
+
* @param steps Array of video transformation steps.
|
|
111
|
+
* @returns Mediabunny output format instance (defaults to MP4).
|
|
112
|
+
* @private
|
|
113
|
+
*/
|
|
114
114
|
private determineOutputFormat;
|
|
115
115
|
/**
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
116
|
+
* Converts format string to Mediabunny output format.
|
|
117
|
+
* @param format Video format string (mp4, webm, mkv, ogg).
|
|
118
|
+
* @returns Mediabunny output format instance.
|
|
119
|
+
* @private
|
|
120
|
+
*/
|
|
121
121
|
private formatStringToOutputFormat;
|
|
122
122
|
/**
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
123
|
+
* Validates that the file is a supported video.
|
|
124
|
+
* @param file The file to validate.
|
|
125
|
+
* @returns Promise that resolves if validation passes.
|
|
126
|
+
* @throws Error if file size exceeds limits, wrong content type, unsupported format, or invalid video.
|
|
127
|
+
* @private
|
|
128
|
+
*/
|
|
129
129
|
private validateVideo;
|
|
130
130
|
/**
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
131
|
+
* Creates transformation result with metadata.
|
|
132
|
+
* @param buffer The transformed video buffer.
|
|
133
|
+
* @param originalFile The original file information.
|
|
134
|
+
* @returns Video transformation result with metadata.
|
|
135
|
+
* @private
|
|
136
|
+
*/
|
|
137
137
|
private createTransformResult;
|
|
138
138
|
/**
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
139
|
+
* Generates cache key for transformation.
|
|
140
|
+
* @param fileId The file identifier.
|
|
141
|
+
* @param steps Array of transformation steps.
|
|
142
|
+
* @returns Unique cache key string.
|
|
143
|
+
* @private
|
|
144
|
+
*/
|
|
145
145
|
private generateCacheKey;
|
|
146
146
|
}
|
|
147
147
|
export { VideoTransformer as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@visulima/storage",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.10",
|
|
4
4
|
"description": "Server-side file-storage abstraction - store files in a web-accessible location via a simplified API. Includes S3, Azure, GCS, local filesystem and 20+ other backends with TUS/multipart/REST upload handlers and the most convenient features of each.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"anolilab",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{y as r}from"./local-meta-storage-iuJnu90B.js";class o extends r{constructor(e){super(e)}}export{o as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{y as r}from"./local-meta-storage-iuJnu90B.js";class o extends r{constructor(e){super(e)}}export{o as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{y as r}from"./local-meta-storage-iuJnu90B.js";class o extends r{constructor(e){super(e)}}export{o as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{y as s}from"./local-meta-storage-iuJnu90B.js";class o extends s{constructor(r){super(r)}}export{o as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{y as r}from"./local-meta-storage-iuJnu90B.js";class o extends r{constructor(e){super(e)}}export{o as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{y as s}from"./local-meta-storage-iuJnu90B.js";class o extends s{constructor(r){super(r)}}export{o as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{y as r}from"./local-meta-storage-iuJnu90B.js";class o extends r{constructor(e){super(e)}}export{o as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{y as r}from"./local-meta-storage-iuJnu90B.js";class o extends r{constructor(t){super(t)}}export{o as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{y as s}from"./local-meta-storage-iuJnu90B.js";class o extends s{constructor(r){super(r)}}export{o as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{y as r}from"./local-meta-storage-iuJnu90B.js";class o extends r{constructor(t){super(t)}}export{o as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{y as r}from"./local-meta-storage-iuJnu90B.js";class e extends r{constructor(o){super(o)}}export{e as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{y as r}from"./local-meta-storage-iuJnu90B.js";class o extends r{constructor(e){super(e)}}export{o as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{y as r}from"./local-meta-storage-iuJnu90B.js";class o extends r{constructor(e){super(e)}}export{o as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{y as r}from"./local-meta-storage-iuJnu90B.js";class o extends r{constructor(t){super(t)}}export{o as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{y as s}from"./local-meta-storage-iuJnu90B.js";class o extends s{constructor(r){super(r)}}export{o as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{y as r}from"./local-meta-storage-iuJnu90B.js";class o extends r{constructor(e){super(e)}}export{o as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{createReadStream as _,createWriteStream as C}from"node:fs";import{truncate as P,stat as F,open as L,copyFile as A}from"node:fs/promises";import{PassThrough as W,Transform as x,pipeline as U}from"node:stream";import{y as D,d as I,z as B,l as M,V,x as Q,f as H}from"./local-meta-storage-iuJnu90B.js";import{A as G,m as K}from"./path-0oTTdkvl-DvWvbDbh.js";import{F as X}from"./index-nZWCQrSe.js";import{d as Y}from"./detect-file-type-BA7UBLKA.js";import{throwErrorCode as g,ERRORS as h,isUploadError as q}from"./ERRORS-BIBxE2oR.js";import{createHash as j}from"node:crypto";import{B as J,a as Z,c as $}from"./storage-0j5nCAUp.js";import tt from"./File-W8aOo15X.js";import{t as k}from"./get-file-status-y3wTtDQs.js";import{t as et}from"./update-size-DuNuLyxj.js";import{i as rt}from"./part-match-D-9dGX42.js";import{e as it}from"./has-content-50BsqrWw.js";class st extends x{constructor(t,e,r="base64"){super(),this.checksum=t,this.algorithm=e,this.encoding=r,this.hash=j(e)}checksum;algorithm;encoding;length=0;digest="";hash;get calculatedDigest(){return this.digest}_transform(t,e,r){this.push(t),this.hash.update(t),this.length+=t.length,r()}_flush(t){this.digest=this.hash.digest(this.encoding),this.checksum&&this.checksum!==this.digest?t(new Error("Checksum mismatch")):t()}}const at=(S,t,e="base64")=>t?new st(S,t,e):new W;class nt extends x{constructor(t=Number.POSITIVE_INFINITY){super(),this.limit=t}limit;length=0;_transform(t,e,r){const a=this.length+t.length;this.limit>=a?(this.push(t),this.length=a,r()):r(new Error("Stream length limit exceeded"))}}class w extends J{static name="disk";checksumTypes=["md5","sha1"];supportsRange=!0;get raw(){return{directory:this.directory}}directory;meta;constructor(t){const e={...t,fileNameValidation:t.fileNameValidation??Z};if(super(e),this.directory=e.directory,e.metaStorage)this.meta=e.metaStorage;else{const r={...e,...e.metaStorageConfig,logger:this.logger};this.meta=new D(r)}this.isReady=!1,this.accessCheck().then(()=>{this.isReady=!0}).catch(r=>{this.logger?.error("Storage access check failed: %O",r)})}normalizeError(t){return super.normalizeError(t)}async create(t){return this.instrumentOperation("create",async()=>{const e={...t};if(t.ttl){const i=typeof t.ttl=="string"?$(t.ttl):t.ttl;i!==void 0&&(e.expiredAt=Date.now()+i)}e.size!==void 0&&Number(e.size)<0&&g(h.REQUEST_ENTITY_TOO_LARGE,"Request entity too large");const r=new tt(e);try{const i=await this.getMeta(r.id);if(i.status==="completed")return i}catch{}r.name=this.namingFunction(r),(r.size===void 0||Number.isNaN(r.size))&&(r.size===void 0||(r.size=this.maxUploadSize)),await this.validate(r);const a=this.getFilePath(r.name);try{await I(a),r.bytesWritten=0}catch(i){const s=this.normalizeError(i instanceof Error?i:new Error(String(i)));await this.onError(s),g(h.FILE_ERROR,s.message)}return r.status=k(r),await this.saveMeta(r),await this.onCreate(r),r})}async write(t){return this.instrumentOperation("write",async()=>{let e;if("contentType"in t&&"metadata"in t&&!("body"in t)&&!("start"in t)?e=t:(e=await this.getMeta(t.id),await this.checkIfExpired(e)),e.status==="completed")return e;if(t.size!==void 0&&et(e,t.size),!rt(t,e))return g(h.FILE_CONFLICT);const r=this.getFilePath(e.name),a=await this.lock(r);try{const i=t.start||0;if(await I(r),e.bytesWritten===0&&(e.bytesWritten=i),it(t)){if(this.isUnsupportedChecksum(t.checksumAlgorithm))return g(h.UNSUPPORTED_CHECKSUM_ALGORITHM);if((t.start===0||t.start===void 0)&&(e.bytesWritten===0||Number.isNaN(e.bytesWritten))&&(!e.contentType||e.contentType==="application/octet-stream"))try{const{fileType:u,stream:d}=await Y(t.body);u?.mime&&(e.contentType=u.mime),t.body=d}catch{}const s=t.signal,o={...e,...t,body:t.body};s&&(o.signal=s);const[n,m]=await this.lazyWrite(o);if(m)return await P(r,e.bytesWritten),g(m);const l=i+(t.contentLength||0);e.bytesWritten=Math.max(e.bytesWritten||0,l),e.bytesWritten=Math.max(e.bytesWritten||0,n),e.status=k(e),await this.saveMeta(e)}else await I(r),e.bytesWritten=0;return e}catch(i){if(q(i))throw i;const s=this.normalizeError(i instanceof Error?i:new Error(String(i)));return await this.onError(s),g(h.FILE_ERROR,(typeof s.message=="string"?s.message:String(i))||String(i))}finally{await this.unlock(r,a)}})}async get({id:t},e){return this.instrumentOperation("get",async()=>{const r=await this.checkIfExpired(await this.meta.get(t)),{bytesWritten:a,contentType:i,expiredAt:s,metadata:o,modifiedAt:n,name:m,originalName:l,size:u}=r,d=this.getFilePath(m),E=e?.range,b=async c=>{const y=c;if(y.code==="ENOENT"||y.code==="EPERM"){const p=this.normalizeError(c instanceof Error?c:new Error(y.message||String(c)));return await this.onError(p),g(h.FILE_NOT_FOUND,(typeof p.message=="string"?p.message:String(c))||String(c))}const f=this.normalizeError(c instanceof Error?c:new Error(String(c)));throw await this.onError(f),c};if(E){let c;try{c=await F(d)}catch(R){return b(R)}const y=c.size,f=Math.max(0,E.start),p=E.end===void 0?y-1:Math.min(y-1,E.end);if(f>p||f>=y)return g(h.BAD_REQUEST,`Invalid range ${f}-${E.end??""}`);const N=p-f+1,z=Buffer.allocUnsafe(N);let O;try{O=await L(d,"r"),await O.read(z,0,N,f)}catch(R){return b(R)}finally{await O?.close()}const v=`W/"${y.toString(16)}-${Math.trunc(c.mtimeMs).toString(16)}-${f}-${p}"`;return{content:z,contentType:i,ETag:v,expiredAt:s,id:t,metadata:o,modifiedAt:n,name:m,originalName:l,size:N}}let T;try{T=await B(d,{buffer:!0})}catch(c){return b(c)}return{content:T,contentType:i,ETag:X(T),expiredAt:s,id:t,metadata:o,modifiedAt:n,name:m,originalName:l,size:u||a}})}async exists({id:t}){return this.instrumentOperation("exists",async()=>{try{const e=await this.getMeta(t),r=this.getFilePath(e.name);return await F(r),!0}catch{return!1}})}async getStream({id:t}){return this.instrumentOperation("getStream",async()=>{try{const e=await this.checkIfExpired(await this.meta.get(t)),{bytesWritten:r,contentType:a,expiredAt:i,modifiedAt:s,name:o,size:n}=e,m=_(this.getFilePath(o));return{headers:{"Content-Length":String(n||r),"Content-Type":a,...i&&{"X-Upload-Expires":i.toString()},...s&&{"Last-Modified":s.toString()}},size:n||r,stream:m}}catch(e){const r=this.normalizeError(e instanceof Error?e:new Error(String(e)));throw await this.onError(r),g(h.FILE_NOT_FOUND,(typeof r.message=="string"?r.message:String(e))||String(e))}})}async delete({id:t}){return this.instrumentOperation("delete",async()=>{const e=await this.getMeta(t);await M(this.getFilePath(e.name)),await this.deleteMeta(t);const r={...e,status:"deleted"};return await this.onDelete(r),r})}async copy(t,e){return this.instrumentOperation("copy",async()=>{w.assertSafeId(t),w.assertSafeId(e);const r=await this.getMeta(t);return await A(this.getFilePath(r.name),this.getFilePath(e)),{...r,name:e}})}async move(t,e){return this.instrumentOperation("move",async()=>{w.assertSafeId(t),w.assertSafeId(e);const r=await this.getMeta(t),a=this.getFilePath(r.name),i=this.getFilePath(e);try{await V(a,i)}catch(s){if(s?.code==="EXDEV")await A(a,i),await M(a);else{const o=this.normalizeError(s instanceof Error?s:new Error(String(s)));throw await this.onError(o),s}}return{...r,id:r.id,name:e}})}async list(){return this.instrumentOperation("list",async()=>{const t={followSymlinks:!1,includeDirs:!1,includeFiles:!0,skip:["*.META$"]},e=[],{directory:r}=this,a=s=>s.replaceAll("\\","/"),i=a(r);for await(const s of Q(r,t)){const{suffix:o}=this.meta,{path:n}=s;if(!n.includes(o)){const{birthtime:m,ctime:l,mtime:u}=await F(n),d=a(n),E=d.startsWith(i)?d.slice(i.length):d;e.push({createdAt:m||l,id:E,modifiedAt:u})}}return e})}getFilePath(t){return w.assertSafeId(t),G(t)&&g(h.INVALID_FILE_NAME,`Invalid file id: "${t}"`),K(this.directory,t)}lazyWrite(t){return new Promise((e,r)=>{const a=C(this.getFilePath(t.name),{flags:"r+",start:t.start}),i=new nt(t.contentLength||t.size-t.start),s=at(t.checksum,t.checksumAlgorithm),o=!t.checksum,{signal:n}=t,m=()=>{a.close(),i.destroy(),s.destroy()},l=d=>{m(),e([Number.NaN,d])};if(i.on("error",()=>{l(h.FILE_CONFLICT)}),s.on("error",()=>{l(h.CHECKSUM_MISMATCH)}),t.body.on("aborted",()=>{l(o?void 0:h.REQUEST_ABORTED)}),t.body.on("error",d=>{m(),r(d)}),n?.aborted){l(o?void 0:h.REQUEST_ABORTED);return}let u;n&&(u=()=>{m(),a.destroy(),i.destroy(),s.destroy(),t.body.destroy(),e([Number.NaN,o?void 0:h.REQUEST_ABORTED])},n.addEventListener("abort",u,{once:!0})),U(t.body,i,s,a,d=>{if(n&&u&&n.removeEventListener("abort",u),d){if(m(),n?.aborted){e([Number.NaN,o?void 0:h.REQUEST_ABORTED]);return}e([Number.NaN,h.FILE_ERROR]);return}e([t.start+a.bytesWritten])})})}async accessCheck(){await H(this.directory)}}export{w as F,nt as n,at as s};
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import { F as File, M as MetaStorage, D as DiskStorageOptions, H as HttpError, d as FileInit, e as FilePart, f as FileQuery, O as OperationOptions, g as FileReturn, i as ERRORS, B as BaseStorage, j as DiskStorageWithChecksumOptions } from "./storage.d-CEM1upWM.js";
|
|
2
|
-
import { Readable } from 'node:stream';
|
|
3
|
-
/**
|
|
4
|
-
* Local disk-based storage implementation.
|
|
5
|
-
* @template TFile The file type used by this storage backend.
|
|
6
|
-
* @remarks
|
|
7
|
-
* ## Error Handling
|
|
8
|
-
* - Filesystem operations throw errors directly (no retry logic)
|
|
9
|
-
* - File not found errors are thrown immediately
|
|
10
|
-
* - Permission errors are propagated as-is
|
|
11
|
-
*
|
|
12
|
-
* ## Retry Behavior
|
|
13
|
-
* - No automatic retries (filesystem operations are typically immediate)
|
|
14
|
-
* - Errors are thrown directly for immediate feedback
|
|
15
|
-
*
|
|
16
|
-
* ## File Paths
|
|
17
|
-
* - Files are stored in the configured directory
|
|
18
|
-
* - Metadata files use the `.META` suffix by default
|
|
19
|
-
* - File paths are resolved relative to the storage directory
|
|
20
|
-
*/
|
|
21
|
-
declare class DiskStorage<TFile extends File = File> extends BaseStorage<TFile> {
|
|
22
|
-
static override readonly name: string;
|
|
23
|
-
override checksumTypes: string[];
|
|
24
|
-
override readonly supportsRange: boolean;
|
|
25
|
-
override get raw(): {
|
|
26
|
-
directory: string;
|
|
27
|
-
};
|
|
28
|
-
directory: string;
|
|
29
|
-
meta: MetaStorage<TFile>;
|
|
30
|
-
constructor(config: DiskStorageOptions<TFile>);
|
|
31
|
-
/**
|
|
32
|
-
* Normalizes errors with disk storage context.
|
|
33
|
-
* @param error The error to normalize.
|
|
34
|
-
* @returns Normalized HTTP error.
|
|
35
|
-
*/
|
|
36
|
-
override normalizeError(error: Error): HttpError;
|
|
37
|
-
/**
|
|
38
|
-
* Creates a new file upload and saves its metadata.
|
|
39
|
-
* @param fileInit File initialization configuration.
|
|
40
|
-
* @returns Promise resolving to the created file object.
|
|
41
|
-
* @throws {Error} If validation fails or file already exists and is completed.
|
|
42
|
-
* @remarks
|
|
43
|
-
* Supports TTL (time-to-live) option in fileInit.
|
|
44
|
-
* Creates the file on disk if it doesn't exist.
|
|
45
|
-
* Returns existing file if it's already completed.
|
|
46
|
-
*/
|
|
47
|
-
create(fileInit: FileInit): Promise<TFile>;
|
|
48
|
-
/**
|
|
49
|
-
* Writes data to a file upload.
|
|
50
|
-
* @param part File part containing data to write, file query, or full file object.
|
|
51
|
-
* @returns Promise resolving to the updated file object.
|
|
52
|
-
* @throws {Error} If file is expired (ERRORS.GONE), locked (ERRORS.FILE_LOCKED), or conflicts occur (ERRORS.FILE_CONFLICT).
|
|
53
|
-
* @remarks
|
|
54
|
-
* Supports chunked uploads with start position.
|
|
55
|
-
* Automatically detects file type from stream on first chunk if contentType is not set.
|
|
56
|
-
* Validates checksum algorithms if provided.
|
|
57
|
-
* Uses file locking to prevent concurrent writes.
|
|
58
|
-
* Updates file status to "completed" when all bytes are written.
|
|
59
|
-
*/
|
|
60
|
-
write(part: FilePart | FileQuery | TFile): Promise<TFile>;
|
|
61
|
-
/**
|
|
62
|
-
* Gets an uploaded file by ID.
|
|
63
|
-
* @param query File query containing the file ID to retrieve.
|
|
64
|
-
* @param query.id File ID to retrieve.
|
|
65
|
-
* @returns Promise resolving to the file data including content buffer.
|
|
66
|
-
* @throws {Error} If the file cannot be found (ERRORS.FILE_NOT_FOUND) or has expired (ERRORS.GONE).
|
|
67
|
-
* @remarks
|
|
68
|
-
* Loads the entire file content into memory as a Buffer.
|
|
69
|
-
* For large files, consider using getStream() instead.
|
|
70
|
-
* Includes ETag (MD5 hash) for content verification.
|
|
71
|
-
*/
|
|
72
|
-
get({
|
|
73
|
-
id
|
|
74
|
-
}: FileQuery, options?: OperationOptions & {
|
|
75
|
-
range?: {
|
|
76
|
-
end?: number;
|
|
77
|
-
start: number;
|
|
78
|
-
};
|
|
79
|
-
}): Promise<FileReturn>;
|
|
80
|
-
/**
|
|
81
|
-
* Checks if a file exists by verifying both metadata and the actual filesystem file.
|
|
82
|
-
* Returns true only if both the metadata and the file exist.
|
|
83
|
-
* @param query File query containing the file ID to check.
|
|
84
|
-
* @returns Promise resolving to true if both metadata and file exist, false otherwise.
|
|
85
|
-
*/
|
|
86
|
-
override exists({
|
|
87
|
-
id
|
|
88
|
-
}: FileQuery): Promise<boolean>;
|
|
89
|
-
/**
|
|
90
|
-
* Gets an uploaded file as a readable stream for efficient large file handling.
|
|
91
|
-
* @param query File query containing the file ID to stream.
|
|
92
|
-
* @param query.id File ID to stream.
|
|
93
|
-
* @returns Promise resolving to an object containing the stream, headers, and size.
|
|
94
|
-
* @throws {UploadError} If the file cannot be found (ERRORS.FILE_NOT_FOUND) or has expired (ERRORS.GONE).
|
|
95
|
-
* @remarks Creates a readable stream directly from the file system for efficient memory usage.
|
|
96
|
-
*/
|
|
97
|
-
override getStream({
|
|
98
|
-
id
|
|
99
|
-
}: FileQuery): Promise<{
|
|
100
|
-
headers?: Record<string, string>;
|
|
101
|
-
size?: number;
|
|
102
|
-
stream: Readable;
|
|
103
|
-
}>;
|
|
104
|
-
/**
|
|
105
|
-
* Deletes an upload and its metadata.
|
|
106
|
-
* @param query File query containing the file ID to delete.
|
|
107
|
-
* @param query.id File ID to delete.
|
|
108
|
-
* @returns Promise resolving to the deleted file object with status: "deleted".
|
|
109
|
-
* @throws {UploadError} If the file metadata cannot be found.
|
|
110
|
-
*/
|
|
111
|
-
delete({
|
|
112
|
-
id
|
|
113
|
-
}: FileQuery): Promise<TFile>;
|
|
114
|
-
/**
|
|
115
|
-
* Copies an upload file to a new location.
|
|
116
|
-
* @param name Source file name/ID.
|
|
117
|
-
* @param destination Destination file name/ID.
|
|
118
|
-
* @returns Promise resolving to the copied file object.
|
|
119
|
-
* @throws {UploadError} If the source file cannot be found.
|
|
120
|
-
*/
|
|
121
|
-
copy(name: string, destination: string): Promise<TFile>;
|
|
122
|
-
/**
|
|
123
|
-
* Moves an upload file to a new location.
|
|
124
|
-
* @param name Source file name/ID.
|
|
125
|
-
* @param destination Destination file name/ID.
|
|
126
|
-
* @returns Promise resolving to the moved file object.
|
|
127
|
-
* @throws {Error} If the source file cannot be found.
|
|
128
|
-
*/
|
|
129
|
-
move(name: string, destination: string): Promise<TFile>;
|
|
130
|
-
/**
|
|
131
|
-
* Retrieves a list of uploaded files.
|
|
132
|
-
* @returns Promise resolving to an array of file metadata objects.
|
|
133
|
-
* @remarks Walks the storage directory and returns all files, excluding metadata files.
|
|
134
|
-
*/
|
|
135
|
-
override list(): Promise<TFile[]>;
|
|
136
|
-
/**
|
|
137
|
-
* Returns the absolute on-disk path for the uploaded file, always rooted at
|
|
138
|
-
* `this.directory`. Absolute inputs and `..` traversals are rejected.
|
|
139
|
-
*/
|
|
140
|
-
protected getFilePath(filename: string): string;
|
|
141
|
-
protected lazyWrite(part: File & FilePart): Promise<[number, ERRORS?]>;
|
|
142
|
-
private accessCheck;
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Additionally calculates checksum of the file/range.
|
|
146
|
-
*/
|
|
147
|
-
declare class DiskStorageWithChecksum<TFile extends File = File> extends DiskStorage<TFile> {
|
|
148
|
-
private hashes;
|
|
149
|
-
constructor(config: DiskStorageWithChecksumOptions<TFile>);
|
|
150
|
-
override delete({
|
|
151
|
-
id
|
|
152
|
-
}: FileQuery): Promise<TFile>;
|
|
153
|
-
override write(part: FilePart | FileQuery): Promise<TFile>;
|
|
154
|
-
protected override lazyWrite(part: File & FilePart): Promise<[number, ERRORS?]>;
|
|
155
|
-
}
|
|
156
|
-
export { DiskStorage as D, DiskStorageWithChecksum as a };
|