@visulima/storage 1.0.0-alpha.2 → 1.0.0-alpha.20
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 +252 -0
- package/LICENSE.md +1256 -512
- package/README.md +4 -4
- package/dist/adapter/nuxt/module.d.ts +41 -34
- package/dist/adapter/nuxt/module.js +1 -93
- package/dist/handler/http/fetch/index.d.ts +297 -4
- package/dist/handler/http/fetch/index.js +1 -4
- package/dist/handler/http/hono/index.d.ts +1474 -58
- package/dist/handler/http/hono/index.js +1 -65
- package/dist/handler/http/nextjs/index.d.ts +66 -58
- package/dist/handler/http/nextjs/index.js +1 -37
- package/dist/handler/http/node/index.d.ts +361 -4
- package/dist/handler/http/node/index.js +1 -4
- package/dist/handler/http/solid-start/index.d.ts +66 -57
- package/dist/handler/http/solid-start/index.js +1 -44
- package/dist/index.d.ts +376 -17
- package/dist/index.js +1 -13
- package/dist/openapi/index.d.ts +24 -5
- package/dist/openapi/index.js +1 -5
- package/dist/packem_shared/AwsLightFile-BTLiRxXj.js +1 -0
- package/dist/packem_shared/AwsLightMetaStorage-DHz1nf_H.js +1 -0
- package/dist/packem_shared/AwsLightStorage-CA9cdfJ6.js +1 -0
- package/dist/packem_shared/AzureFile-BKHru1zB.js +1 -0
- package/dist/packem_shared/AzureSMetaStorage-BqA4jUDJ.js +1 -0
- package/dist/packem_shared/AzureStorage-BKUjCymW.js +1 -0
- package/dist/packem_shared/BaseTransformer-D68eLyz1.js +1 -0
- package/dist/packem_shared/DiskStorage-DNjpDMX9.js +1 -0
- package/dist/packem_shared/DiskStorageWithChecksum-Bb6JX_tC.js +1 -0
- package/dist/packem_shared/ERRORS-B9jkvKwx.js +1 -0
- package/dist/packem_shared/File-alcSNpLq.js +1 -0
- package/dist/packem_shared/GCSConfig-BQ0OpVhe.js +1 -0
- package/dist/packem_shared/GCSFile-CHjX_fJk.js +1 -0
- package/dist/packem_shared/GCSMetaStorage-1UQIN9IN.js +1 -0
- package/dist/packem_shared/GCStorage-PJRb2WWC.js +1 -0
- package/dist/packem_shared/LocalMetaStorage-BWuFvWn4.js +1 -0
- package/dist/packem_shared/MediaTransformer-2C8MJeAg.js +1 -0
- package/dist/packem_shared/MetaStorage-Y4m1dWgd.js +1 -0
- package/dist/packem_shared/Metadata-B6Ir0KO7.js +1 -0
- package/dist/packem_shared/Multipart-Bd9YFFn0.js +1 -0
- package/dist/packem_shared/Multipart-D5bcEvga.js +1 -0
- package/dist/packem_shared/NetlifyBlobFile-CpzkMKng.js +1 -0
- package/dist/packem_shared/NetlifyBlobMetaStorage-dD0oBLom.js +1 -0
- package/dist/packem_shared/NetlifyBlobStorage-ByTwCN-h.js +1 -0
- package/dist/packem_shared/NoOpMetrics-Dky06sf1.js +1 -0
- package/dist/packem_shared/OpenTelemetryMetrics-9uxQMSlg.js +1 -0
- package/dist/packem_shared/Rest-CYEBbtCD.js +1 -0
- package/dist/packem_shared/Rest-DoonVU7B.js +1 -0
- package/dist/packem_shared/S3Client.d-CZ62Jztg.d.ts +20357 -0
- package/dist/packem_shared/S3File-Du6wP0Sz.js +1 -0
- package/dist/packem_shared/S3MetaStorage-vcriiosn.js +1 -0
- package/dist/packem_shared/S3Storage-Fx6-OSc-.js +1 -0
- package/dist/packem_shared/TUS_RESUMABLE-B7KtPVeC.js +1 -0
- package/dist/packem_shared/Tus-Bd_2Ki2G.js +1 -0
- package/dist/packem_shared/Tus-CUBCkuPE.js +1 -0
- package/dist/packem_shared/ValidationError-D8KKJiKA.js +1 -0
- package/dist/packem_shared/VercelBlobFile-CL9MjKcY.js +1 -0
- package/dist/packem_shared/VercelBlobMetaStorage-BsOTx-Su.js +1 -0
- package/dist/packem_shared/VercelBlobStorage-kNkk5Cn4.js +1 -0
- package/dist/packem_shared/_commonjsHelpers-D6W6KoPK.js +1 -0
- package/dist/packem_shared/aws-light-meta-storage-TPyQwLvk.js +4 -0
- package/dist/packem_shared/backblaze-DEflv87m.js +1 -0
- package/dist/packem_shared/base-handler-core-DaggCVsq.js +1 -0
- package/dist/packem_shared/base-handler-fetch-DnarP64X.js +1 -0
- package/dist/packem_shared/base-handler-node-BTes6sql.js +1 -0
- package/dist/packem_shared/cache-qV_5Umeq.js +1 -0
- package/dist/packem_shared/cloudflare-DLAeQvgD.js +1 -0
- package/dist/packem_shared/defaultCloudStorageFileNameValidation-yiM9GxHr.js +1 -0
- package/dist/packem_shared/digitalOcean-nhZUds87.js +1 -0
- package/dist/packem_shared/disk-storage-BvdK4bqF.js +5 -0
- package/dist/packem_shared/disk-storage-with-checksum.d-hEoe2ugb.d.ts +148 -0
- package/dist/packem_shared/gcs-meta-storage-DXqBZ3Xm.js +1 -0
- package/dist/packem_shared/has-content-Bx2p8Okx.js +1 -0
- package/dist/packem_shared/headers-DC2MEOrK.js +27 -0
- package/dist/packem_shared/is-expired-1JuZjDtb.js +1 -0
- package/dist/packem_shared/isRetryableError-DQNSZiBc.js +1 -0
- package/dist/packem_shared/isValidMediaType-B-2UKjZx.js +1 -0
- package/dist/packem_shared/local-meta-storage-Bkwqi_gi.js +1 -0
- package/dist/packem_shared/local-meta-storage.d-Dop9RP9k.d.ts +20 -0
- package/dist/packem_shared/media-transformer.d-LGdEjx6A.d.ts +331 -0
- package/dist/packem_shared/minio-BWwgGXeE.js +1 -0
- package/dist/packem_shared/multipart-base-C6OjBwMS.js +1 -0
- package/dist/packem_shared/part-match-DqD5U7An.js +1 -0
- package/dist/packem_shared/path-D7rMc9nq-B718mbm6.js +1 -0
- package/dist/packem_shared/response-builder-Wdo_fvcF.js +1 -0
- package/dist/packem_shared/rest-base-B2Dv7esY.js +1 -0
- package/dist/packem_shared/restOpenApiSpec-PaIVbESh.js +1 -0
- package/dist/packem_shared/s3-base-storage-xHZNtsGe.js +1 -0
- package/dist/packem_shared/s3-base-storage.d-CczjSe98.d.ts +251 -0
- package/dist/packem_shared/sharedGet-Ce7WGAsc.js +1 -0
- package/dist/packem_shared/storage-m_Cxgiih.js +1 -0
- package/dist/packem_shared/storage.d-BOMUJD96.d.ts +939 -0
- package/dist/packem_shared/tigris-DZoyrMNd.js +1 -0
- package/dist/packem_shared/transformOpenApiSpec-C0vEbDTO.js +1 -0
- package/dist/packem_shared/tus-base.d-C20dSee8.d.ts +99 -0
- package/dist/packem_shared/tusOpenApiSpec-DF0-hlWV.js +1 -0
- package/dist/packem_shared/types.d-B4hqF6yH.d.ts +708 -0
- package/dist/packem_shared/types.d-CNvyxOka.d.ts +49 -0
- package/dist/packem_shared/update-size-DANV7aa2.js +1 -0
- package/dist/packem_shared/validator-DK41xp8N.js +1 -0
- package/dist/packem_shared/waitForStorage-ChSBLhLc.js +1 -0
- package/dist/packem_shared/wasabi-Dmce4x9s.js +1 -0
- package/dist/packem_shared/xhrOpenApiSpec-nyoboz83.js +1 -0
- package/dist/storage/aws/clients/index.d.ts +166 -6
- package/dist/storage/aws/clients/index.js +1 -6
- package/dist/storage/aws/index.d.ts +320 -4
- package/dist/storage/aws/index.js +1 -3
- package/dist/storage/aws-light/index.d.ts +252 -4
- package/dist/storage/aws-light/index.js +1 -3
- package/dist/storage/azure/index.d.ts +10422 -4
- package/dist/storage/azure/index.js +1 -3
- package/dist/storage/gcs/index.d.ts +4107 -5
- package/dist/storage/gcs/index.js +1 -4
- package/dist/storage/local/index.d.ts +7 -4
- package/dist/storage/local/index.js +1 -3
- package/dist/storage/netlify-blob/index.d.ts +142 -4
- package/dist/storage/netlify-blob/index.js +1 -3
- package/dist/storage/vercel-blob/index.d.ts +129 -4
- package/dist/storage/vercel-blob/index.js +1 -3
- package/dist/transformer/audio-transformer.d.ts +127 -125
- package/dist/transformer/audio-transformer.js +1 -278
- package/dist/transformer/image-transformer.d.ts +569 -568
- package/dist/transformer/image-transformer.js +1 -1100
- package/dist/transformer/index.d.ts +62 -5
- package/dist/transformer/index.js +1 -4
- package/dist/transformer/video-transformer.d.ts +144 -142
- package/dist/transformer/video-transformer.js +1 -310
- package/package.json +60 -60
- package/dist/handler/base/base-handler-core.d.ts +0 -91
- package/dist/handler/base/base-handler-fetch.d.ts +0 -76
- package/dist/handler/base/base-handler-node.d.ts +0 -137
- package/dist/handler/multipart/multipart-base.d.ts +0 -84
- package/dist/handler/multipart/multipart-fetch.d.ts +0 -64
- package/dist/handler/multipart/multipart.d.ts +0 -49
- package/dist/handler/rest/rest-base.d.ts +0 -106
- package/dist/handler/rest/rest-fetch.d.ts +0 -88
- package/dist/handler/rest/rest.d.ts +0 -93
- package/dist/handler/tus/tus-base.d.ts +0 -152
- package/dist/handler/tus/tus-fetch.d.ts +0 -72
- package/dist/handler/tus/tus.d.ts +0 -78
- package/dist/handler/types.d.ts +0 -53
- package/dist/handler/utils/request-parser.d.ts +0 -72
- package/dist/handler/utils/response-builder.d.ts +0 -83
- package/dist/handler/utils/storage-utils.d.ts +0 -10
- package/dist/handler/utils/stream-utils.d.ts +0 -29
- package/dist/handler/utils/upload-handlers.d.ts +0 -76
- package/dist/metrics/index.d.ts +0 -2
- package/dist/metrics/no-op-metrics.d.ts +0 -15
- package/dist/metrics/opentelemetry-metrics.d.ts +0 -55
- package/dist/openapi/rest.d.ts +0 -7
- package/dist/openapi/shared.d.ts +0 -13
- package/dist/openapi/transform.d.ts +0 -3
- package/dist/openapi/tus.d.ts +0 -7
- package/dist/openapi/xhr.d.ts +0 -7
- package/dist/packem_shared/AwsLightFile-tTneXZgG.js +0 -11
- package/dist/packem_shared/AwsLightMetaStorage-BWSOtVaN.js +0 -4
- package/dist/packem_shared/AwsLightStorage-Cwkkc-z3.js +0 -133
- package/dist/packem_shared/AzureFile-CesgFzps.js +0 -8
- package/dist/packem_shared/AzureSMetaStorage-CFs-OYJT.js +0 -88
- package/dist/packem_shared/AzureStorage-9MoV2W8q.js +0 -357
- package/dist/packem_shared/BaseTransformer-C2gLib6v.js +0 -82
- package/dist/packem_shared/DiskStorage-CJtTzMQ3.js +0 -12
- package/dist/packem_shared/DiskStorageWithChecksum-BgrG8pvC.js +0 -238
- package/dist/packem_shared/ERRORS-D0apMqnc.js +0 -97
- package/dist/packem_shared/File-Bb3P23dr.js +0 -69
- package/dist/packem_shared/GCSConfig-vPP22kN6.js +0 -11
- package/dist/packem_shared/GCSFile-BIEunhAN.js +0 -8
- package/dist/packem_shared/GCSMetaStorage-sYiSjLUx.js +0 -7
- package/dist/packem_shared/GCStorage-DPl1_DAm.js +0 -406
- package/dist/packem_shared/LocalMetaStorage-CZHhKkMd.js +0 -7
- package/dist/packem_shared/MediaTransformer-D6658DL1.js +0 -1197
- package/dist/packem_shared/MetaStorage-pECeFOad.js +0 -46
- package/dist/packem_shared/Metadata-DRLXeJ0F.js +0 -89
- package/dist/packem_shared/Multipart-CNFK_Okz.js +0 -163
- package/dist/packem_shared/Multipart-CtUL7BQw.js +0 -128
- package/dist/packem_shared/NetlifyBlobFile-CXzyjqrD.js +0 -14
- package/dist/packem_shared/NetlifyBlobMetaStorage-DxZ5aDvD.js +0 -9
- package/dist/packem_shared/NetlifyBlobStorage-C6AX-X0P.js +0 -376
- package/dist/packem_shared/NoOpMetrics-DhAk5rXc.js +0 -10
- package/dist/packem_shared/OpenTelemetryMetrics-BnxhqIaH.js +0 -67
- package/dist/packem_shared/Rest-CAOAEkOj.js +0 -267
- package/dist/packem_shared/Rest-DNuLwBrK.js +0 -228
- package/dist/packem_shared/S3File-DZiyk9Qt.js +0 -11
- package/dist/packem_shared/S3MetaStorage-Dz9aDabA.js +0 -76
- package/dist/packem_shared/S3Storage-CgheE2yH.js +0 -316
- package/dist/packem_shared/TUS_RESUMABLE-GJzZ9R-f.js +0 -434
- package/dist/packem_shared/Tus-B8PmlMgR.js +0 -200
- package/dist/packem_shared/Tus-C4F1aYOl.js +0 -195
- package/dist/packem_shared/ValidationError-BfF1aE4h.js +0 -26
- package/dist/packem_shared/VercelBlobFile-BCg4aTEq.js +0 -18
- package/dist/packem_shared/VercelBlobMetaStorage-Bd9F-VFm.js +0 -9
- package/dist/packem_shared/VercelBlobStorage-BbuEYhOz.js +0 -261
- package/dist/packem_shared/_commonjsHelpers-B85MJLTf.js +0 -5
- package/dist/packem_shared/aws-light-meta-storage-DKJBgbR6.js +0 -446
- package/dist/packem_shared/backblaze-BlMnIcBC.js +0 -20
- package/dist/packem_shared/base-handler-core-BKuf4YLT.js +0 -303
- package/dist/packem_shared/base-handler-fetch-Cr0hLiqg.js +0 -291
- package/dist/packem_shared/base-handler-node-gk5aN9Cx.js +0 -730
- package/dist/packem_shared/cache-B88MXQ_2.js +0 -18
- package/dist/packem_shared/cloudflare-Bi1q8wXE.js +0 -21
- package/dist/packem_shared/defaultCloudStorageFileNameValidation-oVDgf-Sw.js +0 -11
- package/dist/packem_shared/digitalOcean-CWQRJM3L.js +0 -21
- package/dist/packem_shared/disk-storage-DkDoHnKB.js +0 -810
- package/dist/packem_shared/gcs-meta-storage-etw4wuh5.js +0 -158
- package/dist/packem_shared/has-content-CY66ehMK.js +0 -3
- package/dist/packem_shared/headers-DoS5nwM-.js +0 -3220
- package/dist/packem_shared/is-expired-CTThU1q5.js +0 -8
- package/dist/packem_shared/isRetryableError-Dycp7127.js +0 -82
- package/dist/packem_shared/isValidMediaType-BeDgiObq.js +0 -35
- package/dist/packem_shared/local-meta-storage-By-3SNBI.js +0 -649
- package/dist/packem_shared/minio-C2YBZQOw.js +0 -22
- package/dist/packem_shared/multipart-base-B3i67SSX.js +0 -102
- package/dist/packem_shared/part-match-BMNqHDYD.js +0 -96
- package/dist/packem_shared/path-CR6YkPXX-7R1-9CMk.js +0 -161
- package/dist/packem_shared/response-builder-BtnRiBUI.js +0 -45
- package/dist/packem_shared/rest-base-GRCcnan7.js +0 -457
- package/dist/packem_shared/restOpenApiSpec-CwcHHY2C.js +0 -800
- package/dist/packem_shared/s3-base-storage-xw6NJFX7.js +0 -510
- package/dist/packem_shared/sharedGet-Cpo7QUyu.js +0 -1019
- package/dist/packem_shared/storage-BwdYUHs3.js +0 -864
- package/dist/packem_shared/tigris-Hac8TKnX.js +0 -21
- package/dist/packem_shared/transformOpenApiSpec-DWM5WtnN.js +0 -975
- package/dist/packem_shared/tusOpenApiSpec-6ohiToBy.js +0 -740
- package/dist/packem_shared/update-size-CCGm6i1J.js +0 -8
- package/dist/packem_shared/validator-BeX_lJet.js +0 -78
- package/dist/packem_shared/waitForStorage-Cscw85sx.js +0 -18
- package/dist/packem_shared/wasabi-DIyflHSd.js +0 -21
- package/dist/packem_shared/xhrOpenApiSpec-DS17brnx.js +0 -264
- package/dist/storage/aws/clients/backblaze.d.ts +0 -12
- package/dist/storage/aws/clients/cloudflare.d.ts +0 -13
- package/dist/storage/aws/clients/digital-ocean.d.ts +0 -12
- package/dist/storage/aws/clients/minio.d.ts +0 -13
- package/dist/storage/aws/clients/tigris.d.ts +0 -12
- package/dist/storage/aws/clients/types.d.ts +0 -95
- package/dist/storage/aws/clients/wasabi.d.ts +0 -12
- package/dist/storage/aws/s3-base-storage.d.ts +0 -248
- package/dist/storage/aws/s3-client-adapter.d.ts +0 -110
- package/dist/storage/aws/s3-file.d.ts +0 -10
- package/dist/storage/aws/s3-meta-storage.d.ts +0 -15
- package/dist/storage/aws/s3-storage.d.ts +0 -70
- package/dist/storage/aws/types.d.ts +0 -119
- package/dist/storage/aws-light/aws-light-api-adapter.d.ts +0 -130
- package/dist/storage/aws-light/aws-light-file.d.ts +0 -10
- package/dist/storage/aws-light/aws-light-meta-storage.d.ts +0 -19
- package/dist/storage/aws-light/aws-light-storage.d.ts +0 -65
- package/dist/storage/aws-light/types.d.ts +0 -37
- package/dist/storage/azure/azure-file.d.ts +0 -6
- package/dist/storage/azure/azure-meta-storage.d.ts +0 -15
- package/dist/storage/azure/azure-storage.d.ts +0 -69
- package/dist/storage/azure/types.d.ts +0 -62
- package/dist/storage/gcs/fetch-error.d.ts +0 -11
- package/dist/storage/gcs/gcs-config.d.ts +0 -2
- package/dist/storage/gcs/gcs-file.d.ts +0 -6
- package/dist/storage/gcs/gcs-meta-storage.d.ts +0 -27
- package/dist/storage/gcs/gcs-storage.d.ts +0 -91
- package/dist/storage/gcs/types.d.ts +0 -55
- package/dist/storage/gcs/utils.d.ts +0 -7
- package/dist/storage/local/disk-storage-with-checksum.d.ts +0 -15
- package/dist/storage/local/disk-storage.d.ts +0 -135
- package/dist/storage/local/local-meta-storage.d.ts +0 -32
- package/dist/storage/meta-storage.d.ts +0 -30
- package/dist/storage/netlify-blob/netlify-blob-file.d.ts +0 -12
- package/dist/storage/netlify-blob/netlify-blob-meta-storage.d.ts +0 -7
- package/dist/storage/netlify-blob/netlify-blob-storage.d.ts +0 -93
- package/dist/storage/netlify-blob/types.d.ts +0 -30
- package/dist/storage/storage.d.ts +0 -353
- package/dist/storage/types.d.ts +0 -221
- package/dist/storage/utils/file/file.d.ts +0 -25
- package/dist/storage/utils/file/get-file-status.d.ts +0 -9
- package/dist/storage/utils/file/has-content.d.ts +0 -9
- package/dist/storage/utils/file/index.d.ts +0 -10
- package/dist/storage/utils/file/is-expired.d.ts +0 -8
- package/dist/storage/utils/file/metadata.d.ts +0 -18
- package/dist/storage/utils/file/part-match.d.ts +0 -11
- package/dist/storage/utils/file/types.d.ts +0 -37
- package/dist/storage/utils/file/update-metadata.d.ts +0 -10
- package/dist/storage/utils/file/update-size.d.ts +0 -10
- package/dist/storage/vercel-blob/types.d.ts +0 -32
- package/dist/storage/vercel-blob/vercel-blob-file.d.ts +0 -16
- package/dist/storage/vercel-blob/vercel-blob-meta-storage.d.ts +0 -7
- package/dist/storage/vercel-blob/vercel-blob-storage.d.ts +0 -76
- package/dist/transformer/base-transformer.d.ts +0 -63
- package/dist/transformer/media-transformer.d.ts +0 -332
- package/dist/transformer/types.d.ts +0 -652
- package/dist/transformer/utils.d.ts +0 -33
- package/dist/transformer/validation-error.d.ts +0 -23
- package/dist/utils/cache.d.ts +0 -32
- package/dist/utils/chunked-upload.d.ts +0 -65
- package/dist/utils/detect-file-type.d.ts +0 -28
- package/dist/utils/errors.d.ts +0 -74
- package/dist/utils/file-path-url-matcher.d.ts +0 -18
- package/dist/utils/headers.d.ts +0 -111
- package/dist/utils/http.d.ts +0 -92
- package/dist/utils/locker.d.ts +0 -26
- package/dist/utils/pipes/stream-checksum.d.ts +0 -47
- package/dist/utils/pipes/stream-length.d.ts +0 -22
- package/dist/utils/primitives/get-last-one.d.ts +0 -3
- package/dist/utils/primitives/is-record.d.ts +0 -2
- package/dist/utils/primitives/map-values.d.ts +0 -9
- package/dist/utils/primitives/pick.d.ts +0 -2
- package/dist/utils/primitives/to-milliseconds.d.ts +0 -12
- package/dist/utils/primitives/to-seconds.d.ts +0 -12
- package/dist/utils/range-checksum.d.ts +0 -33
- package/dist/utils/range-hasher.d.ts +0 -46
- package/dist/utils/retry.d.ts +0 -64
- package/dist/utils/types.d.ts +0 -108
- package/dist/utils/validation-error.d.ts +0 -22
- package/dist/utils/validator.d.ts +0 -36
|
@@ -1,310 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import BaseTransformer from '../packem_shared/BaseTransformer-C2gLib6v.js';
|
|
3
|
-
import { isValidMediaType, getFormatFromContentType } from '../packem_shared/isValidMediaType-BeDgiObq.js';
|
|
4
|
-
|
|
5
|
-
class VideoTransformer extends BaseTransformer {
|
|
6
|
-
/**
|
|
7
|
-
* Creates a new VideoTransformer instance.
|
|
8
|
-
* @param storage The storage backend for retrieving and storing video files.
|
|
9
|
-
* @param config Configuration options for video transformation including cache settings, codec defaults, and size limits.
|
|
10
|
-
*/
|
|
11
|
-
constructor(storage, config = {}) {
|
|
12
|
-
const logger = config.logger || storage.logger;
|
|
13
|
-
const transformerConfig = {
|
|
14
|
-
cacheTtl: 3600,
|
|
15
|
-
// 1 hour
|
|
16
|
-
defaultBitrate: 2e6,
|
|
17
|
-
// 2 Mbps
|
|
18
|
-
defaultCodec: "avc",
|
|
19
|
-
// No cache provided - no caching
|
|
20
|
-
maxCacheSize: 50,
|
|
21
|
-
// Max 50 transformed videos in cache
|
|
22
|
-
maxVideoSize: 500 * 1024 * 1024,
|
|
23
|
-
// 500MB
|
|
24
|
-
supportedFormats: ["mp4", "webm", "mkv", "avi", "mov", "flv", "wmv"],
|
|
25
|
-
...config
|
|
26
|
-
};
|
|
27
|
-
super(storage, transformerConfig, logger);
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Resizes a video to specified dimensions with optional fit mode.
|
|
31
|
-
* @param fileId Unique identifier of the video file to resize.
|
|
32
|
-
* @param options Resize options including width, height, and fit mode.
|
|
33
|
-
* @returns Promise resolving to transformed video result.
|
|
34
|
-
*/
|
|
35
|
-
async resize(fileId, options) {
|
|
36
|
-
return this.transform(fileId, [{ options, type: "resize" }]);
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Crops a video to the specified region.
|
|
40
|
-
* @param fileId Unique identifier of the video file to crop.
|
|
41
|
-
* @param options Crop options including region coordinates.
|
|
42
|
-
* @returns Promise resolving to transformed video result.
|
|
43
|
-
*/
|
|
44
|
-
async crop(fileId, options) {
|
|
45
|
-
return this.transform(fileId, [{ options, type: "crop" }]);
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Rotates a video by the specified angle.
|
|
49
|
-
* @param fileId Unique identifier of the video file to rotate.
|
|
50
|
-
* @param options Rotation configuration with angle in degrees and optional background color.
|
|
51
|
-
* @returns Promise resolving to transformed video result.
|
|
52
|
-
*/
|
|
53
|
-
async rotate(fileId, options) {
|
|
54
|
-
return this.transform(fileId, [{ options, type: "rotate" }]);
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Converts video format or codec.
|
|
58
|
-
* @param fileId Unique identifier of the video file to convert.
|
|
59
|
-
* @param format Target video format (e.g., "mp4", "webm", "mkv").
|
|
60
|
-
* @param options Video transformation options including quality, bitrate, and codec settings.
|
|
61
|
-
* @returns Promise resolving to transformed video result with updated format metadata.
|
|
62
|
-
*/
|
|
63
|
-
async convertFormat(fileId, format, options = {}) {
|
|
64
|
-
return this.transform(fileId, [{ options: { ...options, format }, type: "format" }]);
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Transcodes video to different codec.
|
|
68
|
-
* @param fileId Unique identifier of the video file to transcode.
|
|
69
|
-
* @param codec Target video codec (e.g., "avc", "hevc", "vp9").
|
|
70
|
-
* @param options Additional transform options.
|
|
71
|
-
* @returns Promise resolving to transformed video result.
|
|
72
|
-
*/
|
|
73
|
-
async transcode(fileId, codec, options = {}) {
|
|
74
|
-
return this.transform(fileId, [{ options: { ...options, codec }, type: "codec" }]);
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Applies a custom transformation pipeline to a video.
|
|
78
|
-
* @param fileId Unique identifier of the video file to transform.
|
|
79
|
-
* @param steps Array of transformation steps to apply in sequence.
|
|
80
|
-
* @returns Promise resolving to transformed video result.
|
|
81
|
-
*/
|
|
82
|
-
async transform(fileId, steps) {
|
|
83
|
-
const fileQuery = { id: fileId };
|
|
84
|
-
const cacheKey = this.generateCacheKey(fileId, steps);
|
|
85
|
-
if (this.cache) {
|
|
86
|
-
const cached = await Promise.resolve(this.cache.get(cacheKey));
|
|
87
|
-
if (cached) {
|
|
88
|
-
this.logger?.debug("Returning cached transformed video for %s", fileId);
|
|
89
|
-
return cached;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
const originalFile = await this.storage.get(fileQuery);
|
|
93
|
-
await this.validateVideo(originalFile);
|
|
94
|
-
const transformedBuffer = await this.applyTransformations(originalFile.content, steps);
|
|
95
|
-
const result = await this.createTransformResult(transformedBuffer, originalFile);
|
|
96
|
-
if (this.cache) {
|
|
97
|
-
this.cache.set(cacheKey, result);
|
|
98
|
-
}
|
|
99
|
-
return result;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Applies multiple transformations in sequence using Mediabunny.
|
|
103
|
-
* @param buffer The original video buffer.
|
|
104
|
-
* @param steps Array of video transformation steps to apply.
|
|
105
|
-
* @returns Promise resolving to transformed video buffer.
|
|
106
|
-
* @private
|
|
107
|
-
*/
|
|
108
|
-
async applyTransformations(buffer, steps) {
|
|
109
|
-
const input = new Input({
|
|
110
|
-
formats: ALL_FORMATS,
|
|
111
|
-
source: new BufferSource(buffer)
|
|
112
|
-
});
|
|
113
|
-
const outputFormat = this.determineOutputFormat(steps);
|
|
114
|
-
const output = new Output({
|
|
115
|
-
format: outputFormat,
|
|
116
|
-
target: new BufferTarget()
|
|
117
|
-
});
|
|
118
|
-
const videoOptions = this.stepsToVideoOptions(steps);
|
|
119
|
-
const conversion = await Conversion.init({
|
|
120
|
-
input,
|
|
121
|
-
output,
|
|
122
|
-
video: videoOptions
|
|
123
|
-
});
|
|
124
|
-
if (!conversion.isValid) {
|
|
125
|
-
const reasons = conversion.discardedTracks.map((track) => track.reason).join(", ");
|
|
126
|
-
throw new Error(`Video transformation failed: ${reasons}`);
|
|
127
|
-
}
|
|
128
|
-
await conversion.execute();
|
|
129
|
-
return Buffer.from(output.target.buffer);
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Converts transformation steps to Mediabunny video options.
|
|
133
|
-
* @param steps Array of video transformation steps to convert.
|
|
134
|
-
* @returns Mediabunny video options object for conversion.
|
|
135
|
-
* @private
|
|
136
|
-
*/
|
|
137
|
-
// eslint-disable-next-line class-methods-use-this
|
|
138
|
-
stepsToVideoOptions(steps) {
|
|
139
|
-
const options = {};
|
|
140
|
-
for (const step of steps) {
|
|
141
|
-
switch (step.type) {
|
|
142
|
-
case "bitrate": {
|
|
143
|
-
const bitrateOptions = step.options;
|
|
144
|
-
if (bitrateOptions.bitrate) {
|
|
145
|
-
options.bitrate = bitrateOptions.bitrate;
|
|
146
|
-
}
|
|
147
|
-
break;
|
|
148
|
-
}
|
|
149
|
-
case "codec": {
|
|
150
|
-
const codecOptions = step.options;
|
|
151
|
-
if (codecOptions.codec) {
|
|
152
|
-
options.codec = codecOptions.codec;
|
|
153
|
-
}
|
|
154
|
-
if (codecOptions.bitrate) {
|
|
155
|
-
options.bitrate = codecOptions.bitrate;
|
|
156
|
-
}
|
|
157
|
-
break;
|
|
158
|
-
}
|
|
159
|
-
case "crop": {
|
|
160
|
-
const cropOptions = step.options;
|
|
161
|
-
options.crop = {
|
|
162
|
-
height: cropOptions.height,
|
|
163
|
-
left: cropOptions.left,
|
|
164
|
-
top: cropOptions.top,
|
|
165
|
-
width: cropOptions.width
|
|
166
|
-
};
|
|
167
|
-
break;
|
|
168
|
-
}
|
|
169
|
-
case "frameRate": {
|
|
170
|
-
const frameRateOptions = step.options;
|
|
171
|
-
if (frameRateOptions.frameRate) {
|
|
172
|
-
options.frameRate = frameRateOptions.frameRate;
|
|
173
|
-
}
|
|
174
|
-
break;
|
|
175
|
-
}
|
|
176
|
-
case "resize": {
|
|
177
|
-
const resizeOptions = step.options;
|
|
178
|
-
options.width = resizeOptions.width;
|
|
179
|
-
options.height = resizeOptions.height;
|
|
180
|
-
options.fit = resizeOptions.fit;
|
|
181
|
-
if (resizeOptions.position !== void 0) {
|
|
182
|
-
options.position = resizeOptions.position;
|
|
183
|
-
}
|
|
184
|
-
break;
|
|
185
|
-
}
|
|
186
|
-
case "rotate": {
|
|
187
|
-
const rotateOptions = step.options;
|
|
188
|
-
options.rotate = rotateOptions.angle;
|
|
189
|
-
if (rotateOptions.background) {
|
|
190
|
-
options.background = rotateOptions.background;
|
|
191
|
-
}
|
|
192
|
-
break;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
return options;
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* Determines output format based on transformation steps.
|
|
200
|
-
* @param steps Array of video transformation steps.
|
|
201
|
-
* @returns Mediabunny output format instance (defaults to MP4).
|
|
202
|
-
* @private
|
|
203
|
-
*/
|
|
204
|
-
determineOutputFormat(steps) {
|
|
205
|
-
for (const step of steps) {
|
|
206
|
-
if (step.type === "format" && step.options.format) {
|
|
207
|
-
return this.formatStringToOutputFormat(step.options.format);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
return new Mp4OutputFormat();
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* Converts format string to Mediabunny output format.
|
|
214
|
-
* @param format Video format string (mp4, webm, mkv, ogg).
|
|
215
|
-
* @returns Mediabunny output format instance.
|
|
216
|
-
* @private
|
|
217
|
-
*/
|
|
218
|
-
// eslint-disable-next-line class-methods-use-this
|
|
219
|
-
formatStringToOutputFormat(format) {
|
|
220
|
-
switch (format.toLowerCase()) {
|
|
221
|
-
case "mkv": {
|
|
222
|
-
return new MkvOutputFormat();
|
|
223
|
-
}
|
|
224
|
-
case "mp4": {
|
|
225
|
-
return new Mp4OutputFormat();
|
|
226
|
-
}
|
|
227
|
-
case "ogg": {
|
|
228
|
-
return new OggOutputFormat();
|
|
229
|
-
}
|
|
230
|
-
case "webm": {
|
|
231
|
-
return new WebMOutputFormat();
|
|
232
|
-
}
|
|
233
|
-
default: {
|
|
234
|
-
return new Mp4OutputFormat();
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
/**
|
|
239
|
-
* Validates that the file is a supported video.
|
|
240
|
-
* @param file The file to validate.
|
|
241
|
-
* @returns Promise that resolves if validation passes.
|
|
242
|
-
* @throws Error if file size exceeds limits, wrong content type, unsupported format, or invalid video.
|
|
243
|
-
* @private
|
|
244
|
-
*/
|
|
245
|
-
async validateVideo(file) {
|
|
246
|
-
const fileSize = typeof file.size === "string" ? Number.parseInt(file.size, 10) : file.size;
|
|
247
|
-
if (this.config?.maxVideoSize && fileSize > this.config.maxVideoSize) {
|
|
248
|
-
throw new Error(`Video size ${fileSize} exceeds maximum allowed size ${this.config.maxVideoSize}`);
|
|
249
|
-
}
|
|
250
|
-
if (!isValidMediaType(file.contentType, "video")) {
|
|
251
|
-
throw new Error(`File is not a video: ${file.contentType}`);
|
|
252
|
-
}
|
|
253
|
-
const format = getFormatFromContentType(file.contentType);
|
|
254
|
-
if (this.config?.supportedFormats && format && !this.config.supportedFormats.includes(format)) {
|
|
255
|
-
throw new Error(`Unsupported video format: ${format}`);
|
|
256
|
-
}
|
|
257
|
-
try {
|
|
258
|
-
const input = new Input({
|
|
259
|
-
formats: ALL_FORMATS,
|
|
260
|
-
source: new BufferSource(file.content)
|
|
261
|
-
});
|
|
262
|
-
const primaryTrack = await input.getPrimaryVideoTrack();
|
|
263
|
-
if (!primaryTrack) {
|
|
264
|
-
throw new Error("No video track found");
|
|
265
|
-
}
|
|
266
|
-
} catch (error) {
|
|
267
|
-
throw new Error(`Invalid video file: ${error}`);
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
/**
|
|
271
|
-
* Creates transformation result with metadata.
|
|
272
|
-
* @param buffer The transformed video buffer.
|
|
273
|
-
* @param originalFile The original file information.
|
|
274
|
-
* @returns Video transformation result with metadata.
|
|
275
|
-
* @private
|
|
276
|
-
*/
|
|
277
|
-
async createTransformResult(buffer, originalFile) {
|
|
278
|
-
const input = new Input({
|
|
279
|
-
formats: ALL_FORMATS,
|
|
280
|
-
source: new BufferSource(buffer)
|
|
281
|
-
});
|
|
282
|
-
const videoTrack = await input.getPrimaryVideoTrack();
|
|
283
|
-
const duration = await input.computeDuration();
|
|
284
|
-
return {
|
|
285
|
-
bitrate: this.config.defaultBitrate,
|
|
286
|
-
buffer,
|
|
287
|
-
duration,
|
|
288
|
-
format: "mp4",
|
|
289
|
-
// Default, would need to detect actual format
|
|
290
|
-
height: videoTrack?.displayHeight || 0,
|
|
291
|
-
originalFile,
|
|
292
|
-
size: buffer.length,
|
|
293
|
-
width: videoTrack?.displayWidth || 0
|
|
294
|
-
};
|
|
295
|
-
}
|
|
296
|
-
/**
|
|
297
|
-
* Generates cache key for transformation.
|
|
298
|
-
* @param fileId The file identifier.
|
|
299
|
-
* @param steps Array of transformation steps.
|
|
300
|
-
* @returns Unique cache key string.
|
|
301
|
-
* @private
|
|
302
|
-
*/
|
|
303
|
-
// eslint-disable-next-line class-methods-use-this
|
|
304
|
-
generateCacheKey(fileId, steps) {
|
|
305
|
-
const stepsKey = steps.map((step) => `${step.type}:${JSON.stringify(step.options)}`).join("|");
|
|
306
|
-
return `${fileId}:${stepsKey}`;
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
export { VideoTransformer as default };
|
|
1
|
+
var w=Object.defineProperty;var p=(n,t)=>w(n,"name",{value:t,configurable:!0});import{Input as f,BufferSource as m,ALL_FORMATS as u,Output as g,BufferTarget as l,Conversion as y,Mp4OutputFormat as d,WebMOutputFormat as b,OggOutputFormat as v,MkvOutputFormat as T}from"mediabunny";import F from"../packem_shared/BaseTransformer-D68eLyz1.js";import{isValidMediaType as k,getFormatFromContentType as O}from"../packem_shared/isValidMediaType-B-2UKjZx.js";var V=Object.defineProperty,z=p((n,t)=>V(n,"name",{value:t,configurable:!0}),"d");class C extends F{static{p(this,"b")}static{z(this,"VideoTransformer")}constructor(t,e={}){const r=e.logger||t.logger,o={cacheTtl:3600,defaultBitrate:2e6,defaultCodec:"avc",maxCacheSize:50,maxVideoSize:500*1024*1024,supportedFormats:["mp4","webm","mkv","avi","mov","flv","wmv"],...e};super(t,o,r)}async resize(t,e){return this.transform(t,[{options:e,type:"resize"}])}async crop(t,e){return this.transform(t,[{options:e,type:"crop"}])}async rotate(t,e){return this.transform(t,[{options:e,type:"rotate"}])}async convertFormat(t,e,r={}){return this.transform(t,[{options:{...r,format:e},type:"format"}])}async transcode(t,e,r={}){return this.transform(t,[{options:{...r,codec:e},type:"codec"}])}async transform(t,e){const r={id:t},o=this.generateCacheKey(t,e);if(this.cache){const s=await Promise.resolve(this.cache.get(o));if(s)return this.logger?.debug("Returning cached transformed video for %s",t),s}const a=await this.storage.get(r);await this.validateVideo(a);const c=await this.applyTransformations(a.content,e),i=await this.createTransformResult(c,a);return this.cache&&this.cache.set(o,i),i}async applyTransformations(t,e){const r=new f({formats:u,source:new m(t)}),o=this.determineOutputFormat(e),a=new g({format:o,target:new l}),c=this.stepsToVideoOptions(e),i=await y.init({input:r,output:a,video:c});if(!i.isValid){const s=i.discardedTracks.map(h=>h.reason).join(", ");throw new Error(`Video transformation failed: ${s}`)}return await i.execute(),Buffer.from(a.target.buffer)}stepsToVideoOptions(t){const e={};for(const r of t)switch(r.type){case"bitrate":{const o=r.options;o.bitrate&&(e.bitrate=o.bitrate);break}case"codec":{const o=r.options;o.codec&&(e.codec=o.codec),o.bitrate&&(e.bitrate=o.bitrate);break}case"crop":{const o=r.options;e.crop={height:o.height,left:o.left,top:o.top,width:o.width};break}case"frameRate":{const o=r.options;o.frameRate&&(e.frameRate=o.frameRate);break}case"resize":{const o=r.options;e.width=o.width,e.height=o.height,e.fit=o.fit,o.position!==void 0&&(e.position=o.position);break}case"rotate":{const o=r.options;e.rotate=o.angle,o.background&&(e.background=o.background);break}}return e}determineOutputFormat(t){for(const e of t)if(e.type==="format"&&e.options.format)return this.formatStringToOutputFormat(e.options.format);return new d}formatStringToOutputFormat(t){switch(t.toLowerCase()){case"mkv":return new T;case"mp4":return new d;case"ogg":return new v;case"webm":return new b;default:return new d}}async validateVideo(t){const e=typeof t.size=="string"?Number.parseInt(t.size,10):t.size;if(this.config?.maxVideoSize&&e>this.config.maxVideoSize)throw new Error(`Video size ${e} exceeds maximum allowed size ${this.config.maxVideoSize}`);if(!k(t.contentType,"video"))throw new Error(`File is not a video: ${t.contentType}`);const r=O(t.contentType);if(this.config?.supportedFormats&&r&&!this.config.supportedFormats.includes(r))throw new Error(`Unsupported video format: ${r}`);try{if(!await new f({formats:u,source:new m(t.content)}).getPrimaryVideoTrack())throw new Error("No video track found")}catch(o){throw new Error(`Invalid video file: ${o}`)}}async createTransformResult(t,e){const r=new f({formats:u,source:new m(t)}),o=await r.getPrimaryVideoTrack(),a=await r.computeDuration();return{bitrate:this.config.defaultBitrate,buffer:t,duration:a,format:"mp4",height:o?.displayHeight||0,originalFile:e,size:t.length,width:o?.displayWidth||0}}generateCacheKey(t,e){const r=e.map(o=>`${o.type}:${JSON.stringify(o.options)}`).join("|");return`${t}:${r}`}}export{C as default};
|
package/package.json
CHANGED
|
@@ -1,63 +1,68 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@visulima/storage",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.20",
|
|
4
4
|
"description": "Visulima upload - Store files in a web-accessible location via a simplified API. Can automatically scale and rotate images. Includes S3, Azure, GCS and local filesystem-based backends with the most convenient features of each.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"anolilab",
|
|
7
|
-
"
|
|
7
|
+
"astro",
|
|
8
|
+
"aws",
|
|
9
|
+
"aws-s3",
|
|
10
|
+
"azure",
|
|
11
|
+
"better-upload",
|
|
12
|
+
"better-uploads",
|
|
13
|
+
"chunk",
|
|
14
|
+
"chunked-upload",
|
|
15
|
+
"chunked-uploads",
|
|
16
|
+
"cloudflare-r2",
|
|
17
|
+
"cloudflare-workers",
|
|
18
|
+
"digitalocean-spaces",
|
|
19
|
+
"edge-runtime",
|
|
20
|
+
"elysia",
|
|
21
|
+
"enterprise-security",
|
|
8
22
|
"express",
|
|
9
|
-
"
|
|
10
|
-
"uploads",
|
|
23
|
+
"fastify",
|
|
11
24
|
"file",
|
|
25
|
+
"file-upload",
|
|
12
26
|
"files",
|
|
13
|
-
"chunk",
|
|
14
|
-
"resumable",
|
|
15
|
-
"chunked-uploads",
|
|
16
|
-
"tus",
|
|
17
27
|
"form",
|
|
18
|
-
"post",
|
|
19
|
-
"multipart",
|
|
20
28
|
"form-data",
|
|
21
29
|
"formdata",
|
|
22
|
-
"
|
|
23
|
-
"better-upload",
|
|
24
|
-
"better-uploads",
|
|
25
|
-
"s3",
|
|
26
|
-
"azure",
|
|
27
|
-
"aws",
|
|
30
|
+
"framework-agnostic",
|
|
28
31
|
"gcs",
|
|
29
32
|
"google",
|
|
30
|
-
"storage",
|
|
31
|
-
"file-upload",
|
|
32
|
-
"cloudflare-r2",
|
|
33
|
-
"digitalocean-spaces",
|
|
34
33
|
"google-cloud-storage",
|
|
34
|
+
"hono",
|
|
35
|
+
"middleware",
|
|
35
36
|
"minio",
|
|
36
|
-
"
|
|
37
|
+
"multipart",
|
|
38
|
+
"multipart-upload",
|
|
37
39
|
"nextjs",
|
|
38
|
-
"remix",
|
|
39
|
-
"sveltekit",
|
|
40
40
|
"nuxt",
|
|
41
|
-
"
|
|
41
|
+
"post",
|
|
42
|
+
"presigned-urls",
|
|
42
43
|
"react",
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"fastify",
|
|
47
|
-
"elysia",
|
|
48
|
-
"framework-agnostic",
|
|
49
|
-
"edge-runtime",
|
|
50
|
-
"cloudflare-workers",
|
|
51
|
-
"vercel-edge",
|
|
44
|
+
"remix",
|
|
45
|
+
"resumable",
|
|
46
|
+
"s3",
|
|
52
47
|
"serverless",
|
|
48
|
+
"storage",
|
|
49
|
+
"sveltekit",
|
|
50
|
+
"tus",
|
|
51
|
+
"typescript",
|
|
53
52
|
"universal",
|
|
54
|
-
"
|
|
55
|
-
"multipart-upload",
|
|
56
|
-
"chunked-upload",
|
|
53
|
+
"upload",
|
|
57
54
|
"upload-library",
|
|
58
|
-
"
|
|
55
|
+
"uploads",
|
|
56
|
+
"uploadthing",
|
|
57
|
+
"vercel-edge",
|
|
58
|
+
"visulima"
|
|
59
59
|
],
|
|
60
60
|
"homepage": "https://visulima.com/packages/uploads",
|
|
61
|
+
"license": "MIT",
|
|
62
|
+
"author": {
|
|
63
|
+
"name": "Daniel Bannert",
|
|
64
|
+
"email": "d.bannert@anolilab.de"
|
|
65
|
+
},
|
|
61
66
|
"repository": {
|
|
62
67
|
"type": "git",
|
|
63
68
|
"url": "https://github.com/visulima/visulima.git",
|
|
@@ -73,13 +78,14 @@
|
|
|
73
78
|
"url": "https://anolilab.com/support"
|
|
74
79
|
}
|
|
75
80
|
],
|
|
76
|
-
"
|
|
77
|
-
|
|
78
|
-
"
|
|
79
|
-
"
|
|
80
|
-
|
|
81
|
-
|
|
81
|
+
"files": [
|
|
82
|
+
"dist/**",
|
|
83
|
+
"README.md",
|
|
84
|
+
"CHANGELOG.md",
|
|
85
|
+
"LICENSE.md"
|
|
86
|
+
],
|
|
82
87
|
"type": "module",
|
|
88
|
+
"sideEffects": false,
|
|
83
89
|
"exports": {
|
|
84
90
|
".": {
|
|
85
91
|
"types": "./dist/index.d.ts",
|
|
@@ -179,21 +185,19 @@
|
|
|
179
185
|
},
|
|
180
186
|
"./package.json": "./package.json"
|
|
181
187
|
},
|
|
182
|
-
"
|
|
183
|
-
"
|
|
184
|
-
"
|
|
185
|
-
|
|
186
|
-
"LICENSE.md"
|
|
187
|
-
],
|
|
188
|
+
"publishConfig": {
|
|
189
|
+
"access": "public",
|
|
190
|
+
"provenance": true
|
|
191
|
+
},
|
|
188
192
|
"dependencies": {
|
|
189
|
-
"@remix-run/multipart-parser": "
|
|
193
|
+
"@remix-run/multipart-parser": "0.16.0",
|
|
190
194
|
"@sindresorhus/fnv1a": "3.1.0",
|
|
191
|
-
"@visulima/pagination": "5.0.0-alpha.
|
|
192
|
-
"file-type": "
|
|
193
|
-
"lru-cache": "
|
|
195
|
+
"@visulima/pagination": "5.0.0-alpha.11",
|
|
196
|
+
"file-type": "22.0.1",
|
|
197
|
+
"lru-cache": "11.3.5",
|
|
194
198
|
"mime": "^4.1.0",
|
|
195
|
-
"nanoid": "5.1.
|
|
196
|
-
"path-to-regexp": "8.
|
|
199
|
+
"nanoid": "5.1.11",
|
|
200
|
+
"path-to-regexp": "8.4.2",
|
|
197
201
|
"type-is": "^2.0.1"
|
|
198
202
|
},
|
|
199
203
|
"peerDependencies": {
|
|
@@ -277,10 +281,6 @@
|
|
|
277
281
|
}
|
|
278
282
|
},
|
|
279
283
|
"engines": {
|
|
280
|
-
"node": "
|
|
281
|
-
},
|
|
282
|
-
"publishConfig": {
|
|
283
|
-
"access": "public",
|
|
284
|
-
"provenance": true
|
|
284
|
+
"node": "^22.14.0 || >=24.10.0"
|
|
285
285
|
}
|
|
286
286
|
}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { EventEmitter } from "node:events";
|
|
2
|
-
import type { BaseStorage } from "../../storage/storage.d.ts";
|
|
3
|
-
import type { UploadFile } from "../../storage/utils/index.d.ts";
|
|
4
|
-
import type MediaTransformer from "../../transformer/media-transformer.d.ts";
|
|
5
|
-
import type { ErrorResponses } from "../../utils/errors.d.ts";
|
|
6
|
-
import type { ResponseBodyType } from "../../utils/types.d.ts";
|
|
7
|
-
import type { UploadOptions } from "../types.d.ts";
|
|
8
|
-
/**
|
|
9
|
-
* Core base class containing shared business logic for all handlers.
|
|
10
|
-
* This class is platform-agnostic and contains no Node.js or Web API specific code.
|
|
11
|
-
* @template TFile The file type used by this handler.
|
|
12
|
-
*/
|
|
13
|
-
declare abstract class BaseHandlerCore<TFile extends UploadFile> extends EventEmitter {
|
|
14
|
-
/**
|
|
15
|
-
* Response body type for the handler.
|
|
16
|
-
*/
|
|
17
|
-
responseType: ResponseBodyType;
|
|
18
|
-
/**
|
|
19
|
-
* Storage instance for file operations.
|
|
20
|
-
*/
|
|
21
|
-
storage: BaseStorage<TFile>;
|
|
22
|
-
/**
|
|
23
|
-
* Optional media transformer for image/video processing.
|
|
24
|
-
*/
|
|
25
|
-
mediaTransformer?: MediaTransformer;
|
|
26
|
-
/**
|
|
27
|
-
* Whether to disable termination for finished uploads.
|
|
28
|
-
*/
|
|
29
|
-
disableTerminationForFinishedUploads?: boolean;
|
|
30
|
-
/**
|
|
31
|
-
* Logger instance for debugging and error reporting.
|
|
32
|
-
*/
|
|
33
|
-
protected logger?: Console;
|
|
34
|
-
/**
|
|
35
|
-
* Gets the logger instance.
|
|
36
|
-
* @returns Logger instance or undefined.
|
|
37
|
-
*/
|
|
38
|
-
get loggerInstance(): Console | undefined;
|
|
39
|
-
/**
|
|
40
|
-
* Internal error responses configuration.
|
|
41
|
-
*/
|
|
42
|
-
protected internalErrorResponses: ErrorResponses;
|
|
43
|
-
/**
|
|
44
|
-
* Gets the error responses configuration.
|
|
45
|
-
* @returns Error responses configuration.
|
|
46
|
-
*/
|
|
47
|
-
get errorResponses(): ErrorResponses;
|
|
48
|
-
constructor({ disableTerminationForFinishedUploads, mediaTransformer, storage }: UploadOptions<TFile>);
|
|
49
|
-
/**
|
|
50
|
-
* Sets custom error responses.
|
|
51
|
-
* @param value Partial error responses to override defaults.
|
|
52
|
-
*/
|
|
53
|
-
set errorResponses(value: Partial<ErrorResponses>);
|
|
54
|
-
/**
|
|
55
|
-
* Assemble error responses by merging defaults with custom overrides.
|
|
56
|
-
* @param customErrors Custom error responses to override defaults
|
|
57
|
-
*/
|
|
58
|
-
assembleErrors: (customErrors?: {}) => void;
|
|
59
|
-
/**
|
|
60
|
-
* Parses HTTP Range header and returns start/end byte positions for partial content requests.
|
|
61
|
-
* @param rangeHeader HTTP Range header value (e.g., "bytes=0-1023").
|
|
62
|
-
* @param fileSize Total size of the file in bytes.
|
|
63
|
-
* @returns Object with start and end positions, or undefined if range is invalid.
|
|
64
|
-
*/
|
|
65
|
-
parseRangeHeader(rangeHeader: string | undefined, fileSize: number): {
|
|
66
|
-
end: number;
|
|
67
|
-
start: number;
|
|
68
|
-
} | undefined;
|
|
69
|
-
/**
|
|
70
|
-
* Build file URL from request and file data.
|
|
71
|
-
* Platform-agnostic version that accepts URL string.
|
|
72
|
-
* @param requestUrl Request URL string
|
|
73
|
-
* @param file File object containing ID and content type
|
|
74
|
-
* @returns Constructed file URL with extension based on content type
|
|
75
|
-
*/
|
|
76
|
-
protected buildFileUrlFromString(requestUrl: string, file: TFile): string;
|
|
77
|
-
/**
|
|
78
|
-
* Negotiates content type based on Accept header and supported formats.
|
|
79
|
-
* Platform-agnostic version that accepts header string.
|
|
80
|
-
* @param acceptHeader Accept header value
|
|
81
|
-
* @param supportedTypes Array of supported MIME types to match against
|
|
82
|
-
* @returns Best matching content type or undefined if no match found
|
|
83
|
-
*/
|
|
84
|
-
negotiateContentTypeFromHeader(acceptHeader: string | undefined, supportedTypes: string[]): string | undefined;
|
|
85
|
-
/**
|
|
86
|
-
* Check for undefined ID or path errors and throw appropriate HTTP errors.
|
|
87
|
-
* @param error The error to check
|
|
88
|
-
*/
|
|
89
|
-
protected checkForUndefinedIdOrPath(error: unknown): void;
|
|
90
|
-
}
|
|
91
|
-
export default BaseHandlerCore;
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import type { UploadFile } from "../../storage/utils/index.d.ts";
|
|
2
|
-
import type { UploadResponse } from "../../utils/types.d.ts";
|
|
3
|
-
import type { Handlers, ResponseFile, ResponseList, UploadOptions } from "../types.d.ts";
|
|
4
|
-
import BaseHandlerCore from "./base-handler-core.d.ts";
|
|
5
|
-
/**
|
|
6
|
-
* Base handler for Web API Fetch platform (Request/Response).
|
|
7
|
-
* Extends BaseHandlerCore with Fetch-specific request/response handling.
|
|
8
|
-
* @template TFile The file type used by this handler.
|
|
9
|
-
*/
|
|
10
|
-
declare abstract class BaseHandlerFetch<TFile extends UploadFile> extends BaseHandlerCore<TFile> {
|
|
11
|
-
/**
|
|
12
|
-
* Limiting enabled HTTP method handler.
|
|
13
|
-
*/
|
|
14
|
-
static readonly methods: Handlers[];
|
|
15
|
-
/**
|
|
16
|
-
* Map of registered HTTP method handlers.
|
|
17
|
-
*/
|
|
18
|
-
protected registeredHandlers: Map<string, (request: Request) => Promise<ResponseFile<TFile> | ResponseList<TFile>>>;
|
|
19
|
-
constructor(options: UploadOptions<TFile>);
|
|
20
|
-
/**
|
|
21
|
-
* Gets the registered handlers map.
|
|
22
|
-
* @returns Map of registered handlers.
|
|
23
|
-
*/
|
|
24
|
-
get handlers(): Map<string, (request: Request) => Promise<ResponseFile<TFile> | ResponseList<TFile>>>;
|
|
25
|
-
/**
|
|
26
|
-
* Handles Web API Fetch requests (for Hono, Cloudflare Workers, etc.).
|
|
27
|
-
* @param request Web API Request object.
|
|
28
|
-
* @returns Promise resolving to Web API Response.
|
|
29
|
-
*/
|
|
30
|
-
fetch(request: Request): Promise<globalThis.Response>;
|
|
31
|
-
/**
|
|
32
|
-
* Compose and register HTTP method handlers.
|
|
33
|
-
* Subclasses should override this to register their specific handlers.
|
|
34
|
-
*/
|
|
35
|
-
protected abstract compose(): void;
|
|
36
|
-
/**
|
|
37
|
-
* Handle the response from handlers for fetch requests and convert to Web API Response.
|
|
38
|
-
* @param request Web API Request object
|
|
39
|
-
* @param file Response file or list from handler
|
|
40
|
-
* @returns Promise resolving to Web API Response object
|
|
41
|
-
*/
|
|
42
|
-
protected handleFetchResponse(request: Request, file: ResponseFile<TFile> | ResponseList<TFile>): Promise<globalThis.Response>;
|
|
43
|
-
/**
|
|
44
|
-
* Convert headers to Web API Headers format by flattening arrays and converting to strings.
|
|
45
|
-
* @param headers Headers object with potentially array values
|
|
46
|
-
* @returns Headers object with all values as strings
|
|
47
|
-
*/
|
|
48
|
-
protected convertHeaders(headers: Record<string, number | string | string[]>): Record<string, string>;
|
|
49
|
-
/**
|
|
50
|
-
* Create Web API Response from UploadResponse object.
|
|
51
|
-
* @param uploadResponse Upload response containing body, headers, and status code
|
|
52
|
-
* @returns Web API Response object
|
|
53
|
-
*/
|
|
54
|
-
protected createResponse(uploadResponse: UploadResponse): globalThis.Response;
|
|
55
|
-
/**
|
|
56
|
-
* Create error Response from Error object with appropriate status code and message.
|
|
57
|
-
* @param error Error object to convert to HTTP error response
|
|
58
|
-
* @returns Web API Response object with error details
|
|
59
|
-
*/
|
|
60
|
-
protected createErrorResponse(error: Error): Promise<globalThis.Response>;
|
|
61
|
-
/**
|
|
62
|
-
* Build file URL from request and file data.
|
|
63
|
-
* @param request Web API Request object
|
|
64
|
-
* @param file File object containing ID and content type
|
|
65
|
-
* @returns Constructed file URL with extension based on content type
|
|
66
|
-
*/
|
|
67
|
-
protected buildFileUrl(request: Request, file: TFile): string;
|
|
68
|
-
/**
|
|
69
|
-
* Negotiates content type based on Accept header and supported formats.
|
|
70
|
-
* @param request Web API Request object containing Accept header.
|
|
71
|
-
* @param supportedTypes Array of supported MIME types to match against.
|
|
72
|
-
* @returns Best matching content type or undefined if no match found.
|
|
73
|
-
*/
|
|
74
|
-
negotiateContentType(request: Request, supportedTypes: string[]): string | undefined;
|
|
75
|
-
}
|
|
76
|
-
export default BaseHandlerFetch;
|