@visulima/storage 1.0.0-alpha.8 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +578 -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-Ba7cLu-t.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-DTBVxHXO.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-BFsD4qbF.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-DFwhEI9C.js +1 -0
- package/dist/packem_shared/BoxStorage-B_t-OVzf.js +1 -0
- package/dist/packem_shared/BunS3File-BcYmsz1n.js +1 -0
- package/dist/packem_shared/BunS3MetaStorage-DFwhEI9C.js +1 -0
- package/dist/packem_shared/BunS3Storage-CB_pZWlV.js +1 -0
- package/dist/packem_shared/BunnyFile-BgEOlcYI.js +1 -0
- package/dist/packem_shared/BunnyMetaStorage-DFwhEI9C.js +1 -0
- package/dist/packem_shared/BunnyStorage-CILSK4_Z.js +1 -0
- package/dist/packem_shared/CloudinaryFile-Bo5B-vM1.js +1 -0
- package/dist/packem_shared/CloudinaryMetaStorage-D_vNzewL.js +1 -0
- package/dist/packem_shared/CloudinaryStorage-DiCbdAi_.js +1 -0
- package/dist/packem_shared/DiskStorage-Kp5t3vnF.js +1 -0
- package/dist/packem_shared/DiskStorageWithChecksum-Bh6w-Iu8.js +1 -0
- package/dist/packem_shared/DropboxFile-BFb7eOzy.js +1 -0
- package/dist/packem_shared/DropboxMetaStorage-DFwhEI9C.js +1 -0
- package/dist/packem_shared/DropboxStorage-H8bd8hEz.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-BA3mpDwz.js +1 -0
- package/dist/packem_shared/FirebaseFile-BLaBxa2A.js +1 -0
- package/dist/packem_shared/FirebaseMetaStorage-D_vNzewL.js +1 -0
- package/dist/packem_shared/FirebaseStorage-Dgk4XyMr.js +2 -0
- package/dist/packem_shared/FtpFile-ClWDYnt2.js +1 -0
- package/dist/packem_shared/FtpMetaStorage-DFwhEI9C.js +1 -0
- package/dist/packem_shared/FtpStorage-g_DjiR-C.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-3fLTlRd4.js +1 -0
- package/dist/packem_shared/GCStorage-DUfwVFd3.js +1 -0
- package/dist/packem_shared/GoogleDriveFile-DHpLhzg9.js +1 -0
- package/dist/packem_shared/GoogleDriveMetaStorage-DqkgoE46.js +1 -0
- package/dist/packem_shared/GoogleDriveStorage-D0-5egHE.js +1 -0
- package/dist/packem_shared/LocalMetaStorage-Bp5mVc76.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-DzSTdlAq.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-Btj2mo9r.js +1 -0
- package/dist/packem_shared/Multipart-C4GpuHMU.js +1 -0
- package/dist/packem_shared/NetlifyBlobFile-DoFhkzaH.js +1 -0
- package/dist/packem_shared/NetlifyBlobMetaStorage-D_vNzewL.js +1 -0
- package/dist/packem_shared/NetlifyBlobStorage-DZdCmOVW.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-DqkgoE46.js +1 -0
- package/dist/packem_shared/OneDriveStorage-CvJetV7_.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-CpvDRnSu.js +1 -0
- package/dist/packem_shared/PocketBaseStorage-BPil-koe.js +1 -0
- package/dist/packem_shared/Rest-BehVaxbl.js +1 -0
- package/dist/packem_shared/Rest-ymPCZkKR.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-wslqssvr.js +1 -0
- package/dist/packem_shared/SftpFile-ClWDYnt2.js +1 -0
- package/dist/packem_shared/SftpMetaStorage-DFwhEI9C.js +1 -0
- package/dist/packem_shared/SftpStorage-BVbMtS2b.js +1 -0
- package/dist/packem_shared/SharePointFile-Blz9FS4h.js +1 -0
- package/dist/packem_shared/SharePointMetaStorage-DFwhEI9C.js +1 -0
- package/dist/packem_shared/SharePointStorage-DWjvR5oZ.js +1 -0
- package/dist/packem_shared/SupabaseFile-Bo5B-vM1.js +1 -0
- package/dist/packem_shared/SupabaseMetaStorage-DqkgoE46.js +1 -0
- package/dist/packem_shared/SupabaseStorage-BiKmYKb6.js +1 -0
- package/dist/packem_shared/TUS_RESUMABLE-CyTSRvPU.js +1 -0
- package/dist/packem_shared/Tus-BgbON_wQ.js +1 -0
- package/dist/packem_shared/Tus-v6jzkaIO.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-D_vNzewL.js +1 -0
- package/dist/packem_shared/UploadThingStorage-jrEnANC5.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-DFwhEI9C.js +1 -0
- package/dist/packem_shared/VercelBlobStorage-Y-cDgH30.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-EeV8gZck.js +1 -0
- package/dist/packem_shared/base-handler-fetch-CHzsgb7C.js +1 -0
- package/dist/packem_shared/base-handler-node-BjpW8pGi.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-DIn-VnCh.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-Dy37wCjI.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-C2T92TYb.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-BVg7lYf5.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-CynUg0mH.js +1 -0
- package/dist/packem_shared/restOpenApiSpec-Csv513qf.js +1 -0
- package/dist/packem_shared/s3-base-storage-DXZYN24h.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-Cyy73Y6r.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 +202 -50
- 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-BlltBst6.js +0 -12
- package/dist/packem_shared/DiskStorageWithChecksum-BJTmMklc.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-BYhwecZl.js +0 -7
- package/dist/packem_shared/GCStorage-BmnoK7Rz.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-5Xpy7WhY.js +0 -163
- package/dist/packem_shared/Multipart-C-iU9LXj.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-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-DO7OslCs.js +0 -267
- package/dist/packem_shared/Rest-DTaszQ6n.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-DHmTk-hU.js +0 -316
- package/dist/packem_shared/TUS_RESUMABLE-BfguFdM1.js +0 -434
- package/dist/packem_shared/Tus-BQItPVAC.js +0 -200
- package/dist/packem_shared/Tus-BibjweWH.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-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-DLEVHemv.js +0 -303
- package/dist/packem_shared/base-handler-fetch-A7V0N6AJ.js +0 -291
- package/dist/packem_shared/base-handler-node-Dx7ce3sU.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-Bh2wy3YW.js +0 -810
- package/dist/packem_shared/gcs-meta-storage-DqNjM7DP.js +0 -158
- package/dist/packem_shared/has-content-CY66ehMK.js +0 -3
- package/dist/packem_shared/headers-C9DasoT1.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-BY0rhkw5.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-Bt9Np3M8.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,1100 +1 @@
|
|
|
1
|
-
import { Readable } from 'node:stream';
|
|
2
|
-
import sharp from 'sharp';
|
|
3
|
-
import BaseTransformer from '../packem_shared/BaseTransformer-C2gLib6v.js';
|
|
4
|
-
import { isValidMediaType, getFormatFromContentType } from '../packem_shared/isValidMediaType-BeDgiObq.js';
|
|
5
|
-
|
|
6
|
-
class ImageTransformer extends BaseTransformer {
|
|
7
|
-
/**
|
|
8
|
-
* Creates a new ImageTransformer instance.
|
|
9
|
-
* @param storage The storage backend for retrieving and storing image files.
|
|
10
|
-
* @param config Configuration options for image transformation including cache settings and size limits.
|
|
11
|
-
*/
|
|
12
|
-
constructor(storage, config = {}) {
|
|
13
|
-
const logger = config.logger || storage.logger;
|
|
14
|
-
const transformerConfig = {
|
|
15
|
-
cacheTtl: 3600,
|
|
16
|
-
// 1 hour
|
|
17
|
-
maxCacheSize: 100,
|
|
18
|
-
// Max 100 transformed images in cache
|
|
19
|
-
maxImageSize: 50 * 1024 * 1024,
|
|
20
|
-
// 50MB
|
|
21
|
-
supportedFormats: ["jpeg", "png", "webp", "avif", "tiff", "gif", "svg"],
|
|
22
|
-
...config
|
|
23
|
-
};
|
|
24
|
-
super(storage, transformerConfig, logger);
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Resizes an image to specified dimensions with optional fit mode.
|
|
28
|
-
* @param fileId Unique identifier of the image file to resize.
|
|
29
|
-
* @param options Resize options including width, height, and fit mode.
|
|
30
|
-
* @returns Promise resolving to transformed image result.
|
|
31
|
-
*/
|
|
32
|
-
async resize(fileId, options) {
|
|
33
|
-
return this.transform(fileId, [{ options, type: "resize" }]);
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Crops an image to the specified region.
|
|
37
|
-
* @param fileId Unique identifier of the image file to crop.
|
|
38
|
-
* @param options Crop options including region coordinates.
|
|
39
|
-
* @returns Promise resolving to transformed image result.
|
|
40
|
-
*/
|
|
41
|
-
async crop(fileId, options) {
|
|
42
|
-
return this.transform(fileId, [{ options, type: "crop" }]);
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Rotates an image by the specified angle.
|
|
46
|
-
* @param fileId Unique identifier of the image file to rotate.
|
|
47
|
-
* @param options Rotate options including angle.
|
|
48
|
-
* @returns Promise resolving to transformed image result.
|
|
49
|
-
*/
|
|
50
|
-
async rotate(fileId, options) {
|
|
51
|
-
return this.transform(fileId, [{ options, type: "rotate" }]);
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Converts an image to the specified format.
|
|
55
|
-
* @param fileId Unique identifier of the image file to convert.
|
|
56
|
-
* @param format Target image format (e.g., "jpeg", "png", "webp").
|
|
57
|
-
* @param options Additional transform options.
|
|
58
|
-
* @returns Promise resolving to transformed image result.
|
|
59
|
-
*/
|
|
60
|
-
async convertFormat(fileId, format, options = {}) {
|
|
61
|
-
return this.transform(fileId, [{ options: { ...options, format }, type: "format" }]);
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Applies sharpening filter to an image.
|
|
65
|
-
* @param fileId Unique identifier of the image file to sharpen.
|
|
66
|
-
* @param options Sharpen options including sigma and flat/jagged threshold.
|
|
67
|
-
* @returns Promise resolving to transformed image result.
|
|
68
|
-
*/
|
|
69
|
-
async sharpen(fileId, options = {}) {
|
|
70
|
-
return this.transform(fileId, [{ options, type: "sharpen" }]);
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Applies blurring filter to an image.
|
|
74
|
-
* @param fileId Unique identifier of the image file to blur.
|
|
75
|
-
* @param options Blur options including sigma.
|
|
76
|
-
* @returns Promise resolving to transformed image result.
|
|
77
|
-
*/
|
|
78
|
-
async blur(fileId, options = {}) {
|
|
79
|
-
return this.transform(fileId, [{ options, type: "blur" }]);
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Applies median filter to an image for noise reduction.
|
|
83
|
-
* @param fileId Unique identifier of the image file to process.
|
|
84
|
-
* @param options Median filter options including radius.
|
|
85
|
-
* @returns Promise resolving to transformed image result.
|
|
86
|
-
*/
|
|
87
|
-
async median(fileId, options = {}) {
|
|
88
|
-
return this.transform(fileId, [{ options, type: "median" }]);
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Applies CLAHE (Contrast Limited Adaptive Histogram Equalization) to an image.
|
|
92
|
-
* @param fileId Unique identifier of the image file to process.
|
|
93
|
-
* @param options CLAHE options including width, height, and maxSlope.
|
|
94
|
-
* @returns Promise resolving to transformed image result.
|
|
95
|
-
*/
|
|
96
|
-
async clahe(fileId, options = {}) {
|
|
97
|
-
return this.transform(fileId, [{ options, type: "clahe" }]);
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Applies convolution kernel to an image.
|
|
101
|
-
* @param fileId Unique identifier of the image file to process.
|
|
102
|
-
* @param options Convolve options including kernel matrix.
|
|
103
|
-
* @returns Promise resolving to transformed image result.
|
|
104
|
-
*/
|
|
105
|
-
async convolve(fileId, options) {
|
|
106
|
-
return this.transform(fileId, [{ options, type: "convolve" }]);
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Applies thresholding to an image to create a binary image.
|
|
110
|
-
* @param fileId Unique identifier of the image file to process.
|
|
111
|
-
* @param options Threshold options including threshold value.
|
|
112
|
-
* @returns Promise resolving to transformed image result.
|
|
113
|
-
*/
|
|
114
|
-
async threshold(fileId, options = {}) {
|
|
115
|
-
return this.transform(fileId, [{ options, type: "threshold" }]);
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Applies boolean operation to an image.
|
|
119
|
-
* @param fileId Unique identifier of the image file to process.
|
|
120
|
-
* @param options Boolean operation options including operator and operand.
|
|
121
|
-
* @returns Promise resolving to transformed image result.
|
|
122
|
-
*/
|
|
123
|
-
async boolean(fileId, options) {
|
|
124
|
-
return this.transform(fileId, [{ options, type: "boolean" }]);
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Applies linear transformation to an image.
|
|
128
|
-
* @param fileId Unique identifier of the image file to process.
|
|
129
|
-
* @param options Linear transformation options including a and b coefficients.
|
|
130
|
-
* @returns Promise resolving to transformed image result.
|
|
131
|
-
*/
|
|
132
|
-
async linear(fileId, options) {
|
|
133
|
-
return this.transform(fileId, [{ options, type: "linear" }]);
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Applies recombine transformation to an image using a matrix.
|
|
137
|
-
* @param fileId Unique identifier of the image file to process.
|
|
138
|
-
* @param options Recombine options including matrix coefficients.
|
|
139
|
-
* @returns Promise resolving to transformed image result.
|
|
140
|
-
*/
|
|
141
|
-
async recombine(fileId, options) {
|
|
142
|
-
return this.transform(fileId, [{ options, type: "recombine" }]);
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Applies modulation (brightness, saturation, hue) to an image.
|
|
146
|
-
* @param fileId Unique identifier of the image file to process.
|
|
147
|
-
* @param options Modulate options including brightness, saturation, and hue.
|
|
148
|
-
* @returns Promise resolving to transformed image result.
|
|
149
|
-
*/
|
|
150
|
-
async modulate(fileId, options) {
|
|
151
|
-
return this.transform(fileId, [{ options, type: "modulate" }]);
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* Applies tinting to an image.
|
|
155
|
-
* @param fileId Unique identifier of the image file to process.
|
|
156
|
-
* @param options Tint options including RGB color values.
|
|
157
|
-
* @returns Promise resolving to transformed image result.
|
|
158
|
-
*/
|
|
159
|
-
async tint(fileId, options) {
|
|
160
|
-
return this.transform(fileId, [{ options, type: "tint" }]);
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* Converts an image to greyscale.
|
|
164
|
-
* @param fileId Unique identifier of the image file to convert.
|
|
165
|
-
* @param options Greyscale conversion options.
|
|
166
|
-
* @returns Promise resolving to transformed image result.
|
|
167
|
-
*/
|
|
168
|
-
async greyscale(fileId, options = {}) {
|
|
169
|
-
return this.transform(fileId, [{ options, type: "greyscale" }]);
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Converts an image to a different colourspace.
|
|
173
|
-
* @param fileId Unique identifier of the image file to convert.
|
|
174
|
-
* @param options Colourspace conversion options including target colourspace.
|
|
175
|
-
* @returns Promise resolving to transformed image result.
|
|
176
|
-
*/
|
|
177
|
-
async colourspace(fileId, options) {
|
|
178
|
-
return this.transform(fileId, [{ options, type: "colourspace" }]);
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* Extracts a specific channel from an image.
|
|
182
|
-
* @param fileId Unique identifier of the image file to process.
|
|
183
|
-
* @param options Extract channel options including channel index.
|
|
184
|
-
* @returns Promise resolving to transformed image result.
|
|
185
|
-
*/
|
|
186
|
-
async extractChannel(fileId, options) {
|
|
187
|
-
return this.transform(fileId, [{ options, type: "extractChannel" }]);
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* Joins channels to an image.
|
|
191
|
-
* @param fileId Unique identifier of the image file to process.
|
|
192
|
-
* @param options Join channel options including channel sources.
|
|
193
|
-
* @returns Promise resolving to transformed image result.
|
|
194
|
-
*/
|
|
195
|
-
async joinChannel(fileId, options) {
|
|
196
|
-
return this.transform(fileId, [{ options, type: "joinChannel" }]);
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* Applies band boolean operation to an image.
|
|
200
|
-
* @param fileId Unique identifier of the image file to process.
|
|
201
|
-
* @param options Band boolean options including operator.
|
|
202
|
-
* @returns Promise resolving to transformed image result.
|
|
203
|
-
*/
|
|
204
|
-
async bandbool(fileId, options) {
|
|
205
|
-
return this.transform(fileId, [{ options, type: "bandbool" }]);
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* Auto-orients an image based on EXIF orientation data.
|
|
209
|
-
* @param fileId Unique identifier of the image file to orient.
|
|
210
|
-
* @param options Additional transform options.
|
|
211
|
-
* @returns Promise resolving to transformed image result.
|
|
212
|
-
*/
|
|
213
|
-
async autoOrient(fileId, options = {}) {
|
|
214
|
-
return this.transform(fileId, [{ options, type: "autoOrient" }]);
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* Flips an image vertically.
|
|
218
|
-
* @param fileId Unique identifier of the image file to flip.
|
|
219
|
-
* @param options Additional transform options.
|
|
220
|
-
* @returns Promise resolving to transformed image result.
|
|
221
|
-
*/
|
|
222
|
-
async flip(fileId, options = {}) {
|
|
223
|
-
return this.transform(fileId, [{ options, type: "flip" }]);
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* Flops an image horizontally.
|
|
227
|
-
* @param fileId Unique identifier of the image file to flop.
|
|
228
|
-
* @param options Additional transform options.
|
|
229
|
-
* @returns Promise resolving to transformed image result.
|
|
230
|
-
*/
|
|
231
|
-
async flop(fileId, options = {}) {
|
|
232
|
-
return this.transform(fileId, [{ options, type: "flop" }]);
|
|
233
|
-
}
|
|
234
|
-
/**
|
|
235
|
-
* Flattens an image alpha channel onto a background color.
|
|
236
|
-
* @param fileId Unique identifier of the image file to flatten.
|
|
237
|
-
* @param options Additional transform options.
|
|
238
|
-
* @returns Promise resolving to transformed image result.
|
|
239
|
-
*/
|
|
240
|
-
async flatten(fileId, options = {}) {
|
|
241
|
-
return this.transform(fileId, [{ options, type: "flatten" }]);
|
|
242
|
-
}
|
|
243
|
-
/**
|
|
244
|
-
* Unflattens an image alpha channel.
|
|
245
|
-
* @param fileId Unique identifier of the image file to unflatten.
|
|
246
|
-
* @param options Additional transform options.
|
|
247
|
-
* @returns Promise resolving to transformed image result.
|
|
248
|
-
*/
|
|
249
|
-
async unflatten(fileId, options = {}) {
|
|
250
|
-
return this.transform(fileId, [{ options, type: "unflatten" }]);
|
|
251
|
-
}
|
|
252
|
-
/**
|
|
253
|
-
* Applies gamma correction to an image.
|
|
254
|
-
* @param fileId Unique identifier of the image file to process.
|
|
255
|
-
* @param options Additional transform options.
|
|
256
|
-
* @returns Promise resolving to transformed image result.
|
|
257
|
-
*/
|
|
258
|
-
async gamma(fileId, options = {}) {
|
|
259
|
-
return this.transform(fileId, [{ options, type: "gamma" }]);
|
|
260
|
-
}
|
|
261
|
-
/**
|
|
262
|
-
* Negates (inverts) an image.
|
|
263
|
-
* @param fileId Unique identifier of the image file to negate.
|
|
264
|
-
* @param options Additional transform options.
|
|
265
|
-
* @returns Promise resolving to transformed image result.
|
|
266
|
-
*/
|
|
267
|
-
async negate(fileId, options = {}) {
|
|
268
|
-
return this.transform(fileId, [{ options, type: "negate" }]);
|
|
269
|
-
}
|
|
270
|
-
/**
|
|
271
|
-
* Normalises an image by enhancing contrast.
|
|
272
|
-
* @param fileId Unique identifier of the image file to normalise.
|
|
273
|
-
* @param options Additional transform options.
|
|
274
|
-
* @returns Promise resolving to transformed image result.
|
|
275
|
-
*/
|
|
276
|
-
async normalise(fileId, options = {}) {
|
|
277
|
-
return this.transform(fileId, [{ options, type: "normalise" }]);
|
|
278
|
-
}
|
|
279
|
-
/**
|
|
280
|
-
* Applies affine transformation to an image.
|
|
281
|
-
* @param fileId Unique identifier of the image file to transform.
|
|
282
|
-
* @param options Affine transformation options including matrix.
|
|
283
|
-
* @returns Promise resolving to transformed image result.
|
|
284
|
-
*/
|
|
285
|
-
async affine(fileId, options) {
|
|
286
|
-
return this.transform(fileId, [{ options, type: "affine" }]);
|
|
287
|
-
}
|
|
288
|
-
/**
|
|
289
|
-
* Applies dilation (morphological operation) to an image.
|
|
290
|
-
* @param fileId Unique identifier of the image file to process.
|
|
291
|
-
* @param options Dilate options including iterations.
|
|
292
|
-
* @returns Promise resolving to transformed image result.
|
|
293
|
-
*/
|
|
294
|
-
async dilate(fileId, options = {}) {
|
|
295
|
-
return this.transform(fileId, [{ options, type: "dilate" }]);
|
|
296
|
-
}
|
|
297
|
-
/**
|
|
298
|
-
* Applies erosion (morphological operation) to an image.
|
|
299
|
-
* @param fileId Unique identifier of the image file to process.
|
|
300
|
-
* @param options Erode options including iterations.
|
|
301
|
-
* @returns Promise resolving to transformed image result.
|
|
302
|
-
*/
|
|
303
|
-
async erode(fileId, options = {}) {
|
|
304
|
-
return this.transform(fileId, [{ options, type: "erode" }]);
|
|
305
|
-
}
|
|
306
|
-
/**
|
|
307
|
-
* Sets pipeline colourspace for an image.
|
|
308
|
-
* @param fileId Unique identifier of the image file to process.
|
|
309
|
-
* @param options Pipeline colourspace options including colourspace.
|
|
310
|
-
* @returns Promise resolving to transformed image result.
|
|
311
|
-
*/
|
|
312
|
-
async pipelineColourspace(fileId, options) {
|
|
313
|
-
return this.transform(fileId, [{ options, type: "pipelineColourspace" }]);
|
|
314
|
-
}
|
|
315
|
-
/**
|
|
316
|
-
* Converts colourspace of an image.
|
|
317
|
-
* @param fileId Unique identifier of the image file to convert.
|
|
318
|
-
* @param options ToColourspace options including target colourspace.
|
|
319
|
-
* @returns Promise resolving to transformed image result.
|
|
320
|
-
*/
|
|
321
|
-
async toColourspace(fileId, options) {
|
|
322
|
-
return this.transform(fileId, [{ options, type: "toColourspace" }]);
|
|
323
|
-
}
|
|
324
|
-
/**
|
|
325
|
-
* Removes alpha channel from an image.
|
|
326
|
-
* @param fileId Unique identifier of the image file to process.
|
|
327
|
-
* @param options RemoveAlpha transformation options.
|
|
328
|
-
* @returns Promise resolving to transformed image result.
|
|
329
|
-
*/
|
|
330
|
-
async removeAlpha(fileId, options = {}) {
|
|
331
|
-
return this.transform(fileId, [{ options, type: "removeAlpha" }]);
|
|
332
|
-
}
|
|
333
|
-
/**
|
|
334
|
-
* Ensures alpha channel exists in an image.
|
|
335
|
-
* @param fileId Unique identifier of the image file to process.
|
|
336
|
-
* @param options EnsureAlpha transformation options.
|
|
337
|
-
* @returns Promise resolving to transformed image result.
|
|
338
|
-
*/
|
|
339
|
-
async ensureAlpha(fileId, options = {}) {
|
|
340
|
-
return this.transform(fileId, [{ options, type: "ensureAlpha" }]);
|
|
341
|
-
}
|
|
342
|
-
/**
|
|
343
|
-
* Applies a custom transformation pipeline to an image.
|
|
344
|
-
* @param fileId Unique identifier of the image file to transform.
|
|
345
|
-
* @param steps Array of transformation steps to apply in sequence.
|
|
346
|
-
* @returns Promise resolving to transformed image result.
|
|
347
|
-
*/
|
|
348
|
-
async transform(fileId, steps) {
|
|
349
|
-
const fileQuery = { id: fileId };
|
|
350
|
-
const cacheKey = this.generateCacheKey(fileId, steps);
|
|
351
|
-
const cached = this.cache ? await Promise.resolve(this.cache.get(cacheKey)) : void 0;
|
|
352
|
-
if (cached) {
|
|
353
|
-
this.logger?.debug("Returning cached transformed image for %s", fileId);
|
|
354
|
-
return cached;
|
|
355
|
-
}
|
|
356
|
-
const originalFile = await this.storage.get(fileQuery);
|
|
357
|
-
await this.validateImage(originalFile);
|
|
358
|
-
const transformedBuffer = await this.applyTransformations(originalFile.content, steps);
|
|
359
|
-
const result = await this.createTransformResult(transformedBuffer, originalFile);
|
|
360
|
-
if (this.cache) {
|
|
361
|
-
this.cache.set(cacheKey, result);
|
|
362
|
-
}
|
|
363
|
-
return result;
|
|
364
|
-
}
|
|
365
|
-
/**
|
|
366
|
-
* Streams transform of a file (for large files, falls back to regular transform).
|
|
367
|
-
* @param fileId Unique identifier of the image file to transform.
|
|
368
|
-
* @param steps Array of transformation steps to apply in sequence.
|
|
369
|
-
* @returns Promise resolving to stream with headers and size information.
|
|
370
|
-
*/
|
|
371
|
-
async transformStream(fileId, steps) {
|
|
372
|
-
const result = await this.transform(fileId, steps);
|
|
373
|
-
return {
|
|
374
|
-
headers: {
|
|
375
|
-
"Content-Length": result.buffer.length.toString(),
|
|
376
|
-
"Content-Type": this.getContentTypeFromResult(result),
|
|
377
|
-
"X-Image-Height": result.height?.toString(),
|
|
378
|
-
"X-Image-Width": result.width?.toString()
|
|
379
|
-
},
|
|
380
|
-
size: result.buffer.length,
|
|
381
|
-
stream: Readable.from(result.buffer)
|
|
382
|
-
};
|
|
383
|
-
}
|
|
384
|
-
/**
|
|
385
|
-
* Applies multiple transformations in sequence using Sharp.
|
|
386
|
-
* @param buffer The original image buffer.
|
|
387
|
-
* @param steps Array of transformation steps to apply.
|
|
388
|
-
* @returns Promise resolving to transformed image buffer.
|
|
389
|
-
* @private
|
|
390
|
-
*/
|
|
391
|
-
async applyTransformations(buffer, steps) {
|
|
392
|
-
let sharpInstance = sharp(buffer);
|
|
393
|
-
for (const step of steps) {
|
|
394
|
-
switch (step.type) {
|
|
395
|
-
case "affine": {
|
|
396
|
-
sharpInstance = this.applyAffine(sharpInstance, step.options);
|
|
397
|
-
break;
|
|
398
|
-
}
|
|
399
|
-
case "autoOrient": {
|
|
400
|
-
sharpInstance = sharpInstance.rotate();
|
|
401
|
-
break;
|
|
402
|
-
}
|
|
403
|
-
case "bandbool": {
|
|
404
|
-
sharpInstance = this.applyBandbool(sharpInstance, step.options);
|
|
405
|
-
break;
|
|
406
|
-
}
|
|
407
|
-
case "blur": {
|
|
408
|
-
sharpInstance = this.applyBlur(sharpInstance, step.options);
|
|
409
|
-
break;
|
|
410
|
-
}
|
|
411
|
-
case "boolean": {
|
|
412
|
-
sharpInstance = this.applyBoolean(sharpInstance, step.options);
|
|
413
|
-
break;
|
|
414
|
-
}
|
|
415
|
-
case "clahe": {
|
|
416
|
-
sharpInstance = this.applyCLAHE(sharpInstance, step.options);
|
|
417
|
-
break;
|
|
418
|
-
}
|
|
419
|
-
case "colourspace": {
|
|
420
|
-
sharpInstance = this.applyColourspace(sharpInstance, step.options);
|
|
421
|
-
break;
|
|
422
|
-
}
|
|
423
|
-
case "convolve": {
|
|
424
|
-
sharpInstance = this.applyConvolve(sharpInstance, step.options);
|
|
425
|
-
break;
|
|
426
|
-
}
|
|
427
|
-
case "crop": {
|
|
428
|
-
sharpInstance = this.applyCrop(sharpInstance, step.options);
|
|
429
|
-
break;
|
|
430
|
-
}
|
|
431
|
-
case "dilate": {
|
|
432
|
-
sharpInstance = this.applyDilate(sharpInstance, step.options);
|
|
433
|
-
break;
|
|
434
|
-
}
|
|
435
|
-
case "ensureAlpha": {
|
|
436
|
-
sharpInstance = this.applyEnsureAlpha(sharpInstance, step.options);
|
|
437
|
-
break;
|
|
438
|
-
}
|
|
439
|
-
case "erode": {
|
|
440
|
-
sharpInstance = this.applyErode(sharpInstance, step.options);
|
|
441
|
-
break;
|
|
442
|
-
}
|
|
443
|
-
case "extractChannel": {
|
|
444
|
-
sharpInstance = this.applyExtractChannel(sharpInstance, step.options);
|
|
445
|
-
break;
|
|
446
|
-
}
|
|
447
|
-
case "flatten": {
|
|
448
|
-
sharpInstance = sharpInstance.flatten();
|
|
449
|
-
break;
|
|
450
|
-
}
|
|
451
|
-
case "flip": {
|
|
452
|
-
sharpInstance = sharpInstance.flip();
|
|
453
|
-
break;
|
|
454
|
-
}
|
|
455
|
-
case "flop": {
|
|
456
|
-
sharpInstance = sharpInstance.flop();
|
|
457
|
-
break;
|
|
458
|
-
}
|
|
459
|
-
case "format":
|
|
460
|
-
case "quality": {
|
|
461
|
-
sharpInstance = this.applyFormatAndQuality(sharpInstance, step.options);
|
|
462
|
-
break;
|
|
463
|
-
}
|
|
464
|
-
case "gamma": {
|
|
465
|
-
sharpInstance = sharpInstance.gamma();
|
|
466
|
-
break;
|
|
467
|
-
}
|
|
468
|
-
case "greyscale": {
|
|
469
|
-
sharpInstance = this.applyGreyscale(sharpInstance, step.options);
|
|
470
|
-
break;
|
|
471
|
-
}
|
|
472
|
-
case "joinChannel": {
|
|
473
|
-
sharpInstance = this.applyJoinChannel(sharpInstance, step.options);
|
|
474
|
-
break;
|
|
475
|
-
}
|
|
476
|
-
case "linear": {
|
|
477
|
-
sharpInstance = this.applyLinear(sharpInstance, step.options);
|
|
478
|
-
break;
|
|
479
|
-
}
|
|
480
|
-
case "median": {
|
|
481
|
-
sharpInstance = this.applyMedian(sharpInstance, step.options);
|
|
482
|
-
break;
|
|
483
|
-
}
|
|
484
|
-
case "modulate": {
|
|
485
|
-
sharpInstance = this.applyModulate(sharpInstance, step.options);
|
|
486
|
-
break;
|
|
487
|
-
}
|
|
488
|
-
case "negate": {
|
|
489
|
-
sharpInstance = sharpInstance.negate();
|
|
490
|
-
break;
|
|
491
|
-
}
|
|
492
|
-
case "normalise":
|
|
493
|
-
case "normalize": {
|
|
494
|
-
sharpInstance = sharpInstance.normalise();
|
|
495
|
-
break;
|
|
496
|
-
}
|
|
497
|
-
case "pipelineColourspace": {
|
|
498
|
-
sharpInstance = this.applyPipelineColourspace(sharpInstance, step.options);
|
|
499
|
-
break;
|
|
500
|
-
}
|
|
501
|
-
case "recombine": {
|
|
502
|
-
sharpInstance = this.applyRecombine(sharpInstance, step.options);
|
|
503
|
-
break;
|
|
504
|
-
}
|
|
505
|
-
case "removeAlpha": {
|
|
506
|
-
sharpInstance = this.applyRemoveAlpha(sharpInstance, step.options);
|
|
507
|
-
break;
|
|
508
|
-
}
|
|
509
|
-
case "resize": {
|
|
510
|
-
sharpInstance = this.applyResize(sharpInstance, step.options);
|
|
511
|
-
break;
|
|
512
|
-
}
|
|
513
|
-
case "rotate": {
|
|
514
|
-
sharpInstance = this.applyRotate(sharpInstance, step.options);
|
|
515
|
-
break;
|
|
516
|
-
}
|
|
517
|
-
case "sharpen": {
|
|
518
|
-
sharpInstance = this.applySharpen(sharpInstance, step.options);
|
|
519
|
-
break;
|
|
520
|
-
}
|
|
521
|
-
case "threshold": {
|
|
522
|
-
sharpInstance = this.applyThreshold(sharpInstance, step.options);
|
|
523
|
-
break;
|
|
524
|
-
}
|
|
525
|
-
case "tint": {
|
|
526
|
-
sharpInstance = this.applyTint(sharpInstance, step.options);
|
|
527
|
-
break;
|
|
528
|
-
}
|
|
529
|
-
case "toColourspace": {
|
|
530
|
-
sharpInstance = this.applyToColourspace(sharpInstance, step.options);
|
|
531
|
-
break;
|
|
532
|
-
}
|
|
533
|
-
case "unflatten": {
|
|
534
|
-
sharpInstance = sharpInstance.unflatten();
|
|
535
|
-
break;
|
|
536
|
-
}
|
|
537
|
-
default: {
|
|
538
|
-
throw new Error(`Unknown transformation type: ${step.type}`);
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
return sharpInstance.toBuffer();
|
|
543
|
-
}
|
|
544
|
-
/**
|
|
545
|
-
* Applies resize transformation using Sharp.
|
|
546
|
-
* @param sharpInstance The Sharp instance to modify.
|
|
547
|
-
* @param options Resize transformation options.
|
|
548
|
-
* @returns Modified Sharp instance with resize applied.
|
|
549
|
-
* @private
|
|
550
|
-
*/
|
|
551
|
-
applyResize(sharpInstance, options) {
|
|
552
|
-
const {
|
|
553
|
-
background,
|
|
554
|
-
fastShrinkOnLoad,
|
|
555
|
-
fit = "cover",
|
|
556
|
-
height,
|
|
557
|
-
kernel,
|
|
558
|
-
position,
|
|
559
|
-
width,
|
|
560
|
-
withoutEnlargement,
|
|
561
|
-
withoutReduction,
|
|
562
|
-
...formatOptions
|
|
563
|
-
} = options;
|
|
564
|
-
let resizeOptions = {
|
|
565
|
-
background: background || "transparent",
|
|
566
|
-
fastShrinkOnLoad,
|
|
567
|
-
fit,
|
|
568
|
-
height,
|
|
569
|
-
kernel,
|
|
570
|
-
position,
|
|
571
|
-
width,
|
|
572
|
-
withoutEnlargement,
|
|
573
|
-
withoutReduction
|
|
574
|
-
};
|
|
575
|
-
if (Object.keys(formatOptions).length > 0) {
|
|
576
|
-
resizeOptions = { ...resizeOptions, ...this.getFormatOptions(formatOptions) };
|
|
577
|
-
}
|
|
578
|
-
return sharpInstance.resize(resizeOptions);
|
|
579
|
-
}
|
|
580
|
-
/**
|
|
581
|
-
* Applies crop transformation using Sharp.
|
|
582
|
-
* @param sharpInstance The Sharp instance to modify.
|
|
583
|
-
* @param options Crop transformation options.
|
|
584
|
-
* @returns Modified Sharp instance with crop applied.
|
|
585
|
-
* @private
|
|
586
|
-
*/
|
|
587
|
-
applyCrop(sharpInstance, options) {
|
|
588
|
-
const { height, left, top, width, ...formatOptions } = options;
|
|
589
|
-
let cropInstance = sharpInstance.extract({
|
|
590
|
-
height,
|
|
591
|
-
left,
|
|
592
|
-
top,
|
|
593
|
-
width
|
|
594
|
-
});
|
|
595
|
-
if (Object.keys(formatOptions).length > 0) {
|
|
596
|
-
cropInstance = this.applyFormatAndQuality(cropInstance, formatOptions);
|
|
597
|
-
}
|
|
598
|
-
return cropInstance;
|
|
599
|
-
}
|
|
600
|
-
/**
|
|
601
|
-
* Applies rotate transformation using Sharp.
|
|
602
|
-
* @param sharpInstance The Sharp instance to modify.
|
|
603
|
-
* @param options Rotate transformation options.
|
|
604
|
-
* @returns Modified Sharp instance with rotation applied.
|
|
605
|
-
* @private
|
|
606
|
-
*/
|
|
607
|
-
applyRotate(sharpInstance, options) {
|
|
608
|
-
const { angle, background, ...formatOptions } = options;
|
|
609
|
-
let rotateInstance = sharpInstance.rotate(angle, {
|
|
610
|
-
background: background || "transparent"
|
|
611
|
-
});
|
|
612
|
-
if (Object.keys(formatOptions).length > 0) {
|
|
613
|
-
rotateInstance = this.applyFormatAndQuality(rotateInstance, formatOptions);
|
|
614
|
-
}
|
|
615
|
-
return rotateInstance;
|
|
616
|
-
}
|
|
617
|
-
/**
|
|
618
|
-
* Applies sharpen transformation using Sharp.
|
|
619
|
-
* @param sharpInstance The Sharp instance to modify.
|
|
620
|
-
* @param options Sharpen transformation options.
|
|
621
|
-
* @returns Modified Sharp instance with sharpening applied.
|
|
622
|
-
* @private
|
|
623
|
-
*/
|
|
624
|
-
applySharpen(sharpInstance, options) {
|
|
625
|
-
const { sigma, ...formatOptions } = options;
|
|
626
|
-
const sharpenOptions = {};
|
|
627
|
-
if (sigma !== void 0) {
|
|
628
|
-
sharpenOptions.sigma = sigma;
|
|
629
|
-
}
|
|
630
|
-
let sharpenInstance = sharpInstance.sharpen(sharpenOptions);
|
|
631
|
-
if (Object.keys(formatOptions).length > 0) {
|
|
632
|
-
sharpenInstance = this.applyFormatAndQuality(sharpenInstance, formatOptions);
|
|
633
|
-
}
|
|
634
|
-
return sharpenInstance;
|
|
635
|
-
}
|
|
636
|
-
/**
|
|
637
|
-
* Applies blur transformation using Sharp.
|
|
638
|
-
* @param sharpInstance The Sharp instance to modify.
|
|
639
|
-
* @param options Blur transformation options.
|
|
640
|
-
* @returns Modified Sharp instance with blurring applied.
|
|
641
|
-
* @private
|
|
642
|
-
*/
|
|
643
|
-
applyBlur(sharpInstance, options) {
|
|
644
|
-
const { sigma, ...formatOptions } = options;
|
|
645
|
-
let blurInstance = sharpInstance.blur(sigma === void 0 ? true : sigma);
|
|
646
|
-
if (Object.keys(formatOptions).length > 0) {
|
|
647
|
-
blurInstance = this.applyFormatAndQuality(blurInstance, formatOptions);
|
|
648
|
-
}
|
|
649
|
-
return blurInstance;
|
|
650
|
-
}
|
|
651
|
-
/**
|
|
652
|
-
* Applies median filter using Sharp.
|
|
653
|
-
* @param sharpInstance The Sharp instance to modify.
|
|
654
|
-
* @param options Median transformation options.
|
|
655
|
-
* @returns Modified Sharp instance with median filter applied.
|
|
656
|
-
* @private
|
|
657
|
-
*/
|
|
658
|
-
applyMedian(sharpInstance, options) {
|
|
659
|
-
const { size, ...formatOptions } = options;
|
|
660
|
-
let medianInstance = sharpInstance.median(size);
|
|
661
|
-
if (Object.keys(formatOptions).length > 0) {
|
|
662
|
-
medianInstance = this.applyFormatAndQuality(medianInstance, formatOptions);
|
|
663
|
-
}
|
|
664
|
-
return medianInstance;
|
|
665
|
-
}
|
|
666
|
-
/**
|
|
667
|
-
* Applies CLAHE (Contrast Limited Adaptive Histogram Equalization) using Sharp.
|
|
668
|
-
* @param sharpInstance The Sharp instance to modify.
|
|
669
|
-
* @param options CLAHE transformation options.
|
|
670
|
-
* @returns Modified Sharp instance with CLAHE applied.
|
|
671
|
-
* @private
|
|
672
|
-
*/
|
|
673
|
-
applyCLAHE(sharpInstance, options) {
|
|
674
|
-
const { height, maxSlope, width, ...formatOptions } = options;
|
|
675
|
-
let claheInstance = sharpInstance.clahe({
|
|
676
|
-
height,
|
|
677
|
-
maxSlope,
|
|
678
|
-
width
|
|
679
|
-
});
|
|
680
|
-
if (Object.keys(formatOptions).length > 0) {
|
|
681
|
-
claheInstance = this.applyFormatAndQuality(claheInstance, formatOptions);
|
|
682
|
-
}
|
|
683
|
-
return claheInstance;
|
|
684
|
-
}
|
|
685
|
-
/**
|
|
686
|
-
* Applies convolution using Sharp.
|
|
687
|
-
* @param sharpInstance The Sharp instance to modify.
|
|
688
|
-
* @param options Convolution transformation options.
|
|
689
|
-
* @returns Modified Sharp instance with convolution applied.
|
|
690
|
-
* @private
|
|
691
|
-
*/
|
|
692
|
-
applyConvolve(sharpInstance, options) {
|
|
693
|
-
const { height, kernel, offset, scale, width, ...formatOptions } = options;
|
|
694
|
-
let convolveInstance = sharpInstance.convolve({
|
|
695
|
-
height,
|
|
696
|
-
kernel,
|
|
697
|
-
offset,
|
|
698
|
-
scale,
|
|
699
|
-
width
|
|
700
|
-
});
|
|
701
|
-
if (Object.keys(formatOptions).length > 0) {
|
|
702
|
-
convolveInstance = this.applyFormatAndQuality(convolveInstance, formatOptions);
|
|
703
|
-
}
|
|
704
|
-
return convolveInstance;
|
|
705
|
-
}
|
|
706
|
-
/**
|
|
707
|
-
* Applies threshold using Sharp.
|
|
708
|
-
* @param sharpInstance The Sharp instance to modify.
|
|
709
|
-
* @param options Threshold transformation options.
|
|
710
|
-
* @returns Modified Sharp instance with thresholding applied.
|
|
711
|
-
* @private
|
|
712
|
-
*/
|
|
713
|
-
applyThreshold(sharpInstance, options) {
|
|
714
|
-
const { grayscale, greyscale, threshold = 128, ...formatOptions } = options;
|
|
715
|
-
let thresholdInstance = sharpInstance.threshold(threshold, {
|
|
716
|
-
greyscale: greyscale || grayscale
|
|
717
|
-
});
|
|
718
|
-
if (Object.keys(formatOptions).length > 0) {
|
|
719
|
-
thresholdInstance = this.applyFormatAndQuality(thresholdInstance, formatOptions);
|
|
720
|
-
}
|
|
721
|
-
return thresholdInstance;
|
|
722
|
-
}
|
|
723
|
-
/**
|
|
724
|
-
* Applies boolean operation using Sharp.
|
|
725
|
-
* @param sharpInstance The Sharp instance to modify.
|
|
726
|
-
* @param options Boolean operation options.
|
|
727
|
-
* @returns Modified Sharp instance with boolean operation applied.
|
|
728
|
-
* @private
|
|
729
|
-
*/
|
|
730
|
-
applyBoolean(sharpInstance, options) {
|
|
731
|
-
const { operand, operator, raw, ...formatOptions } = options;
|
|
732
|
-
let booleanInstance = sharpInstance.boolean(operand, operator, raw);
|
|
733
|
-
if (Object.keys(formatOptions).length > 0) {
|
|
734
|
-
booleanInstance = this.applyFormatAndQuality(booleanInstance, formatOptions);
|
|
735
|
-
}
|
|
736
|
-
return booleanInstance;
|
|
737
|
-
}
|
|
738
|
-
/**
|
|
739
|
-
* Applies linear transformation using Sharp.
|
|
740
|
-
* @param sharpInstance The Sharp instance to modify.
|
|
741
|
-
* @param options Linear transformation options.
|
|
742
|
-
* @returns Modified Sharp instance with linear transformation applied.
|
|
743
|
-
* @private
|
|
744
|
-
*/
|
|
745
|
-
applyLinear(sharpInstance, options) {
|
|
746
|
-
const { a, b, ...formatOptions } = options;
|
|
747
|
-
let linearInstance = sharpInstance.linear(a, b);
|
|
748
|
-
if (Object.keys(formatOptions).length > 0) {
|
|
749
|
-
linearInstance = this.applyFormatAndQuality(linearInstance, formatOptions);
|
|
750
|
-
}
|
|
751
|
-
return linearInstance;
|
|
752
|
-
}
|
|
753
|
-
/**
|
|
754
|
-
* Applies recombine transformation using Sharp.
|
|
755
|
-
* @param sharpInstance The Sharp instance to modify.
|
|
756
|
-
* @param options Recombine transformation options.
|
|
757
|
-
* @returns Modified Sharp instance with recombine applied.
|
|
758
|
-
* @private
|
|
759
|
-
*/
|
|
760
|
-
applyRecombine(sharpInstance, options) {
|
|
761
|
-
const { matrix, ...formatOptions } = options;
|
|
762
|
-
let recombineInstance = sharpInstance.recomb(matrix.flat());
|
|
763
|
-
if (Object.keys(formatOptions).length > 0) {
|
|
764
|
-
recombineInstance = this.applyFormatAndQuality(recombineInstance, formatOptions);
|
|
765
|
-
}
|
|
766
|
-
return recombineInstance;
|
|
767
|
-
}
|
|
768
|
-
/**
|
|
769
|
-
* Applies modulate transformation using Sharp.
|
|
770
|
-
* @param sharpInstance The Sharp instance to modify.
|
|
771
|
-
* @param options Modulate transformation options.
|
|
772
|
-
* @returns Modified Sharp instance with modulation applied.
|
|
773
|
-
* @private
|
|
774
|
-
*/
|
|
775
|
-
applyModulate(sharpInstance, options) {
|
|
776
|
-
const { brightness, hue, lightness, saturation, ...formatOptions } = options;
|
|
777
|
-
let modulateInstance = sharpInstance.modulate({
|
|
778
|
-
brightness,
|
|
779
|
-
hue,
|
|
780
|
-
lightness,
|
|
781
|
-
saturation
|
|
782
|
-
});
|
|
783
|
-
if (Object.keys(formatOptions).length > 0) {
|
|
784
|
-
modulateInstance = this.applyFormatAndQuality(modulateInstance, formatOptions);
|
|
785
|
-
}
|
|
786
|
-
return modulateInstance;
|
|
787
|
-
}
|
|
788
|
-
/**
|
|
789
|
-
* Applies tint using Sharp.
|
|
790
|
-
* @param sharpInstance The Sharp instance to modify.
|
|
791
|
-
* @param options Tint transformation options.
|
|
792
|
-
* @returns Modified Sharp instance with tinting applied.
|
|
793
|
-
* @private
|
|
794
|
-
*/
|
|
795
|
-
applyTint(sharpInstance, options) {
|
|
796
|
-
const { rgb, ...formatOptions } = options;
|
|
797
|
-
let tintInstance = sharpInstance.tint(Array.isArray(rgb) ? rgb : rgb);
|
|
798
|
-
if (Object.keys(formatOptions).length > 0) {
|
|
799
|
-
tintInstance = this.applyFormatAndQuality(tintInstance, formatOptions);
|
|
800
|
-
}
|
|
801
|
-
return tintInstance;
|
|
802
|
-
}
|
|
803
|
-
/**
|
|
804
|
-
* Applies greyscale conversion using Sharp.
|
|
805
|
-
* @param sharpInstance The Sharp instance to modify.
|
|
806
|
-
* @param options Greyscale transformation options.
|
|
807
|
-
* @returns Modified Sharp instance converted to greyscale.
|
|
808
|
-
* @private
|
|
809
|
-
*/
|
|
810
|
-
applyGreyscale(sharpInstance, options) {
|
|
811
|
-
const { grayscale, greyscale, ...formatOptions } = options;
|
|
812
|
-
let greyscaleInstance = sharpInstance.greyscale(greyscale || grayscale);
|
|
813
|
-
if (Object.keys(formatOptions).length > 0) {
|
|
814
|
-
greyscaleInstance = this.applyFormatAndQuality(greyscaleInstance, formatOptions);
|
|
815
|
-
}
|
|
816
|
-
return greyscaleInstance;
|
|
817
|
-
}
|
|
818
|
-
/**
|
|
819
|
-
* Applies colourspace conversion using Sharp.
|
|
820
|
-
* @param sharpInstance The Sharp instance to modify.
|
|
821
|
-
* @param options Colourspace transformation options.
|
|
822
|
-
* @returns Modified Sharp instance with colourspace conversion.
|
|
823
|
-
* @private
|
|
824
|
-
*/
|
|
825
|
-
applyColourspace(sharpInstance, options) {
|
|
826
|
-
const { colourspace, ...formatOptions } = options;
|
|
827
|
-
let colourspaceInstance = sharpInstance.toColourspace(colourspace);
|
|
828
|
-
if (Object.keys(formatOptions).length > 0) {
|
|
829
|
-
colourspaceInstance = this.applyFormatAndQuality(colourspaceInstance, formatOptions);
|
|
830
|
-
}
|
|
831
|
-
return colourspaceInstance;
|
|
832
|
-
}
|
|
833
|
-
/**
|
|
834
|
-
* Extracts channel using Sharp.
|
|
835
|
-
* @param sharpInstance The Sharp instance to modify.
|
|
836
|
-
* @param options Channel extraction options including channel index.
|
|
837
|
-
* @returns Modified Sharp instance with channel extracted.
|
|
838
|
-
* @private
|
|
839
|
-
*/
|
|
840
|
-
applyExtractChannel(sharpInstance, options) {
|
|
841
|
-
const { channel, ...formatOptions } = options;
|
|
842
|
-
let extractInstance = sharpInstance.extractChannel(channel);
|
|
843
|
-
if (Object.keys(formatOptions).length > 0) {
|
|
844
|
-
extractInstance = this.applyFormatAndQuality(extractInstance, formatOptions);
|
|
845
|
-
}
|
|
846
|
-
return extractInstance;
|
|
847
|
-
}
|
|
848
|
-
/**
|
|
849
|
-
* Joins channels using Sharp.
|
|
850
|
-
* @param sharpInstance The Sharp instance to modify.
|
|
851
|
-
* @param options Channel joining options including image sources.
|
|
852
|
-
* @returns Modified Sharp instance with channels joined.
|
|
853
|
-
* @private
|
|
854
|
-
*/
|
|
855
|
-
applyJoinChannel(sharpInstance, options) {
|
|
856
|
-
const { images, ...formatOptions } = options;
|
|
857
|
-
let joinInstance = sharpInstance.joinChannel(images);
|
|
858
|
-
if (Object.keys(formatOptions).length > 0) {
|
|
859
|
-
joinInstance = this.applyFormatAndQuality(joinInstance, formatOptions);
|
|
860
|
-
}
|
|
861
|
-
return joinInstance;
|
|
862
|
-
}
|
|
863
|
-
/**
|
|
864
|
-
* Applies band boolean operation using Sharp.
|
|
865
|
-
* @param sharpInstance The Sharp instance to modify.
|
|
866
|
-
* @param options Band boolean options including operator.
|
|
867
|
-
* @returns Modified Sharp instance with band boolean operation applied.
|
|
868
|
-
* @private
|
|
869
|
-
*/
|
|
870
|
-
applyBandbool(sharpInstance, options) {
|
|
871
|
-
const { operator, ...formatOptions } = options;
|
|
872
|
-
let bandboolInstance = sharpInstance.bandbool(operator);
|
|
873
|
-
if (Object.keys(formatOptions).length > 0) {
|
|
874
|
-
bandboolInstance = this.applyFormatAndQuality(bandboolInstance, formatOptions);
|
|
875
|
-
}
|
|
876
|
-
return bandboolInstance;
|
|
877
|
-
}
|
|
878
|
-
/**
|
|
879
|
-
* Applies affine transformation using Sharp.
|
|
880
|
-
* @param sharpInstance The Sharp instance to modify.
|
|
881
|
-
* @param options Affine transformation options including matrix.
|
|
882
|
-
* @returns Modified Sharp instance with affine transformation applied.
|
|
883
|
-
* @private
|
|
884
|
-
*/
|
|
885
|
-
applyAffine(sharpInstance, options) {
|
|
886
|
-
const { background, interpolation, matrix, ...formatOptions } = options;
|
|
887
|
-
let affineInstance = sharpInstance.affine(matrix, {
|
|
888
|
-
background: background || "transparent",
|
|
889
|
-
interpolator: interpolation || "bicubic"
|
|
890
|
-
});
|
|
891
|
-
if (Object.keys(formatOptions).length > 0) {
|
|
892
|
-
affineInstance = this.applyFormatAndQuality(affineInstance, formatOptions);
|
|
893
|
-
}
|
|
894
|
-
return affineInstance;
|
|
895
|
-
}
|
|
896
|
-
/**
|
|
897
|
-
* Applies dilation using Sharp.
|
|
898
|
-
* @param sharpInstance The Sharp instance to modify.
|
|
899
|
-
* @param options Dilate options including kernel size.
|
|
900
|
-
* @returns Modified Sharp instance with dilation applied.
|
|
901
|
-
* @private
|
|
902
|
-
*/
|
|
903
|
-
applyDilate(sharpInstance, options) {
|
|
904
|
-
const { kernelSize, ...formatOptions } = options;
|
|
905
|
-
let dilateInstance = kernelSize ? sharpInstance.dilate(kernelSize) : sharpInstance.dilate();
|
|
906
|
-
if (Object.keys(formatOptions).length > 0) {
|
|
907
|
-
dilateInstance = this.applyFormatAndQuality(dilateInstance, formatOptions);
|
|
908
|
-
}
|
|
909
|
-
return dilateInstance;
|
|
910
|
-
}
|
|
911
|
-
/**
|
|
912
|
-
* Applies erosion using Sharp.
|
|
913
|
-
* @param sharpInstance The Sharp instance to modify.
|
|
914
|
-
* @param options Erode options including kernel size.
|
|
915
|
-
* @returns Modified Sharp instance with erosion applied.
|
|
916
|
-
* @private
|
|
917
|
-
*/
|
|
918
|
-
applyErode(sharpInstance, options) {
|
|
919
|
-
const { kernelSize, ...formatOptions } = options;
|
|
920
|
-
let erodeInstance = kernelSize ? sharpInstance.erode(kernelSize) : sharpInstance.erode();
|
|
921
|
-
if (Object.keys(formatOptions).length > 0) {
|
|
922
|
-
erodeInstance = this.applyFormatAndQuality(erodeInstance, formatOptions);
|
|
923
|
-
}
|
|
924
|
-
return erodeInstance;
|
|
925
|
-
}
|
|
926
|
-
/**
|
|
927
|
-
* Applies pipeline colourspace using Sharp.
|
|
928
|
-
* @param sharpInstance The Sharp instance to modify.
|
|
929
|
-
* @param options Pipeline colourspace options including target colourspace.
|
|
930
|
-
* @returns Modified Sharp instance with pipeline colourspace applied.
|
|
931
|
-
* @private
|
|
932
|
-
*/
|
|
933
|
-
applyPipelineColourspace(sharpInstance, options) {
|
|
934
|
-
const { colourspace, ...formatOptions } = options;
|
|
935
|
-
let colourspaceInstance = sharpInstance.pipelineColourspace(colourspace);
|
|
936
|
-
if (Object.keys(formatOptions).length > 0) {
|
|
937
|
-
colourspaceInstance = this.applyFormatAndQuality(colourspaceInstance, formatOptions);
|
|
938
|
-
}
|
|
939
|
-
return colourspaceInstance;
|
|
940
|
-
}
|
|
941
|
-
/**
|
|
942
|
-
* Applies to colourspace conversion using Sharp.
|
|
943
|
-
* @param sharpInstance The Sharp instance to modify.
|
|
944
|
-
* @param options To colourspace options including target colourspace.
|
|
945
|
-
* @returns Modified Sharp instance with colourspace conversion applied.
|
|
946
|
-
* @private
|
|
947
|
-
*/
|
|
948
|
-
applyToColourspace(sharpInstance, options) {
|
|
949
|
-
const { colourspace, ...formatOptions } = options;
|
|
950
|
-
let colourspaceInstance = sharpInstance.toColourspace(colourspace);
|
|
951
|
-
if (Object.keys(formatOptions).length > 0) {
|
|
952
|
-
colourspaceInstance = this.applyFormatAndQuality(colourspaceInstance, formatOptions);
|
|
953
|
-
}
|
|
954
|
-
return colourspaceInstance;
|
|
955
|
-
}
|
|
956
|
-
/**
|
|
957
|
-
* Applies remove alpha using Sharp.
|
|
958
|
-
* @param sharpInstance The Sharp instance to modify.
|
|
959
|
-
* @param options Remove alpha transformation options.
|
|
960
|
-
* @returns Modified Sharp instance with alpha channel removed.
|
|
961
|
-
* @private
|
|
962
|
-
*/
|
|
963
|
-
applyRemoveAlpha(sharpInstance, options) {
|
|
964
|
-
const { background, ...formatOptions } = options;
|
|
965
|
-
let alphaInstance = sharpInstance.removeAlpha();
|
|
966
|
-
if (Object.keys(formatOptions).length > 0) {
|
|
967
|
-
alphaInstance = this.applyFormatAndQuality(alphaInstance, formatOptions);
|
|
968
|
-
}
|
|
969
|
-
return alphaInstance;
|
|
970
|
-
}
|
|
971
|
-
/**
|
|
972
|
-
* Applies ensure alpha using Sharp.
|
|
973
|
-
* @param sharpInstance The Sharp instance to modify.
|
|
974
|
-
* @param options Ensure alpha transformation options.
|
|
975
|
-
* @returns Modified Sharp instance with alpha channel ensured.
|
|
976
|
-
* @private
|
|
977
|
-
*/
|
|
978
|
-
applyEnsureAlpha(sharpInstance, options) {
|
|
979
|
-
const { alpha, ...formatOptions } = options;
|
|
980
|
-
let alphaInstance = sharpInstance.ensureAlpha();
|
|
981
|
-
if (Object.keys(formatOptions).length > 0) {
|
|
982
|
-
alphaInstance = this.applyFormatAndQuality(alphaInstance, formatOptions);
|
|
983
|
-
}
|
|
984
|
-
return alphaInstance;
|
|
985
|
-
}
|
|
986
|
-
/**
|
|
987
|
-
* Applies format and quality transformation using Sharp.
|
|
988
|
-
* @param sharpInstance The Sharp instance to modify.
|
|
989
|
-
* @param options Format and quality transformation options.
|
|
990
|
-
* @returns Modified Sharp instance with format and quality settings applied.
|
|
991
|
-
* @private
|
|
992
|
-
*/
|
|
993
|
-
applyFormatAndQuality(sharpInstance, options) {
|
|
994
|
-
const formatOptions = this.getFormatOptions(options);
|
|
995
|
-
if (options.format) {
|
|
996
|
-
return sharpInstance.toFormat(options.format, formatOptions);
|
|
997
|
-
}
|
|
998
|
-
if (Object.keys(formatOptions).length > 0) {
|
|
999
|
-
return sharpInstance.jpeg(formatOptions).png(formatOptions).webp(formatOptions);
|
|
1000
|
-
}
|
|
1001
|
-
return sharpInstance;
|
|
1002
|
-
}
|
|
1003
|
-
/**
|
|
1004
|
-
* Gets format-specific options for Sharp.
|
|
1005
|
-
* @param options Transform options containing format-specific settings.
|
|
1006
|
-
* @returns Record of format options for Sharp processing.
|
|
1007
|
-
* @private
|
|
1008
|
-
*/
|
|
1009
|
-
// eslint-disable-next-line class-methods-use-this
|
|
1010
|
-
getFormatOptions(options) {
|
|
1011
|
-
const { alphaQuality, compressionLevel, delay, effort, loop, lossless, progressive, quality } = options;
|
|
1012
|
-
const formatOptions = {};
|
|
1013
|
-
if (quality !== void 0) {
|
|
1014
|
-
formatOptions.quality = quality;
|
|
1015
|
-
}
|
|
1016
|
-
if (progressive !== void 0) {
|
|
1017
|
-
formatOptions.progressive = progressive;
|
|
1018
|
-
}
|
|
1019
|
-
if (lossless !== void 0) {
|
|
1020
|
-
formatOptions.lossless = lossless;
|
|
1021
|
-
}
|
|
1022
|
-
if (compressionLevel !== void 0) {
|
|
1023
|
-
formatOptions.compressionLevel = compressionLevel;
|
|
1024
|
-
}
|
|
1025
|
-
if (effort !== void 0) {
|
|
1026
|
-
formatOptions.effort = effort;
|
|
1027
|
-
}
|
|
1028
|
-
if (alphaQuality !== void 0) {
|
|
1029
|
-
formatOptions.alphaQuality = alphaQuality;
|
|
1030
|
-
}
|
|
1031
|
-
if (loop !== void 0) {
|
|
1032
|
-
formatOptions.loop = loop;
|
|
1033
|
-
}
|
|
1034
|
-
if (delay !== void 0) {
|
|
1035
|
-
formatOptions.delay = delay;
|
|
1036
|
-
}
|
|
1037
|
-
return formatOptions;
|
|
1038
|
-
}
|
|
1039
|
-
/**
|
|
1040
|
-
* Validates that the file is a supported image.
|
|
1041
|
-
* @param file The file to validate.
|
|
1042
|
-
* @returns Promise that resolves if validation passes.
|
|
1043
|
-
* @throws Error if file size exceeds limits, wrong content type, unsupported format, or invalid image.
|
|
1044
|
-
* @private
|
|
1045
|
-
*/
|
|
1046
|
-
async validateImage(file) {
|
|
1047
|
-
const fileSize = typeof file.size === "string" ? Number.parseInt(file.size, 10) : file.size;
|
|
1048
|
-
if (this.config?.maxImageSize && fileSize > this.config.maxImageSize) {
|
|
1049
|
-
throw new Error(`Image size ${fileSize} exceeds maximum allowed size ${this.config.maxImageSize}`);
|
|
1050
|
-
}
|
|
1051
|
-
if (!isValidMediaType(file.contentType, "image")) {
|
|
1052
|
-
throw new Error(`File is not an image: ${file.contentType}`);
|
|
1053
|
-
}
|
|
1054
|
-
const format = getFormatFromContentType(file.contentType);
|
|
1055
|
-
if (this.config?.supportedFormats && format && !this.config.supportedFormats.includes(format)) {
|
|
1056
|
-
throw new Error(`Unsupported image format: ${format}`);
|
|
1057
|
-
}
|
|
1058
|
-
try {
|
|
1059
|
-
const metadata = await sharp(file.content).metadata();
|
|
1060
|
-
if (!metadata.width || !metadata.height) {
|
|
1061
|
-
throw new Error("Invalid image: missing dimensions");
|
|
1062
|
-
}
|
|
1063
|
-
} catch (error) {
|
|
1064
|
-
throw new Error(`Invalid image file: ${error}`);
|
|
1065
|
-
}
|
|
1066
|
-
}
|
|
1067
|
-
/**
|
|
1068
|
-
* Creates transformation result with metadata.
|
|
1069
|
-
* @param buffer The transformed image buffer.
|
|
1070
|
-
* @param originalFile The original file information.
|
|
1071
|
-
* @returns Image transformation result with metadata.
|
|
1072
|
-
* @private
|
|
1073
|
-
*/
|
|
1074
|
-
// eslint-disable-next-line class-methods-use-this
|
|
1075
|
-
async createTransformResult(buffer, originalFile) {
|
|
1076
|
-
const metadata = await sharp(buffer).metadata();
|
|
1077
|
-
return {
|
|
1078
|
-
buffer,
|
|
1079
|
-
format: metadata.format || "unknown",
|
|
1080
|
-
height: metadata.height || 0,
|
|
1081
|
-
originalFile,
|
|
1082
|
-
size: buffer.length,
|
|
1083
|
-
width: metadata.width || 0
|
|
1084
|
-
};
|
|
1085
|
-
}
|
|
1086
|
-
/**
|
|
1087
|
-
* Generates cache key for transformation.
|
|
1088
|
-
* @param fileId The file identifier.
|
|
1089
|
-
* @param steps Array of transformation steps.
|
|
1090
|
-
* @returns Unique cache key string.
|
|
1091
|
-
* @private
|
|
1092
|
-
*/
|
|
1093
|
-
// eslint-disable-next-line class-methods-use-this
|
|
1094
|
-
generateCacheKey(fileId, steps) {
|
|
1095
|
-
const stepsKey = steps.map((step) => `${step.type}:${JSON.stringify(step.options)}`).join("|");
|
|
1096
|
-
return `${fileId}:${stepsKey}`;
|
|
1097
|
-
}
|
|
1098
|
-
}
|
|
1099
|
-
|
|
1100
|
-
export { ImageTransformer as default };
|
|
1
|
+
import{Readable as u}from"node:stream";import y from"sharp";import g from"../packem_shared/BaseTransformer-Buw5lX_3.js";import{isValidMediaType as f,getFormatFromContentType as d}from"../packem_shared/getFormatFromContentType-DCTTPQHm.js";class C extends g{constructor(e,a={}){const t=a.logger||e.logger,n={cacheTtl:3600,failOn:"warning",limitInputPixels:268435456,maxCacheSize:100,maxImageSize:50*1024*1024,supportedFormats:["jpeg","png","webp","avif","tiff","gif","svg"],...a};super(e,n,t)}openImage(e){return y(e,{failOn:this.config?.failOn??"warning",limitInputPixels:this.config?.limitInputPixels??268435456})}async resize(e,a){return this.transform(e,[{options:a,type:"resize"}])}async crop(e,a){return this.transform(e,[{options:a,type:"crop"}])}async rotate(e,a){return this.transform(e,[{options:a,type:"rotate"}])}async convertFormat(e,a,t={}){return this.transform(e,[{options:{...t,format:a},type:"format"}])}async sharpen(e,a={}){return this.transform(e,[{options:a,type:"sharpen"}])}async blur(e,a={}){return this.transform(e,[{options:a,type:"blur"}])}async median(e,a={}){return this.transform(e,[{options:a,type:"median"}])}async clahe(e,a={}){return this.transform(e,[{options:a,type:"clahe"}])}async convolve(e,a){return this.transform(e,[{options:a,type:"convolve"}])}async threshold(e,a={}){return this.transform(e,[{options:a,type:"threshold"}])}async boolean(e,a){return this.transform(e,[{options:a,type:"boolean"}])}async linear(e,a){return this.transform(e,[{options:a,type:"linear"}])}async recombine(e,a){return this.transform(e,[{options:a,type:"recombine"}])}async modulate(e,a){return this.transform(e,[{options:a,type:"modulate"}])}async tint(e,a){return this.transform(e,[{options:a,type:"tint"}])}async greyscale(e,a={}){return this.transform(e,[{options:a,type:"greyscale"}])}async colourspace(e,a){return this.transform(e,[{options:a,type:"colourspace"}])}async extractChannel(e,a){return this.transform(e,[{options:a,type:"extractChannel"}])}async joinChannel(e,a){return this.transform(e,[{options:a,type:"joinChannel"}])}async bandbool(e,a){return this.transform(e,[{options:a,type:"bandbool"}])}async autoOrient(e,a={}){return this.transform(e,[{options:a,type:"autoOrient"}])}async flip(e,a={}){return this.transform(e,[{options:a,type:"flip"}])}async flop(e,a={}){return this.transform(e,[{options:a,type:"flop"}])}async flatten(e,a={}){return this.transform(e,[{options:a,type:"flatten"}])}async unflatten(e,a={}){return this.transform(e,[{options:a,type:"unflatten"}])}async gamma(e,a={}){return this.transform(e,[{options:a,type:"gamma"}])}async negate(e,a={}){return this.transform(e,[{options:a,type:"negate"}])}async normalise(e,a={}){return this.transform(e,[{options:a,type:"normalise"}])}async affine(e,a){return this.transform(e,[{options:a,type:"affine"}])}async dilate(e,a={}){return this.transform(e,[{options:a,type:"dilate"}])}async erode(e,a={}){return this.transform(e,[{options:a,type:"erode"}])}async pipelineColourspace(e,a){return this.transform(e,[{options:a,type:"pipelineColourspace"}])}async toColourspace(e,a){return this.transform(e,[{options:a,type:"toColourspace"}])}async removeAlpha(e,a={}){return this.transform(e,[{options:a,type:"removeAlpha"}])}async ensureAlpha(e,a={}){return this.transform(e,[{options:a,type:"ensureAlpha"}])}async transform(e,a){const t={id:e},n=this.generateCacheKey(e,a),o=this.cache?await Promise.resolve(this.cache.get(n)):void 0;if(o)return this.logger?.debug("Returning cached transformed image for %s",e),o;const r=await this.storage.get(t);await this.validateImage(r);const s=await this.applyTransformations(r.content,a),i=await this.createTransformResult(s,r);return this.cache&&this.cache.set(n,i),i}async transformStream(e,a){const t=await this.transform(e,a);return{headers:{"Content-Length":t.buffer.length.toString(),"Content-Type":this.getContentTypeFromResult(t),"X-Image-Height":t.height?.toString(),"X-Image-Width":t.width?.toString()},size:t.buffer.length,stream:u.from(t.buffer)}}async applyTransformations(e,a){let t=this.openImage(e);for(const n of a)switch(n.type){case"affine":{t=this.applyAffine(t,n.options);break}case"autoOrient":{t=t.rotate();break}case"bandbool":{t=this.applyBandbool(t,n.options);break}case"blur":{t=this.applyBlur(t,n.options);break}case"boolean":{t=this.applyBoolean(t,n.options);break}case"clahe":{t=this.applyCLAHE(t,n.options);break}case"colourspace":{t=this.applyColourspace(t,n.options);break}case"convolve":{t=this.applyConvolve(t,n.options);break}case"crop":{t=this.applyCrop(t,n.options);break}case"dilate":{t=this.applyDilate(t,n.options);break}case"ensureAlpha":{t=this.applyEnsureAlpha(t,n.options);break}case"erode":{t=this.applyErode(t,n.options);break}case"extractChannel":{t=this.applyExtractChannel(t,n.options);break}case"flatten":{t=t.flatten();break}case"flip":{t=t.flip();break}case"flop":{t=t.flop();break}case"format":case"quality":{t=this.applyFormatAndQuality(t,n.options);break}case"gamma":{t=t.gamma();break}case"greyscale":{t=this.applyGreyscale(t,n.options);break}case"joinChannel":{t=this.applyJoinChannel(t,n.options);break}case"linear":{t=this.applyLinear(t,n.options);break}case"median":{t=this.applyMedian(t,n.options);break}case"modulate":{t=this.applyModulate(t,n.options);break}case"negate":{t=t.negate();break}case"normalise":case"normalize":{t=t.normalise();break}case"pipelineColourspace":{t=this.applyPipelineColourspace(t,n.options);break}case"recombine":{t=this.applyRecombine(t,n.options);break}case"removeAlpha":{t=this.applyRemoveAlpha(t,n.options);break}case"resize":{t=this.applyResize(t,n.options);break}case"rotate":{t=this.applyRotate(t,n.options);break}case"sharpen":{t=this.applySharpen(t,n.options);break}case"threshold":{t=this.applyThreshold(t,n.options);break}case"tint":{t=this.applyTint(t,n.options);break}case"toColourspace":{t=this.applyToColourspace(t,n.options);break}case"unflatten":{t=t.unflatten();break}default:throw new Error(`Unknown transformation type: ${n.type}`)}return t.toBuffer()}applyResize(e,a){const{background:t,fastShrinkOnLoad:n,fit:o="cover",height:r,kernel:s,position:i,width:l,withoutEnlargement:p,withoutReduction:m,...c}=a;let h={background:t||"transparent",fastShrinkOnLoad:n,fit:o,height:r,kernel:s,position:i,width:l,withoutEnlargement:p,withoutReduction:m};return Object.keys(c).length>0&&(h={...h,...this.getFormatOptions(c)}),e.resize(h)}applyCrop(e,a){const{height:t,left:n,top:o,width:r,...s}=a;let i=e.extract({height:t,left:n,top:o,width:r});return Object.keys(s).length>0&&(i=this.applyFormatAndQuality(i,s)),i}applyRotate(e,a){const{angle:t,background:n,...o}=a;let r=e.rotate(t,{background:n||"transparent"});return Object.keys(o).length>0&&(r=this.applyFormatAndQuality(r,o)),r}applySharpen(e,a){const{sigma:t,...n}=a,o={};t!==void 0&&(o.sigma=t);let r=e.sharpen(o);return Object.keys(n).length>0&&(r=this.applyFormatAndQuality(r,n)),r}applyBlur(e,a){const{sigma:t,...n}=a;let o=e.blur(t===void 0?!0:t);return Object.keys(n).length>0&&(o=this.applyFormatAndQuality(o,n)),o}applyMedian(e,a){const{size:t,...n}=a;let o=e.median(t);return Object.keys(n).length>0&&(o=this.applyFormatAndQuality(o,n)),o}applyCLAHE(e,a){const{height:t,maxSlope:n,width:o,...r}=a;let s=e.clahe({height:t,maxSlope:n,width:o});return Object.keys(r).length>0&&(s=this.applyFormatAndQuality(s,r)),s}applyConvolve(e,a){const{height:t,kernel:n,offset:o,scale:r,width:s,...i}=a;let l=e.convolve({height:t,kernel:n,offset:o,scale:r,width:s});return Object.keys(i).length>0&&(l=this.applyFormatAndQuality(l,i)),l}applyThreshold(e,a){const{grayscale:t,greyscale:n,threshold:o=128,...r}=a;let s=e.threshold(o,{greyscale:n||t});return Object.keys(r).length>0&&(s=this.applyFormatAndQuality(s,r)),s}applyBoolean(e,a){const{operand:t,operator:n,raw:o,...r}=a;let s=e.boolean(t,n,o);return Object.keys(r).length>0&&(s=this.applyFormatAndQuality(s,r)),s}applyLinear(e,a){const{a:t,b:n,...o}=a;let r=e.linear(t,n);return Object.keys(o).length>0&&(r=this.applyFormatAndQuality(r,o)),r}applyRecombine(e,a){const{matrix:t,...n}=a;let o=e.recomb(t.flat());return Object.keys(n).length>0&&(o=this.applyFormatAndQuality(o,n)),o}applyModulate(e,a){const{brightness:t,hue:n,lightness:o,saturation:r,...s}=a;let i=e.modulate({brightness:t,hue:n,lightness:o,saturation:r});return Object.keys(s).length>0&&(i=this.applyFormatAndQuality(i,s)),i}applyTint(e,a){const{rgb:t,...n}=a;let o=e.tint(Array.isArray(t)?{b:t[2],g:t[1],r:t[0]}:t);return Object.keys(n).length>0&&(o=this.applyFormatAndQuality(o,n)),o}applyGreyscale(e,a){const{grayscale:t,greyscale:n,...o}=a;let r=e.greyscale(n||t);return Object.keys(o).length>0&&(r=this.applyFormatAndQuality(r,o)),r}applyColourspace(e,a){const{colourspace:t,...n}=a;let o=e.toColourspace(t);return Object.keys(n).length>0&&(o=this.applyFormatAndQuality(o,n)),o}applyExtractChannel(e,a){const{channel:t,...n}=a;let o=e.extractChannel(t);return Object.keys(n).length>0&&(o=this.applyFormatAndQuality(o,n)),o}applyJoinChannel(e,a){const{images:t,...n}=a;let o=e.joinChannel(t);return Object.keys(n).length>0&&(o=this.applyFormatAndQuality(o,n)),o}applyBandbool(e,a){const{operator:t,...n}=a;let o=e.bandbool(t);return Object.keys(n).length>0&&(o=this.applyFormatAndQuality(o,n)),o}applyAffine(e,a){const{background:t,interpolation:n,matrix:o,...r}=a;let s=e.affine(o,{background:t||"transparent",interpolator:n||"bicubic"});return Object.keys(r).length>0&&(s=this.applyFormatAndQuality(s,r)),s}applyDilate(e,a){const{kernelSize:t,...n}=a;let o=t?e.dilate(t):e.dilate();return Object.keys(n).length>0&&(o=this.applyFormatAndQuality(o,n)),o}applyErode(e,a){const{kernelSize:t,...n}=a;let o=t?e.erode(t):e.erode();return Object.keys(n).length>0&&(o=this.applyFormatAndQuality(o,n)),o}applyPipelineColourspace(e,a){const{colourspace:t,...n}=a;let o=e.pipelineColourspace(t);return Object.keys(n).length>0&&(o=this.applyFormatAndQuality(o,n)),o}applyToColourspace(e,a){const{colourspace:t,...n}=a;let o=e.toColourspace(t);return Object.keys(n).length>0&&(o=this.applyFormatAndQuality(o,n)),o}applyRemoveAlpha(e,a){const{background:t,...n}=a;let o=e.removeAlpha();return Object.keys(n).length>0&&(o=this.applyFormatAndQuality(o,n)),o}applyEnsureAlpha(e,a){const{alpha:t,...n}=a;let o=e.ensureAlpha();return Object.keys(n).length>0&&(o=this.applyFormatAndQuality(o,n)),o}applyFormatAndQuality(e,a){const t=this.getFormatOptions(a);return a.format?e.toFormat(a.format,t):Object.keys(t).length>0?e.jpeg(t).png(t).webp(t):e}getFormatOptions(e){const{alphaQuality:a,compressionLevel:t,delay:n,effort:o,loop:r,lossless:s,progressive:i,quality:l}=e,p={};return l!==void 0&&(p.quality=l),i!==void 0&&(p.progressive=i),s!==void 0&&(p.lossless=s),t!==void 0&&(p.compressionLevel=t),o!==void 0&&(p.effort=o),a!==void 0&&(p.alphaQuality=a),r!==void 0&&(p.loop=r),n!==void 0&&(p.delay=n),p}async validateImage(e){const a=typeof e.size=="string"?Number.parseInt(e.size,10):e.size;if(this.config?.maxImageSize&&a>this.config.maxImageSize)throw new Error(`Image size ${a} exceeds maximum allowed size ${this.config.maxImageSize}`);if(!f(e.contentType,"image"))throw new Error(`File is not an image: ${e.contentType}`);const t=d(e.contentType);if(this.config?.supportedFormats&&t&&!this.config.supportedFormats.includes(t))throw new Error(`Unsupported image format: ${t}`);try{const n=await this.openImage(e.content).metadata();if(!n.width||!n.height)throw new Error("Invalid image: missing dimensions");const{maxImageHeight:o,maxImageWidth:r}=this.config??{};if(r!==void 0&&n.width>r)throw new Error(`Image width ${n.width}px exceeds maximum ${r}px`);if(o!==void 0&&n.height>o)throw new Error(`Image height ${n.height}px exceeds maximum ${o}px`)}catch(n){throw new Error(`Invalid image file: ${n}`)}}async createTransformResult(e,a){const t=await y(e).metadata();return{buffer:e,format:t.format||"unknown",height:t.height||0,originalFile:a,size:e.length,width:t.width||0}}generateCacheKey(e,a){const t=a.map(n=>`${n.type}:${JSON.stringify(n.options)}`).join("|");return`${e}:${t}`}}export{C as default};
|