UNPKG

@adonis-agora/media

Version:

Media-library for AdonisJS — owner collections (MIME whitelist, single-file replace, ordering), image conversions (eager/lazy), pluggable content transformers (HLS video via mediabunny, metadata probe, image blur-up placeholder), and column attachments, a

102 lines • 5.94 kB
import type { Readable } from 'node:stream'; import { type S3Client } from '@aws-sdk/client-s3'; import type { CopyOptions, Disk, DiskCapabilities, DiskMetaData, DiskStat, DiskWriteOptions, ExtendedDisk, ListOptions, ListResult, MultipartPart, MultipartUploadDisk, SignedUrlOptions } from '../types.js'; /** * Construction options for {@link S3Disk}. The {@link S3Client} is built and injected by the * `disks.s3()` factory (which lazily imports `@aws-sdk/client-s3`), so this module — and the heavy * AWS SDK it pulls in — is only ever loaded when an S3 disk is actually selected. */ export interface S3DiskOptions { /** A configured `@aws-sdk/client-s3` client. */ client: S3Client; /** Target bucket. */ bucket: string; /** Prefix prepended to every key (e.g. `uploads`). Leading/trailing slashes are trimmed. */ keyPrefix?: string; /** Base URL for stable public URLs (CDN or bucket website). When set, {@link S3Disk.getUrl} uses it. */ publicBaseUrl?: string; /** Region — used only to synthesise a virtual-hosted URL when no `publicBaseUrl` is set. */ region?: string; /** Custom endpoint (S3-compatible services). Used for URL synthesis when no `publicBaseUrl` is set. */ endpoint?: string; /** * Endpoint presigned URLs are signed against, when it differs from `endpoint`. SigV4 embeds the * `Host` in the signature, and presigned URLs are consumed by the BROWSER (a part `PUT` during a * direct upload, a `GET` while streaming) — so when the app reaches storage through an internal * FQDN the internet cannot resolve (MinIO behind a private network), set this to the public one. * Server-side operations keep using `endpoint`; only what leaves the server is signed for here. */ publicEndpoint?: string; /** Emit path-style URLs (`endpoint/bucket/key`) instead of virtual-hosted-style. */ forcePathStyle?: boolean; /** * Whether objects on this disk are readable without credentials. Declarative — it is NOT applied * as an ACL on write and never probes S3; it simply answers {@link S3Disk.getVisibility}, which is * what `delivery.mode: 'auto'` reads to choose between a public and a signed URL. Default * `private`, the safe assumption for a bucket whose policy this disk cannot see. */ visibility?: 'public' | 'private'; } /** * S3-backed {@link Disk} satisfying the same structural contract as an `@adonisjs/drive` disk, so it * is a drop-in for the media-library and attachment layers. Backed by `@aws-sdk/client-s3` (an * optional peer). Beyond the base {@link Disk} surface it also implements {@link MultipartUploadDisk} * — native S3 multipart, powering the `proxy` and `direct` upload modes — which the upload layer * detects structurally (`isMultipartCapable`) rather than through the base contract. It also * implements the optional {@link ExtendedDisk} surface (copy/move, batched delete, list, size/stat, * plus a {@link DiskCapabilities} descriptor), detected structurally via `isExtendedDisk`. */ export declare class S3Disk implements Disk, MultipartUploadDisk, ExtendedDisk { #private; /** Coarse feature descriptor — S3 supports presign, native multipart, and prefix listing. */ readonly capabilities: DiskCapabilities; private readonly client; private readonly bucket; private readonly keyPrefix; private readonly publicBaseUrl; private readonly region; private readonly endpoint; private readonly publicEndpoint; private readonly forcePathStyle; private readonly visibility; constructor(options: S3DiskOptions); /** Map a logical key to a fully-qualified S3 key, applying the configured prefix. */ key(path: string): string; put(key: string, contents: Uint8Array, options?: DiskWriteOptions): Promise<void>; /** * `ContentLength` is required, not an optimization: S3 cannot size a stream, so the SDK * derives `x-amz-decoded-content-length` from it and throws * `Invalid value "undefined" for header "x-amz-decoded-content-length"` when it is absent. * Callers that reach this path already know the size (it is what makes streaming eligible). */ putStream(key: string, contents: Readable, options?: DiskWriteOptions): Promise<void>; getBytes(key: string): Promise<Uint8Array>; getStream(key: string): Promise<Readable>; exists(key: string): Promise<boolean>; delete(key: string): Promise<void>; getUrl(key: string): Promise<string>; /** * The configured visibility, verbatim — S3 cannot be asked cheaply (a `GetObjectAcl` per read is * not free, and object ACLs say nothing about a bucket policy anyway), so this reports what the * disk was told rather than guessing. */ getVisibility(_key: string): Promise<'public' | 'private'>; getSignedUrl(key: string, options?: SignedUrlOptions): Promise<string>; getMetaData(key: string): Promise<DiskMetaData>; size(key: string): Promise<number>; stat(key: string): Promise<DiskStat>; copy(from: string, to: string, options?: CopyOptions): Promise<void>; move(from: string, to: string, options?: CopyOptions): Promise<void>; private batchDeleteUnsupported; private deleteOneByOne; deleteMany(keys: string[]): Promise<void>; list(prefix: string, options?: ListOptions): Promise<ListResult>; createMultipartUpload(key: string, options?: DiskWriteOptions): Promise<{ uploadId: string; }>; uploadPart(key: string, uploadId: string, partNumber: number, body: Uint8Array): Promise<MultipartPart>; presignUploadPart(key: string, uploadId: string, partNumber: number, expiresInSeconds: number): Promise<string>; completeMultipartUpload(key: string, uploadId: string, parts: MultipartPart[]): Promise<void>; abortMultipartUpload(key: string, uploadId: string): Promise<void>; } //# sourceMappingURL=s3.d.ts.map