@visulima/storage 1.0.0-alpha.9 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +562 -0
- package/LICENSE.md +237 -568
- package/README.md +82 -466
- package/dist/adapter/nuxt/module.d.ts +41 -34
- package/dist/adapter/nuxt/module.js +1 -93
- package/dist/adapter/nuxt/package.json +0 -6
- package/dist/ai/ai-sdk/index.d.ts +113 -0
- package/dist/ai/ai-sdk/index.js +1 -0
- package/dist/ai/claude/index.d.ts +177 -0
- package/dist/ai/claude/index.js +1 -0
- package/dist/ai/openai/index.d.ts +205 -0
- package/dist/ai/openai/index.js +1 -0
- package/dist/ai/tanstack/index.d.ts +115 -0
- package/dist/ai/tanstack/index.js +1 -0
- package/dist/handler/http/fetch/index.d.ts +303 -4
- package/dist/handler/http/fetch/index.js +1 -4
- package/dist/handler/http/hono/index.d.ts +73 -64
- 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 +368 -4
- package/dist/handler/http/node/index.js +1 -8
- 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 +106 -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/AbstractBaseStorage-CiPEMcuo.js +1 -0
- package/dist/packem_shared/AwsLightFile-CpZrubaV.js +1 -0
- package/dist/packem_shared/AwsLightMetaStorage-DPqJ9LTr.js +1 -0
- package/dist/packem_shared/AwsLightStorage-BK-WPL0h.js +1 -0
- package/dist/packem_shared/AzureFile-DFSaVe25.js +1 -0
- package/dist/packem_shared/AzureSMetaStorage-ByzM6Aix.js +1 -0
- package/dist/packem_shared/AzureStorage-1UvDIQZd.js +1 -0
- package/dist/packem_shared/BaseTransformer-Buw5lX_3.js +1 -0
- package/dist/packem_shared/BoxFile-CseIoPW1.js +1 -0
- package/dist/packem_shared/BoxMetaStorage-BSn6Qfnf.js +1 -0
- package/dist/packem_shared/BoxStorage-DbGqBLux.js +1 -0
- package/dist/packem_shared/BunS3File-BcYmsz1n.js +1 -0
- package/dist/packem_shared/BunS3MetaStorage-BSn6Qfnf.js +1 -0
- package/dist/packem_shared/BunS3Storage-DNvimm9e.js +1 -0
- package/dist/packem_shared/BunnyFile-BgEOlcYI.js +1 -0
- package/dist/packem_shared/BunnyMetaStorage-BSn6Qfnf.js +1 -0
- package/dist/packem_shared/BunnyStorage-C7d0opLL.js +1 -0
- package/dist/packem_shared/CloudinaryFile-Bo5B-vM1.js +1 -0
- package/dist/packem_shared/CloudinaryMetaStorage-DPVnmNe5.js +1 -0
- package/dist/packem_shared/CloudinaryStorage-Dc3XA2lP.js +1 -0
- package/dist/packem_shared/DiskStorage-CI07TVNu.js +1 -0
- package/dist/packem_shared/DiskStorageWithChecksum-vFCubS6K.js +1 -0
- package/dist/packem_shared/DropboxFile-BFb7eOzy.js +1 -0
- package/dist/packem_shared/DropboxMetaStorage-BSn6Qfnf.js +1 -0
- package/dist/packem_shared/DropboxStorage-CY9Ggu3m.js +1 -0
- package/dist/packem_shared/ERRORS-BIBxE2oR.js +1 -0
- package/dist/packem_shared/File-W8aOo15X.js +1 -0
- package/dist/packem_shared/Files-CpIcMjP0.js +1 -0
- package/dist/packem_shared/FirebaseFile-BLaBxa2A.js +1 -0
- package/dist/packem_shared/FirebaseMetaStorage-DPVnmNe5.js +1 -0
- package/dist/packem_shared/FirebaseStorage-D6O9CJXN.js +2 -0
- package/dist/packem_shared/FtpFile-ClWDYnt2.js +1 -0
- package/dist/packem_shared/FtpMetaStorage-BSn6Qfnf.js +1 -0
- package/dist/packem_shared/FtpStorage-DbEjbq8z.js +1 -0
- package/dist/packem_shared/GCSConfig-BQ0OpVhe.js +1 -0
- package/dist/packem_shared/GCSFile-Cero7qZN.js +1 -0
- package/dist/packem_shared/GCSMetaStorage-BuPA0DDW.js +1 -0
- package/dist/packem_shared/GCStorage-i9t5TQc1.js +1 -0
- package/dist/packem_shared/GoogleDriveFile-DHpLhzg9.js +1 -0
- package/dist/packem_shared/GoogleDriveMetaStorage-Cbwa1CHV.js +1 -0
- package/dist/packem_shared/GoogleDriveStorage-Bklsz7Bh.js +1 -0
- package/dist/packem_shared/LocalMetaStorage-BhicZnNl.js +1 -0
- package/dist/packem_shared/MediaTransformer-D2kUsklW.js +1 -0
- package/dist/packem_shared/MemoryMetaStorage-Ksgh9pe7.js +1 -0
- package/dist/packem_shared/MemoryStorage-9gbWd09l.js +1 -0
- package/dist/packem_shared/MetaStorage-DPEUyWgN.js +1 -0
- package/dist/packem_shared/Metadata-B7CcBueg.js +1 -0
- package/dist/packem_shared/Multipart-CQjYqU--.js +1 -0
- package/dist/packem_shared/Multipart-D0ok6BBy.js +1 -0
- package/dist/packem_shared/NetlifyBlobFile-DoFhkzaH.js +1 -0
- package/dist/packem_shared/NetlifyBlobMetaStorage-DPVnmNe5.js +1 -0
- package/dist/packem_shared/NetlifyBlobStorage-CkpCCoN1.js +1 -0
- package/dist/packem_shared/NoOpMetrics-BLo6u4NY.js +1 -0
- package/dist/packem_shared/OneDriveFile-CNNJYI43.js +1 -0
- package/dist/packem_shared/OneDriveMetaStorage-Cbwa1CHV.js +1 -0
- package/dist/packem_shared/OneDriveStorage-CP6MvGAa.js +1 -0
- package/dist/packem_shared/OpenTelemetryMetrics-DJDQsNKp.js +1 -0
- package/dist/packem_shared/PocketBaseFile-DpJpxl3e.js +1 -0
- package/dist/packem_shared/PocketBaseMetaStorage-DOTLwVE7.js +1 -0
- package/dist/packem_shared/PocketBaseStorage-2qhbI2PW.js +1 -0
- package/dist/packem_shared/Rest-CI_BiZPv.js +1 -0
- package/dist/packem_shared/Rest-DvfN4-kf.js +1 -0
- package/dist/packem_shared/S3File-CpZrubaV.js +1 -0
- package/dist/packem_shared/S3MetaStorage-CMonflzp.js +1 -0
- package/dist/packem_shared/S3Storage-YGeNk3Tt.js +1 -0
- package/dist/packem_shared/SftpFile-ClWDYnt2.js +1 -0
- package/dist/packem_shared/SftpMetaStorage-BSn6Qfnf.js +1 -0
- package/dist/packem_shared/SftpStorage-2Hz396Xr.js +1 -0
- package/dist/packem_shared/SharePointFile-Blz9FS4h.js +1 -0
- package/dist/packem_shared/SharePointMetaStorage-BSn6Qfnf.js +1 -0
- package/dist/packem_shared/SharePointStorage-CrX2Pk6C.js +1 -0
- package/dist/packem_shared/SupabaseFile-Bo5B-vM1.js +1 -0
- package/dist/packem_shared/SupabaseMetaStorage-Cbwa1CHV.js +1 -0
- package/dist/packem_shared/SupabaseStorage-Dc_DBX29.js +1 -0
- package/dist/packem_shared/TUS_RESUMABLE-CyTSRvPU.js +1 -0
- package/dist/packem_shared/Tus-BBVt2ky3.js +1 -0
- package/dist/packem_shared/Tus-BlBZykIL.js +1 -0
- package/dist/packem_shared/UploadControl-DZJhI9Wh.js +1 -0
- package/dist/packem_shared/UploadThingFile-BTFMpcIA.js +1 -0
- package/dist/packem_shared/UploadThingMetaStorage-DPVnmNe5.js +1 -0
- package/dist/packem_shared/UploadThingStorage-BChykYSe.js +1 -0
- package/dist/packem_shared/ValidationError-3B06DFyE.js +1 -0
- package/dist/packem_shared/VercelBlobFile-CVQwKlZk.js +1 -0
- package/dist/packem_shared/VercelBlobMetaStorage-BSn6Qfnf.js +1 -0
- package/dist/packem_shared/VercelBlobStorage-CsRyPfw3.js +1 -0
- package/dist/packem_shared/_commonjsHelpers-CWAkuNXM.js +1 -0
- package/dist/packem_shared/agentsCopyFile-Dl5iffdH.js +1 -0
- package/dist/packem_shared/akamai-DthkaFul.js +1 -0
- package/dist/packem_shared/alibaba-BEi25O1g.js +1 -0
- package/dist/packem_shared/approval-fVHwBp7u.js +1 -0
- package/dist/packem_shared/approval.d-CMAYH9GF.d.ts +75 -0
- package/dist/packem_shared/aws-light-meta-storage-DGrn72VJ.js +4 -0
- package/dist/packem_shared/azure-meta-storage-ClbEsfI4.js +1 -0
- package/dist/packem_shared/backblaze-m1N5NZ9q.js +1 -0
- package/dist/packem_shared/base-handler-core-D-9Ku1h-.js +1 -0
- package/dist/packem_shared/base-handler-fetch-CfkNakv8.js +1 -0
- package/dist/packem_shared/base-handler-node-BF1v1qDa.js +1 -0
- package/dist/packem_shared/cache-Cw3QjoVN.js +1 -0
- package/dist/packem_shared/claudeCopyFile-BX9O4ORk.js +1 -0
- package/dist/packem_shared/cloudflare-CdUTErlo.js +1 -0
- package/dist/packem_shared/copyFile-49FtxXcm.js +1 -0
- package/dist/packem_shared/copyFile-BUPezT_c.js +1 -0
- package/dist/packem_shared/createResponsesFileTools-6Tvt2PNr.js +1 -0
- package/dist/packem_shared/createRetryWrapper-CxgiV_hH.js +1 -0
- package/dist/packem_shared/detect-file-type-BA7UBLKA.js +1 -0
- package/dist/packem_shared/digitalOcean-B2uB6pgz.js +1 -0
- package/dist/packem_shared/disk-storage-CsQcYW3s.js +1 -0
- package/dist/packem_shared/disk-storage-with-checksum.d-B-VGEsfl.d.ts +156 -0
- package/dist/packem_shared/executors-BDzMjc4y.js +1 -0
- package/dist/packem_shared/executors.d-BZP2rWo3.d.ts +69 -0
- package/dist/packem_shared/exoscale-BDa1Gjth.js +1 -0
- package/dist/packem_shared/filebase-CsFYJIwB.js +1 -0
- package/dist/packem_shared/files.d-CH0iLBNC.d.ts +655 -0
- package/dist/packem_shared/gcs-meta-storage-B1RrMqH3.js +1 -0
- package/dist/packem_shared/get-file-status-y3wTtDQs.js +1 -0
- package/dist/packem_shared/getFormatFromContentType-DCTTPQHm.js +1 -0
- package/dist/packem_shared/has-content-50BsqrWw.js +1 -0
- package/dist/packem_shared/headers-BAiAKekR.js +26 -0
- package/dist/packem_shared/hetzner-BGGFiRGD.js +1 -0
- package/dist/packem_shared/ibmCos-j-3TfJ5p.js +1 -0
- package/dist/packem_shared/idriveE2-C6pQ5pQ0.js +1 -0
- package/dist/packem_shared/index-nZWCQrSe.js +5 -0
- package/dist/packem_shared/internal-D_cZIFwI.js +1 -0
- package/dist/packem_shared/is-expired-CBEk6XBi.js +1 -0
- package/dist/packem_shared/local-meta-storage-iuJnu90B.js +11 -0
- package/dist/packem_shared/local-meta-storage.d-D9PBfkn6.d.ts +21 -0
- package/dist/packem_shared/media-transformer.d-Quf4ai47.d.ts +331 -0
- package/dist/packem_shared/memory-storage.d-4EU1cMt1.d.ts +101 -0
- package/dist/packem_shared/minio-NKquuBfS.js +1 -0
- package/dist/packem_shared/multipart-base-BOzY19lb.js +1 -0
- package/dist/packem_shared/oauth-refresh-EdGzlcOZ.js +1 -0
- package/dist/packem_shared/oracleCloud-DslqNpn6.js +1 -0
- package/dist/packem_shared/ovhCloud-CMHE6uLV.js +1 -0
- package/dist/packem_shared/part-match-D-9dGX42.js +1 -0
- package/dist/packem_shared/path-0oTTdkvl-DvWvbDbh.js +1 -0
- package/dist/packem_shared/posix-dirname-CfpH5wZi.js +1 -0
- package/dist/packem_shared/response-builder-CbSA8qPa.js +1 -0
- package/dist/packem_shared/rest-base-e0reNDE_.js +1 -0
- package/dist/packem_shared/restOpenApiSpec-Csv513qf.js +1 -0
- package/dist/packem_shared/s3-base-storage-BoTyhuzO.js +1 -0
- package/dist/packem_shared/s3-base-storage.d-BQgP5B-t.d.ts +287 -0
- package/dist/packem_shared/scaleway-U1In3v70.js +1 -0
- package/dist/packem_shared/sharedErrorSchemaObject-YN65aAKj.js +1 -0
- package/dist/packem_shared/storage-0j5nCAUp.js +1 -0
- package/dist/packem_shared/storage.d-CEM1upWM.d.ts +1176 -0
- package/dist/packem_shared/storj-Cb59q9kF.js +1 -0
- package/dist/packem_shared/sync-DhR3536K.js +1 -0
- package/dist/packem_shared/tencent-Q1y2GENc.js +1 -0
- package/dist/packem_shared/tigris-BELKoyyp.js +1 -0
- package/dist/packem_shared/transformOpenApiSpec-CIEAgpBD.js +1 -0
- package/dist/packem_shared/tus-base.d-DLzKE54M.d.ts +106 -0
- package/dist/packem_shared/tusOpenApiSpec-D96B03t5.js +1 -0
- package/dist/packem_shared/types.d-Bon9GVVe.d.ts +104 -0
- package/dist/packem_shared/types.d-CggTCgXr.d.ts +49 -0
- package/dist/packem_shared/types.d-CrUWY4On.d.ts +720 -0
- package/dist/packem_shared/update-size-DuNuLyxj.js +1 -0
- package/dist/packem_shared/vultr-B491cQ4e.js +1 -0
- package/dist/packem_shared/waitForStorage-ByQmG4xF.js +1 -0
- package/dist/packem_shared/wasabi-DFrwIoab.js +1 -0
- package/dist/packem_shared/xhrOpenApiSpec-DQR4h6M8.js +1 -0
- package/dist/packem_shared/yandex-CwzHuEKP.js +1 -0
- package/dist/storage/aws/clients/index.d.ts +612 -6
- package/dist/storage/aws/clients/index.js +1 -6
- package/dist/storage/aws/index.d.ts +332 -4
- package/dist/storage/aws/index.js +1 -3
- package/dist/storage/aws-light/index.d.ts +259 -4
- package/dist/storage/aws-light/index.js +1 -3
- package/dist/storage/azure/index.d.ts +236 -4
- package/dist/storage/azure/index.js +1 -3
- package/dist/storage/box/index.d.ts +189 -0
- package/dist/storage/box/index.js +1 -0
- package/dist/storage/bun-s3/index.d.ts +200 -0
- package/dist/storage/bun-s3/index.js +1 -0
- package/dist/storage/bunny/index.d.ts +119 -0
- package/dist/storage/bunny/index.js +1 -0
- package/dist/storage/cloudinary/index.d.ts +121 -0
- package/dist/storage/cloudinary/index.js +1 -0
- package/dist/storage/dropbox/index.d.ts +132 -0
- package/dist/storage/dropbox/index.js +1 -0
- package/dist/storage/firebase/index.d.ts +192 -0
- package/dist/storage/firebase/index.js +1 -0
- package/dist/storage/ftp/index.d.ts +91 -0
- package/dist/storage/ftp/index.js +1 -0
- package/dist/storage/gcs/index.d.ts +195 -5
- package/dist/storage/gcs/index.js +1 -4
- package/dist/storage/google-drive/index.d.ts +148 -0
- package/dist/storage/google-drive/index.js +1 -0
- package/dist/storage/local/index.d.ts +7 -4
- package/dist/storage/local/index.js +1 -3
- package/dist/storage/memory/index.d.ts +6 -0
- package/dist/storage/memory/index.js +1 -0
- package/dist/storage/netlify-blob/index.d.ts +147 -4
- package/dist/storage/netlify-blob/index.js +1 -3
- package/dist/storage/onedrive/index.d.ts +103 -0
- package/dist/storage/onedrive/index.js +1 -0
- package/dist/storage/pocketbase/index.d.ts +172 -0
- package/dist/storage/pocketbase/index.js +1 -0
- package/dist/storage/sftp/index.d.ts +92 -0
- package/dist/storage/sftp/index.js +1 -0
- package/dist/storage/sharepoint/index.d.ts +180 -0
- package/dist/storage/sharepoint/index.js +1 -0
- package/dist/storage/supabase/index.d.ts +115 -0
- package/dist/storage/supabase/index.js +1 -0
- package/dist/storage/uploadthing/index.d.ts +95 -0
- package/dist/storage/uploadthing/index.js +1 -0
- package/dist/storage/vercel-blob/index.d.ts +189 -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 +573 -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 +218 -67
- 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-Blv-GP4v.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-B0v048hG.js +0 -357
- package/dist/packem_shared/BaseTransformer-C2gLib6v.js +0 -82
- package/dist/packem_shared/DiskStorage-Ck5yGQsq.js +0 -12
- package/dist/packem_shared/DiskStorageWithChecksum-BRl-V5x2.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-CHZKMe7N.js +0 -7
- package/dist/packem_shared/GCStorage-C-gAuP0j.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-CRV21AUU.js +0 -128
- package/dist/packem_shared/Multipart-D2ryPMjD.js +0 -163
- package/dist/packem_shared/NetlifyBlobFile-CXzyjqrD.js +0 -14
- package/dist/packem_shared/NetlifyBlobMetaStorage-DxZ5aDvD.js +0 -9
- package/dist/packem_shared/NetlifyBlobStorage-CLPtjHqd.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-DcxBMBjU.js +0 -228
- package/dist/packem_shared/Rest-DjwU3puo.js +0 -267
- package/dist/packem_shared/S3File-DZiyk9Qt.js +0 -11
- package/dist/packem_shared/S3MetaStorage-Dz9aDabA.js +0 -76
- package/dist/packem_shared/S3Storage-DHmTk-hU.js +0 -316
- package/dist/packem_shared/TUS_RESUMABLE-Dtfsffnj.js +0 -434
- package/dist/packem_shared/Tus-DFVlZHaX.js +0 -200
- package/dist/packem_shared/Tus-DaN0FmOy.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-DD9LMOS6.js +0 -261
- package/dist/packem_shared/_commonjsHelpers-BqLXS_qQ.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-BoAqTyz7.js +0 -303
- package/dist/packem_shared/base-handler-fetch-D4u2xits.js +0 -291
- package/dist/packem_shared/base-handler-node-DGzcHHAy.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-DUuacjWv.js +0 -11
- package/dist/packem_shared/digitalOcean-CWQRJM3L.js +0 -21
- package/dist/packem_shared/disk-storage-CD47QI30.js +0 -810
- package/dist/packem_shared/gcs-meta-storage-CJ8Uts_d.js +0 -158
- package/dist/packem_shared/has-content-CY66ehMK.js +0 -3
- package/dist/packem_shared/headers-YLRp1dLo.js +0 -1318
- 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-C994naBi.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-D9URIFkc.js +0 -457
- package/dist/packem_shared/restOpenApiSpec-D1JC_Jto.js +0 -800
- package/dist/packem_shared/s3-base-storage-C1DIHTYY.js +0 -510
- package/dist/packem_shared/sharedGet-Cpo7QUyu.js +0 -1019
- package/dist/packem_shared/storage-C6NSXb8h.js +0 -1175
- package/dist/packem_shared/tigris-Hac8TKnX.js +0 -21
- package/dist/packem_shared/transformOpenApiSpec-DWM5WtnN.js +0 -975
- package/dist/packem_shared/tusOpenApiSpec-mBZkl7he.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-B1V5Dxrj.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,730 +0,0 @@
|
|
|
1
|
-
import { paginate } from '@visulima/pagination';
|
|
2
|
-
import { H as HeaderUtilities, h as httpErrorsExports, c as createHttpError } from './headers-YLRp1dLo.js';
|
|
3
|
-
import mime from 'mime';
|
|
4
|
-
import { ERRORS, isUploadError } from './ERRORS-D0apMqnc.js';
|
|
5
|
-
import { match } from 'path-to-regexp';
|
|
6
|
-
import { p as pick, B as BaseHandlerCore, s as setHeaders, d as getRealPath, u as uuidRegex } from './base-handler-core-BoAqTyz7.js';
|
|
7
|
-
import { i as isValidationError } from './validator-BeX_lJet.js';
|
|
8
|
-
import { waitForStorage } from './waitForStorage-Cscw85sx.js';
|
|
9
|
-
import { PassThrough } from 'node:stream';
|
|
10
|
-
import { e as convertHeadersToString } from './response-builder-BtnRiBUI.js';
|
|
11
|
-
|
|
12
|
-
const internalMatcher = match(["/:uuid", "/*path/:uuid.:ext/:metadata", "/*path/:uuid/:metadata", "/*path/:uuid.:ext", "/*path/:uuid"], {
|
|
13
|
-
decode: decodeURIComponent
|
|
14
|
-
});
|
|
15
|
-
const filePathUrlMatcher = (path) => {
|
|
16
|
-
const result = internalMatcher(path);
|
|
17
|
-
if (!result) {
|
|
18
|
-
return void 0;
|
|
19
|
-
}
|
|
20
|
-
const { params } = result;
|
|
21
|
-
if (!params.uuid) {
|
|
22
|
-
return void 0;
|
|
23
|
-
}
|
|
24
|
-
const orderedParams = {
|
|
25
|
-
uuid: params.uuid
|
|
26
|
-
};
|
|
27
|
-
if (params.metadata !== void 0) {
|
|
28
|
-
orderedParams.metadata = params.metadata;
|
|
29
|
-
}
|
|
30
|
-
if (params.path !== void 0) {
|
|
31
|
-
orderedParams.path = params.path;
|
|
32
|
-
}
|
|
33
|
-
if (params.ext !== void 0) {
|
|
34
|
-
orderedParams.ext = params.ext;
|
|
35
|
-
}
|
|
36
|
-
return {
|
|
37
|
-
params: orderedParams,
|
|
38
|
-
path: result.path
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
const createRangeLimitedStream = (sourceStream, start, end) => {
|
|
43
|
-
let bytesRead = 0;
|
|
44
|
-
let bytesSent = 0;
|
|
45
|
-
const contentLength = end - start + 1;
|
|
46
|
-
return new PassThrough({
|
|
47
|
-
// Use appropriate high water mark for better backpressure handling
|
|
48
|
-
highWaterMark: Math.min(64 * 1024, contentLength),
|
|
49
|
-
// 64KB or content length, whichever is smaller
|
|
50
|
-
transform(chunk, _, callback) {
|
|
51
|
-
const chunkSize = chunk.length;
|
|
52
|
-
const currentPos = bytesRead;
|
|
53
|
-
const endPos = currentPos + chunkSize - 1;
|
|
54
|
-
bytesRead += chunkSize;
|
|
55
|
-
if (endPos < start) {
|
|
56
|
-
callback();
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
if (currentPos > end) {
|
|
60
|
-
this.end();
|
|
61
|
-
callback();
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
const chunkStart = Math.max(0, start - currentPos);
|
|
65
|
-
const chunkEnd = Math.min(chunkSize, end - currentPos + 1);
|
|
66
|
-
if (chunkStart < chunkEnd) {
|
|
67
|
-
const dataToSend = chunk.subarray(chunkStart, chunkEnd);
|
|
68
|
-
bytesSent += dataToSend.length;
|
|
69
|
-
const canContinue = this.push(dataToSend);
|
|
70
|
-
if (!canContinue) {
|
|
71
|
-
sourceStream.pause();
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
if (bytesSent >= contentLength) {
|
|
75
|
-
this.end();
|
|
76
|
-
sourceStream.destroy();
|
|
77
|
-
}
|
|
78
|
-
callback();
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
};
|
|
82
|
-
const pipeWithBackpressure = (source, destination, sendError) => {
|
|
83
|
-
let isDestroyed = false;
|
|
84
|
-
const cleanup = () => {
|
|
85
|
-
if (isDestroyed)
|
|
86
|
-
return;
|
|
87
|
-
isDestroyed = true;
|
|
88
|
-
source.destroy();
|
|
89
|
-
};
|
|
90
|
-
destination.on("drain", () => {
|
|
91
|
-
source.resume();
|
|
92
|
-
});
|
|
93
|
-
destination.on("close", cleanup);
|
|
94
|
-
destination.on("finish", cleanup);
|
|
95
|
-
destination.on("error", cleanup);
|
|
96
|
-
source.on("end", () => {
|
|
97
|
-
destination.end();
|
|
98
|
-
});
|
|
99
|
-
source.on("error", async (error) => {
|
|
100
|
-
if (!isDestroyed) {
|
|
101
|
-
await sendError(destination, error);
|
|
102
|
-
cleanup();
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
source.on("data", (chunk) => {
|
|
106
|
-
const canContinue = destination.write(chunk);
|
|
107
|
-
if (!canContinue) {
|
|
108
|
-
source.pause();
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
if (typeof destination.listeners === "function" && destination.listeners("close")?.length === 0) {
|
|
112
|
-
destination.on("close", cleanup);
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
const handleHeadOptionsRequest = (file, send, response) => {
|
|
117
|
-
const { headers, statusCode } = file;
|
|
118
|
-
send(response, { headers, statusCode });
|
|
119
|
-
};
|
|
120
|
-
const handleGetRequest = (file, request, response, next, send, sendStream, parseRangeHeader) => {
|
|
121
|
-
request.body = file?.data === void 0 ? file : file.data;
|
|
122
|
-
const { headers, statusCode } = file;
|
|
123
|
-
const streamingFile = file;
|
|
124
|
-
if (streamingFile.stream) {
|
|
125
|
-
if (typeof next === "function") {
|
|
126
|
-
next();
|
|
127
|
-
} else {
|
|
128
|
-
const range = parseRangeHeader(request.headers.range, streamingFile.size || 0);
|
|
129
|
-
sendStream(response, streamingFile.stream, {
|
|
130
|
-
headers,
|
|
131
|
-
range: range || void 0,
|
|
132
|
-
size: streamingFile.size,
|
|
133
|
-
statusCode
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
} else {
|
|
137
|
-
let body = "";
|
|
138
|
-
if (file.content !== void 0) {
|
|
139
|
-
body = file.content;
|
|
140
|
-
} else if (typeof file === "object" && "data" in file) {
|
|
141
|
-
body = file.data;
|
|
142
|
-
}
|
|
143
|
-
if (typeof next === "function") {
|
|
144
|
-
next();
|
|
145
|
-
} else {
|
|
146
|
-
send(response, { body, headers, statusCode });
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
};
|
|
150
|
-
const handleCompletedUpload = async (file, request, response, next, storage, logger, finish) => {
|
|
151
|
-
const { headers: fileHeaders, statusCode, ...basicFile } = file;
|
|
152
|
-
if (typeof next === "function") {
|
|
153
|
-
request._body = true;
|
|
154
|
-
request.body = basicFile;
|
|
155
|
-
next();
|
|
156
|
-
} else {
|
|
157
|
-
const responseFile = file;
|
|
158
|
-
const originalHeaders = responseFile.headers ? { ...responseFile.headers } : {};
|
|
159
|
-
if (responseFile.headers === void 0) {
|
|
160
|
-
responseFile.headers = {};
|
|
161
|
-
}
|
|
162
|
-
if (responseFile.statusCode === void 0) {
|
|
163
|
-
responseFile.statusCode = 200;
|
|
164
|
-
}
|
|
165
|
-
try {
|
|
166
|
-
const result = storage.onComplete(basicFile, responseFile, request);
|
|
167
|
-
if (result instanceof Promise) {
|
|
168
|
-
await result;
|
|
169
|
-
}
|
|
170
|
-
} catch (error) {
|
|
171
|
-
if (logger?.error) {
|
|
172
|
-
logger.error("[onComplete error]: %O", error);
|
|
173
|
-
}
|
|
174
|
-
throw error;
|
|
175
|
-
}
|
|
176
|
-
if (Object.keys(responseFile.headers || {}).length === 0 && Object.keys(originalHeaders).length > 0) {
|
|
177
|
-
responseFile.headers = originalHeaders;
|
|
178
|
-
} else if (responseFile.headers && Object.keys(originalHeaders).length > 0) {
|
|
179
|
-
responseFile.headers = {
|
|
180
|
-
...originalHeaders,
|
|
181
|
-
...responseFile.headers
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
finish(request, response, responseFile);
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
const handlePartialUpload = (file, request, response, send) => {
|
|
188
|
-
const { headers: fileHeaders, statusCode, ...basicFile } = file;
|
|
189
|
-
const headers = fileHeaders || {};
|
|
190
|
-
const isChunkedUploadInit = headers["X-Chunked-Upload"] === "true" || headers["x-chunked-upload"] === "true";
|
|
191
|
-
let body;
|
|
192
|
-
const responseHeaders = {
|
|
193
|
-
...convertHeadersToString(headers),
|
|
194
|
-
...fileHeaders ? convertHeadersToString(fileHeaders) : {},
|
|
195
|
-
...basicFile.hash === void 0 ? {} : { [`X-Range-${basicFile.hash?.algorithm.toUpperCase()}`]: String(basicFile.hash?.value) }
|
|
196
|
-
};
|
|
197
|
-
if (isChunkedUploadInit) {
|
|
198
|
-
body = JSON.stringify(basicFile);
|
|
199
|
-
if (!responseHeaders["Content-Type"] && !responseHeaders["content-type"]) {
|
|
200
|
-
responseHeaders["Content-Type"] = "application/json; charset=utf-8";
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
if (request.method === "HEAD") {
|
|
204
|
-
body = "";
|
|
205
|
-
}
|
|
206
|
-
send(response, {
|
|
207
|
-
body,
|
|
208
|
-
headers: responseHeaders,
|
|
209
|
-
statusCode: statusCode || 200
|
|
210
|
-
});
|
|
211
|
-
};
|
|
212
|
-
const handleUploadError = async (error, request, emit, listenerCount, logger, sendError, response) => {
|
|
213
|
-
const errorObject = error instanceof Error ? error : new Error(String(error));
|
|
214
|
-
const uError = pick(errorObject, ["name", ...Object.getOwnPropertyNames(errorObject)]);
|
|
215
|
-
const errorEvent = { ...uError, request: pick(request, ["headers", "method", "url"]) };
|
|
216
|
-
if (listenerCount("error") > 0) {
|
|
217
|
-
emit("error", errorEvent);
|
|
218
|
-
}
|
|
219
|
-
if (logger?.error) {
|
|
220
|
-
logger.error("[error]: %O", errorEvent);
|
|
221
|
-
}
|
|
222
|
-
await sendError(response, errorObject);
|
|
223
|
-
};
|
|
224
|
-
|
|
225
|
-
const CONTENT_TYPE = "Content-Type";
|
|
226
|
-
class BaseHandlerNode extends BaseHandlerCore {
|
|
227
|
-
/**
|
|
228
|
-
* Limiting enabled HTTP method handler.
|
|
229
|
-
*/
|
|
230
|
-
static methods = ["delete", "get", "head", "options", "patch", "post", "put"];
|
|
231
|
-
/**
|
|
232
|
-
* Map of registered HTTP method handlers.
|
|
233
|
-
*/
|
|
234
|
-
registeredHandlers = /* @__PURE__ */ new Map();
|
|
235
|
-
constructor(options) {
|
|
236
|
-
super(options);
|
|
237
|
-
this.compose();
|
|
238
|
-
}
|
|
239
|
-
/**
|
|
240
|
-
* Gets the registered handlers map.
|
|
241
|
-
* @returns Map of registered handlers.
|
|
242
|
-
*/
|
|
243
|
-
get handlers() {
|
|
244
|
-
return this.registeredHandlers;
|
|
245
|
-
}
|
|
246
|
-
/**
|
|
247
|
-
* Handles HTTP request (alias for upload method).
|
|
248
|
-
* @param request Node.js IncomingMessage.
|
|
249
|
-
* @param response Node.js ServerResponse.
|
|
250
|
-
*/
|
|
251
|
-
handle = async (request, response) => this.upload(request, response);
|
|
252
|
-
/**
|
|
253
|
-
* Main upload handler that processes HTTP requests and routes them to appropriate method handlers.
|
|
254
|
-
* @param request Node.js IncomingMessage.
|
|
255
|
-
* @param response Node.js ServerResponse.
|
|
256
|
-
* @param next Optional Express-style next function for middleware compatibility.
|
|
257
|
-
* @throws {UploadError} When storage is not ready or method is not allowed.
|
|
258
|
-
*/
|
|
259
|
-
upload = async (request, response, next) => {
|
|
260
|
-
request.on("error", (error) => this.logger?.error("[request error]: %O", error));
|
|
261
|
-
this.logger?.debug("[request]: %s %s", request.method, request.url);
|
|
262
|
-
const handler = this.registeredHandlers.get(request.method);
|
|
263
|
-
if (!handler) {
|
|
264
|
-
await this.sendError(response, { UploadErrorCode: ERRORS.METHOD_NOT_ALLOWED });
|
|
265
|
-
return;
|
|
266
|
-
}
|
|
267
|
-
try {
|
|
268
|
-
await waitForStorage(this.storage);
|
|
269
|
-
} catch {
|
|
270
|
-
await this.sendError(response, { UploadErrorCode: ERRORS.STORAGE_ERROR });
|
|
271
|
-
return;
|
|
272
|
-
}
|
|
273
|
-
try {
|
|
274
|
-
const file = await handler.call(this, request, response);
|
|
275
|
-
if (["HEAD", "OPTIONS"].includes(request.method)) {
|
|
276
|
-
handleHeadOptionsRequest(file, this.send.bind(this), response);
|
|
277
|
-
} else if (request.method === "GET") {
|
|
278
|
-
const fileResponse = file;
|
|
279
|
-
if (fileResponse) {
|
|
280
|
-
handleGetRequest(
|
|
281
|
-
fileResponse,
|
|
282
|
-
request,
|
|
283
|
-
response,
|
|
284
|
-
next,
|
|
285
|
-
this.send.bind(this),
|
|
286
|
-
this.sendStream.bind(this),
|
|
287
|
-
this.parseRangeHeader.bind(this)
|
|
288
|
-
);
|
|
289
|
-
}
|
|
290
|
-
} else {
|
|
291
|
-
const { headers: fileHeaders, statusCode, ...basicFile } = file;
|
|
292
|
-
this.logger?.debug("[%s]: %s: %d/%d", basicFile.status, basicFile.name, basicFile.bytesWritten, basicFile.size);
|
|
293
|
-
if (basicFile.status !== void 0 && this.listenerCount(basicFile.status) > 0) {
|
|
294
|
-
this.emit(basicFile.status, {
|
|
295
|
-
...basicFile,
|
|
296
|
-
request: pick(request, ["headers", "method", "url"])
|
|
297
|
-
});
|
|
298
|
-
}
|
|
299
|
-
if (basicFile.status === "completed") {
|
|
300
|
-
await handleCompletedUpload(
|
|
301
|
-
file,
|
|
302
|
-
request,
|
|
303
|
-
response,
|
|
304
|
-
next,
|
|
305
|
-
this.storage,
|
|
306
|
-
this.logger,
|
|
307
|
-
(_request, resp, uploadResp) => {
|
|
308
|
-
this.finish(_request, resp, uploadResp);
|
|
309
|
-
}
|
|
310
|
-
);
|
|
311
|
-
} else {
|
|
312
|
-
handlePartialUpload(file, request, response, (resp, data) => {
|
|
313
|
-
this.send(resp, {
|
|
314
|
-
body: data.body,
|
|
315
|
-
headers: data.headers,
|
|
316
|
-
statusCode: data.statusCode
|
|
317
|
-
});
|
|
318
|
-
});
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
} catch (error) {
|
|
322
|
-
await handleUploadError(error, request, this.emit.bind(this), this.listenerCount.bind(this), this.logger, this.sendError.bind(this), response);
|
|
323
|
-
}
|
|
324
|
-
};
|
|
325
|
-
/**
|
|
326
|
-
* Sends an HTTP response with the provided body, headers, and status code.
|
|
327
|
-
* @param response Node.js ServerResponse to send data to.
|
|
328
|
-
* @param body Response body, headers, and status code.
|
|
329
|
-
*/
|
|
330
|
-
// eslint-disable-next-line class-methods-use-this
|
|
331
|
-
send(response, { body = "", headers = {}, statusCode = 200 }) {
|
|
332
|
-
let data;
|
|
333
|
-
const finalHeaders = { ...headers };
|
|
334
|
-
if (typeof body === "string") {
|
|
335
|
-
data = body;
|
|
336
|
-
if (finalHeaders[CONTENT_TYPE] === void 0) {
|
|
337
|
-
finalHeaders[CONTENT_TYPE] = HeaderUtilities.createContentType({ mediaType: "text/plain" });
|
|
338
|
-
} else {
|
|
339
|
-
const contentTypeValue = Array.isArray(finalHeaders[CONTENT_TYPE]) ? finalHeaders[CONTENT_TYPE].join(", ") : String(finalHeaders[CONTENT_TYPE]);
|
|
340
|
-
finalHeaders[CONTENT_TYPE] = HeaderUtilities.ensureCharset(contentTypeValue);
|
|
341
|
-
}
|
|
342
|
-
if (finalHeaders["Content-Length"] === void 0) {
|
|
343
|
-
finalHeaders["Content-Length"] = Buffer.byteLength(body);
|
|
344
|
-
}
|
|
345
|
-
} else if (body instanceof Buffer) {
|
|
346
|
-
data = body;
|
|
347
|
-
} else {
|
|
348
|
-
data = JSON.stringify(body);
|
|
349
|
-
if (!finalHeaders[CONTENT_TYPE]) {
|
|
350
|
-
finalHeaders[CONTENT_TYPE] = HeaderUtilities.createContentType({
|
|
351
|
-
charset: "utf8",
|
|
352
|
-
mediaType: "application/json"
|
|
353
|
-
});
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
setHeaders(response, finalHeaders);
|
|
357
|
-
response.statusCode = statusCode;
|
|
358
|
-
response.end(data);
|
|
359
|
-
}
|
|
360
|
-
/**
|
|
361
|
-
* Sends an error response to the client with appropriate status code and message.
|
|
362
|
-
* @param response Node.js ServerResponse to send error to.
|
|
363
|
-
* @param error Error object to convert to HTTP error response.
|
|
364
|
-
*/
|
|
365
|
-
async sendError(response, error) {
|
|
366
|
-
let httpError;
|
|
367
|
-
if (isUploadError(error)) {
|
|
368
|
-
httpError = this.internalErrorResponses[error.UploadErrorCode];
|
|
369
|
-
} else if (!isValidationError(error) && !httpErrorsExports.isHttpError(error)) {
|
|
370
|
-
httpError = this.storage.normalizeError(error);
|
|
371
|
-
} else {
|
|
372
|
-
httpError = {
|
|
373
|
-
...error,
|
|
374
|
-
code: error.code || error.name,
|
|
375
|
-
headers: error.headers || {},
|
|
376
|
-
message: error.message,
|
|
377
|
-
name: error.name,
|
|
378
|
-
statusCode: error.statusCode || 500
|
|
379
|
-
};
|
|
380
|
-
}
|
|
381
|
-
await this.storage.onError(httpError);
|
|
382
|
-
let errorResponse;
|
|
383
|
-
if (httpError.body) {
|
|
384
|
-
if (typeof httpError.body === "object" && httpError.body !== null) {
|
|
385
|
-
errorResponse = { body: httpError.body, headers: httpError.headers, statusCode: httpError.statusCode };
|
|
386
|
-
} else {
|
|
387
|
-
errorResponse = {
|
|
388
|
-
body: {
|
|
389
|
-
error: {
|
|
390
|
-
code: httpError.code || httpError.name || "Error",
|
|
391
|
-
message: httpError.body || httpError.message || "Unknown error",
|
|
392
|
-
name: httpError.name || "Error"
|
|
393
|
-
}
|
|
394
|
-
},
|
|
395
|
-
headers: httpError.headers,
|
|
396
|
-
statusCode: httpError.statusCode || 500
|
|
397
|
-
};
|
|
398
|
-
}
|
|
399
|
-
} else {
|
|
400
|
-
errorResponse = {
|
|
401
|
-
body: {
|
|
402
|
-
error: {
|
|
403
|
-
code: httpError.code || httpError.name || "Error",
|
|
404
|
-
message: httpError.message || "Unknown error",
|
|
405
|
-
name: httpError.name || "Error"
|
|
406
|
-
}
|
|
407
|
-
},
|
|
408
|
-
headers: httpError.headers,
|
|
409
|
-
statusCode: httpError.statusCode || 500
|
|
410
|
-
};
|
|
411
|
-
}
|
|
412
|
-
this.send(response, errorResponse);
|
|
413
|
-
}
|
|
414
|
-
/**
|
|
415
|
-
* Sends streaming response to client with proper backpressure handling and range request support.
|
|
416
|
-
* @param response Node.js ServerResponse to stream data to.
|
|
417
|
-
* @param stream Readable stream containing the file data.
|
|
418
|
-
* @param options Streaming options including headers, range, size, and status code.
|
|
419
|
-
*/
|
|
420
|
-
sendStream(response, stream, {
|
|
421
|
-
headers = {},
|
|
422
|
-
range,
|
|
423
|
-
size,
|
|
424
|
-
statusCode = 200
|
|
425
|
-
}) {
|
|
426
|
-
setHeaders(response, headers);
|
|
427
|
-
response.statusCode = statusCode;
|
|
428
|
-
let finalStream = stream;
|
|
429
|
-
if (range && size) {
|
|
430
|
-
response.statusCode = 206;
|
|
431
|
-
response.setHeader("Content-Range", `bytes ${range.start}-${range.end}/${size}`);
|
|
432
|
-
response.setHeader("Content-Length", range.end - range.start + 1);
|
|
433
|
-
response.setHeader("Accept-Ranges", "bytes");
|
|
434
|
-
finalStream = createRangeLimitedStream(stream, range.start, range.end);
|
|
435
|
-
} else {
|
|
436
|
-
if (size) {
|
|
437
|
-
response.setHeader("Content-Length", size);
|
|
438
|
-
}
|
|
439
|
-
response.setHeader("Accept-Ranges", "bytes");
|
|
440
|
-
}
|
|
441
|
-
pipeWithBackpressure(finalStream, response, (resp, error) => this.sendError(resp, error));
|
|
442
|
-
}
|
|
443
|
-
/**
|
|
444
|
-
* Finish upload by sending final response to client with completed file data.
|
|
445
|
-
* @param _request HTTP request (unused parameter)
|
|
446
|
-
* @param response HTTP response object to send final response to
|
|
447
|
-
* @param uploadResponse Final upload response data containing body, headers, and status code
|
|
448
|
-
*/
|
|
449
|
-
finish(_request, response, uploadResponse) {
|
|
450
|
-
const isResponseFile = "id" in uploadResponse && "headers" in uploadResponse && !("body" in uploadResponse);
|
|
451
|
-
let body;
|
|
452
|
-
let headers;
|
|
453
|
-
let statusCode;
|
|
454
|
-
if (isResponseFile) {
|
|
455
|
-
const responseFile = uploadResponse;
|
|
456
|
-
const fileHeaders = responseFile.headers || {};
|
|
457
|
-
const fileStatusCode = responseFile.statusCode || 200;
|
|
458
|
-
const { headers: _, statusCode: __, ...fileData } = responseFile;
|
|
459
|
-
body = fileData;
|
|
460
|
-
headers = { ...fileHeaders };
|
|
461
|
-
statusCode = fileStatusCode;
|
|
462
|
-
} else {
|
|
463
|
-
const uploadResp = uploadResponse;
|
|
464
|
-
body = uploadResp.body;
|
|
465
|
-
headers = uploadResp.headers || {};
|
|
466
|
-
statusCode = uploadResp.statusCode || 200;
|
|
467
|
-
}
|
|
468
|
-
if (body && typeof body === "object" && body.content !== void 0) {
|
|
469
|
-
const { content, contentType } = body;
|
|
470
|
-
body = content;
|
|
471
|
-
headers = {
|
|
472
|
-
...headers,
|
|
473
|
-
"Content-Type": contentType
|
|
474
|
-
};
|
|
475
|
-
}
|
|
476
|
-
this.send(response, {
|
|
477
|
-
body: body || uploadResponse,
|
|
478
|
-
headers,
|
|
479
|
-
statusCode
|
|
480
|
-
});
|
|
481
|
-
}
|
|
482
|
-
/**
|
|
483
|
-
* Build file URL from request and file data.
|
|
484
|
-
* @param request HTTP request with optional originalUrl property
|
|
485
|
-
* @param file File object containing ID and content type
|
|
486
|
-
* @returns Constructed file URL with extension based on content type
|
|
487
|
-
*/
|
|
488
|
-
buildFileUrl(request, file) {
|
|
489
|
-
return this.buildFileUrlFromString(request.originalUrl || request.url, file);
|
|
490
|
-
}
|
|
491
|
-
/**
|
|
492
|
-
* Negotiates content type based on Accept header and supported formats.
|
|
493
|
-
* @param request HTTP request object containing Accept header.
|
|
494
|
-
* @param supportedTypes Array of supported MIME types to match against.
|
|
495
|
-
* @returns Best matching content type or undefined if no match found.
|
|
496
|
-
*/
|
|
497
|
-
negotiateContentType(request, supportedTypes) {
|
|
498
|
-
return super.negotiateContentTypeFromHeader(request.headers.accept, supportedTypes);
|
|
499
|
-
}
|
|
500
|
-
/**
|
|
501
|
-
* Default OPTIONS handler.
|
|
502
|
-
* @param _request HTTP request (unused)
|
|
503
|
-
* @param _response HTTP response (unused)
|
|
504
|
-
* @returns Promise resolving to ResponseFile with CORS headers
|
|
505
|
-
*/
|
|
506
|
-
async options(_request, _response) {
|
|
507
|
-
const child = this.constructor;
|
|
508
|
-
return {
|
|
509
|
-
headers: {
|
|
510
|
-
"Access-Control-Allow-Methods": (child.methods || BaseHandlerNode.methods).map((method) => method.toUpperCase()).join(", ")
|
|
511
|
-
},
|
|
512
|
-
statusCode: 204
|
|
513
|
-
};
|
|
514
|
-
}
|
|
515
|
-
/**
|
|
516
|
-
* Retrieves a file or list of files based on the request path.
|
|
517
|
-
* @param request Node.js IncomingMessage with optional originalUrl.
|
|
518
|
-
* @param response Node.js ServerResponse.
|
|
519
|
-
* @returns Promise resolving to a single file, paginated list, or array of files.
|
|
520
|
-
* @throws {UploadError} When file is not found or storage error occurs.
|
|
521
|
-
*/
|
|
522
|
-
// eslint-disable-next-line sonarjs/cognitive-complexity
|
|
523
|
-
async get(request, _response) {
|
|
524
|
-
const pathMatch = filePathUrlMatcher(getRealPath(request));
|
|
525
|
-
if (pathMatch && pathMatch.params.uuid) {
|
|
526
|
-
const { ext, metadata, uuid: rawUuid } = pathMatch.params;
|
|
527
|
-
const uuid = ext ? rawUuid.replace(new RegExp(String.raw`\.${ext}$`), "") : rawUuid;
|
|
528
|
-
if (metadata === "metadata" && getRealPath(request).endsWith("/metadata")) {
|
|
529
|
-
try {
|
|
530
|
-
const file = await this.storage.getMeta(uuid);
|
|
531
|
-
return {
|
|
532
|
-
...file,
|
|
533
|
-
content: JSON.stringify(file),
|
|
534
|
-
headers: {
|
|
535
|
-
"Content-Type": HeaderUtilities.createContentType({
|
|
536
|
-
charset: "utf8",
|
|
537
|
-
mediaType: "application/json"
|
|
538
|
-
}),
|
|
539
|
-
...file.expiredAt === void 0 ? {} : { "X-Upload-Expires": file.expiredAt.toString() },
|
|
540
|
-
...file.modifiedAt === void 0 ? {} : { "Last-Modified": file.modifiedAt.toString() }
|
|
541
|
-
},
|
|
542
|
-
statusCode: 200
|
|
543
|
-
};
|
|
544
|
-
} catch (error) {
|
|
545
|
-
const errorWithCode = error;
|
|
546
|
-
if (errorWithCode.UploadErrorCode === ERRORS.FILE_NOT_FOUND || errorWithCode.UploadErrorCode === ERRORS.GONE) {
|
|
547
|
-
throw createHttpError(404, "File metadata not found");
|
|
548
|
-
}
|
|
549
|
-
throw error;
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
if (!uuidRegex.test(uuid)) {
|
|
553
|
-
return this.list(request, _response);
|
|
554
|
-
}
|
|
555
|
-
try {
|
|
556
|
-
const url = new URL(request.url || "", "http://localhost");
|
|
557
|
-
const queryParameters = Object.fromEntries(url.searchParams.entries());
|
|
558
|
-
const hasTransformationParameters = Object.keys(queryParameters).length > 0 && this.mediaTransformer;
|
|
559
|
-
if (hasTransformationParameters && this.mediaTransformer) {
|
|
560
|
-
try {
|
|
561
|
-
const transformedResult = await this.mediaTransformer.handle(uuid, queryParameters);
|
|
562
|
-
return {
|
|
563
|
-
content: transformedResult.buffer,
|
|
564
|
-
headers: {
|
|
565
|
-
"Content-Length": String(transformedResult.size),
|
|
566
|
-
"Content-Type": `${transformedResult.mediaType}/${transformedResult.format}`,
|
|
567
|
-
"X-Media-Type": transformedResult.mediaType,
|
|
568
|
-
"X-Original-Format": transformedResult.originalFile?.contentType?.split("/")[1] || "",
|
|
569
|
-
"X-Transformed-Format": transformedResult.format,
|
|
570
|
-
...transformedResult.originalFile?.expiredAt === void 0 ? {} : { "X-Upload-Expires": transformedResult.originalFile.expiredAt.toString() },
|
|
571
|
-
...transformedResult.originalFile?.modifiedAt === void 0 ? {} : { "Last-Modified": transformedResult.originalFile.modifiedAt.toString() },
|
|
572
|
-
...transformedResult.originalFile?.ETag === void 0 ? {} : { ETag: transformedResult.originalFile.ETag }
|
|
573
|
-
},
|
|
574
|
-
statusCode: 200
|
|
575
|
-
};
|
|
576
|
-
} catch (transformError) {
|
|
577
|
-
if (transformError.name === "ValidationError") {
|
|
578
|
-
throw createHttpError(400, transformError.message);
|
|
579
|
-
}
|
|
580
|
-
this.logger?.warn(`Media transformation failed: ${transformError.message}`);
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
const fileMeta = await this.storage.getMeta(uuid);
|
|
584
|
-
const useStreaming = request.headers.range || fileMeta.size && fileMeta.size > 1024 * 1024;
|
|
585
|
-
if (useStreaming && this.storage.getStream) {
|
|
586
|
-
try {
|
|
587
|
-
const streamResult = await this.storage.getStream({ id: uuid });
|
|
588
|
-
let contentType2 = streamResult.headers?.["Content-Type"] || fileMeta.contentType;
|
|
589
|
-
if (contentType2.includes("image") && typeof ext === "string") {
|
|
590
|
-
contentType2 = mime.getType(ext) || contentType2;
|
|
591
|
-
}
|
|
592
|
-
return {
|
|
593
|
-
headers: {
|
|
594
|
-
...streamResult.headers,
|
|
595
|
-
"Accept-Ranges": "bytes",
|
|
596
|
-
// Indicate we support range requests
|
|
597
|
-
"Content-Type": contentType2
|
|
598
|
-
},
|
|
599
|
-
size: streamResult.size,
|
|
600
|
-
statusCode: 200,
|
|
601
|
-
stream: streamResult.stream,
|
|
602
|
-
...fileMeta,
|
|
603
|
-
contentType: contentType2
|
|
604
|
-
};
|
|
605
|
-
} catch (streamError) {
|
|
606
|
-
this.logger?.warn(`Streaming failed, falling back to buffer: ${streamError}`);
|
|
607
|
-
}
|
|
608
|
-
}
|
|
609
|
-
const file = await this.storage.get({ id: uuid });
|
|
610
|
-
let { contentType } = file;
|
|
611
|
-
if (contentType.includes("image") && typeof ext === "string") {
|
|
612
|
-
contentType = mime.getType(ext) || contentType;
|
|
613
|
-
}
|
|
614
|
-
const { ETag, expiredAt, modifiedAt, size } = file;
|
|
615
|
-
return {
|
|
616
|
-
headers: {
|
|
617
|
-
"Accept-Ranges": "bytes",
|
|
618
|
-
// Indicate we support range requests
|
|
619
|
-
"Content-Length": String(size),
|
|
620
|
-
"Content-Type": contentType,
|
|
621
|
-
...expiredAt === void 0 ? {} : { "X-Upload-Expires": expiredAt.toString() },
|
|
622
|
-
...modifiedAt === void 0 ? {} : { "Last-Modified": modifiedAt.toString() },
|
|
623
|
-
...ETag === void 0 ? {} : { ETag }
|
|
624
|
-
},
|
|
625
|
-
statusCode: 200,
|
|
626
|
-
...file,
|
|
627
|
-
contentType
|
|
628
|
-
};
|
|
629
|
-
} catch (error) {
|
|
630
|
-
const errorWithCode = error;
|
|
631
|
-
if (errorWithCode.UploadErrorCode === ERRORS.FILE_NOT_FOUND || errorWithCode.UploadErrorCode === ERRORS.GONE) {
|
|
632
|
-
throw createHttpError(404, "File not found");
|
|
633
|
-
}
|
|
634
|
-
throw error;
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
return this.list(request, _response);
|
|
638
|
-
}
|
|
639
|
-
/**
|
|
640
|
-
* Returns a list of uploaded files with optional pagination support.
|
|
641
|
-
* @param request Node.js IncomingMessage containing query parameters for pagination.
|
|
642
|
-
* @param _response Node.js ServerResponse (unused).
|
|
643
|
-
* @returns Promise resolving to a paginated or complete list of uploaded files.
|
|
644
|
-
*/
|
|
645
|
-
async list(request, _response) {
|
|
646
|
-
const url = new URL(request.url || "", "http://localhost");
|
|
647
|
-
const limit = url.searchParams.get("limit");
|
|
648
|
-
const page = url.searchParams.get("page");
|
|
649
|
-
const list = await this.storage.list(Number(limit || 1e3));
|
|
650
|
-
if (list.length === 0) {
|
|
651
|
-
return {
|
|
652
|
-
data: [],
|
|
653
|
-
headers: {},
|
|
654
|
-
statusCode: 200
|
|
655
|
-
};
|
|
656
|
-
}
|
|
657
|
-
if (page !== void 0 && limit !== void 0) {
|
|
658
|
-
return {
|
|
659
|
-
data: paginate(Number(page), Number(limit), list.length, list),
|
|
660
|
-
headers: {},
|
|
661
|
-
statusCode: 200
|
|
662
|
-
};
|
|
663
|
-
}
|
|
664
|
-
return {
|
|
665
|
-
data: list,
|
|
666
|
-
headers: {},
|
|
667
|
-
statusCode: 200
|
|
668
|
-
};
|
|
669
|
-
}
|
|
670
|
-
/**
|
|
671
|
-
* Streams download of a file with resumable support using HTTP range requests.
|
|
672
|
-
* @param request Node.js IncomingMessage with optional originalUrl and range header.
|
|
673
|
-
* @param response Node.js ServerResponse to stream the file to.
|
|
674
|
-
* @throws {HttpError} When file is not found or streaming is not supported.
|
|
675
|
-
*/
|
|
676
|
-
async download(request, response) {
|
|
677
|
-
const pathMatch = filePathUrlMatcher(getRealPath(request));
|
|
678
|
-
if (!pathMatch || !pathMatch.params.uuid || !uuidRegex.test(pathMatch.params.uuid)) {
|
|
679
|
-
throw createHttpError(404, "File not found");
|
|
680
|
-
}
|
|
681
|
-
const { ext, uuid } = pathMatch.params;
|
|
682
|
-
try {
|
|
683
|
-
const fileMeta = await this.storage.getMeta(uuid);
|
|
684
|
-
if (!this.storage.getStream) {
|
|
685
|
-
await this.sendError(response, createHttpError(501, "Streaming download not supported"));
|
|
686
|
-
return;
|
|
687
|
-
}
|
|
688
|
-
const streamResult = await this.storage.getStream({ id: uuid });
|
|
689
|
-
let contentType = streamResult.headers?.["Content-Type"] || fileMeta.contentType;
|
|
690
|
-
if (contentType.includes("image") && typeof ext === "string") {
|
|
691
|
-
contentType = mime.getType(ext) || contentType;
|
|
692
|
-
}
|
|
693
|
-
const range = this.parseRangeHeader(request.headers.range, streamResult.size || 0);
|
|
694
|
-
const headers = {
|
|
695
|
-
...streamResult.headers,
|
|
696
|
-
"Accept-Ranges": "bytes",
|
|
697
|
-
"Content-Disposition": HeaderUtilities.createContentDisposition({
|
|
698
|
-
filename: fileMeta.originalName || uuid,
|
|
699
|
-
type: "attachment"
|
|
700
|
-
}),
|
|
701
|
-
"Content-Type": contentType
|
|
702
|
-
};
|
|
703
|
-
this.sendStream(response, streamResult.stream, {
|
|
704
|
-
headers,
|
|
705
|
-
range: range || void 0,
|
|
706
|
-
size: streamResult.size,
|
|
707
|
-
statusCode: range ? 206 : 200
|
|
708
|
-
});
|
|
709
|
-
} catch (error) {
|
|
710
|
-
const errorWithCode = error;
|
|
711
|
-
if (errorWithCode.UploadErrorCode === ERRORS.FILE_NOT_FOUND || errorWithCode.UploadErrorCode === ERRORS.GONE) {
|
|
712
|
-
await this.sendError(response, createHttpError(404, "File not found"));
|
|
713
|
-
return;
|
|
714
|
-
}
|
|
715
|
-
await this.sendError(response, error);
|
|
716
|
-
}
|
|
717
|
-
}
|
|
718
|
-
/**
|
|
719
|
-
* Check if error is related to undefined ID or path and throw appropriate HTTP error.
|
|
720
|
-
* @param error Error object to check
|
|
721
|
-
*/
|
|
722
|
-
// eslint-disable-next-line class-methods-use-this
|
|
723
|
-
checkForUndefinedIdOrPath(error) {
|
|
724
|
-
if (error instanceof Error && ["Id is undefined", "Invalid request URL", "Path is undefined"].includes(error.message)) {
|
|
725
|
-
throw createHttpError(404, "File not found");
|
|
726
|
-
}
|
|
727
|
-
}
|
|
728
|
-
}
|
|
729
|
-
|
|
730
|
-
export { BaseHandlerNode as B };
|