UNPKG

@nuxthub/core

Version:

Build full-stack Nuxt applications on Cloudflare, with zero configuration.

159 lines (158 loc) 5.48 kB
import type { ReadableStream } from '@cloudflare/workers-types/experimental'; import { type H3Event } from 'h3'; import type { BlobListResult, BlobMultipartUpload, HandleMPUResponse, BlobMultipartOptions, BlobUploadOptions, BlobPutOptions, BlobEnsureOptions, BlobObject, BlobListOptions, BlobCredentialsOptions, BlobCredentials } from '@nuxthub/core'; interface HubBlob { /** * List all the blobs in the bucket (metadata only). * * @param options The list options * * @example ```ts * const { blobs } = await hubBlob().list({ limit: 10 }) * ``` */ list(options?: BlobListOptions): Promise<BlobListResult>; /** * Serve the blob from the bucket. * * @param event The H3 event (needed to set headers for the response) * @param pathname The pathname of the blob * * @example ```ts * export default eventHandler(async (event) => { * return hubBlob().serve(event, '/my-image.jpg') * }) * ``` */ serve(event: H3Event, pathname: string): Promise<ReadableStream<any>>; /** * Put a new blob into the bucket. * * @param pathname The pathname of the blob * @param body The blob content * @param options The put options * * @example ```ts * const blob = await hubBlob().put('/my-image.jpg', file) * ``` */ put(pathname: string, body: string | ReadableStream<any> | ArrayBuffer | ArrayBufferView | Blob, options?: BlobPutOptions): Promise<BlobObject>; /** * Get the blob metadata from the bucket. * * @param pathname The pathname of the blob * * @example ```ts * const blobMetadata = await hubBlob().head('/my-image.jpg') * ``` */ head(pathname: string): Promise<BlobObject>; /** * Get the blob body from the bucket. * * @param pathname The pathname of the blob * * @example ```ts * const blob = await hubBlob().get('/my-image.jpg') * ``` */ get(pathname: string): Promise<Blob | null>; /** * Delete the blob from the bucket. * * @param pathnames The pathname of the blob * * @example ```ts * await hubBlob().del('/my-image.jpg') * ``` */ del(pathnames: string | string[]): Promise<void>; /** * Delete the blob from the bucket. * * @param pathnames The pathname of the blob * * @example ```ts * await hubBlob().delete('/my-image.jpg') * ``` */ delete(pathnames: string | string[]): Promise<void>; /** * Create a multipart upload. * * @see https://hub.nuxt.com/docs/features/blob#createmultipartupload */ createMultipartUpload(pathname: string, options?: BlobMultipartOptions): Promise<BlobMultipartUpload>; /** * Get the specified multipart upload. * * @see https://hub.nuxt.com/docs/features/blob#resumemultipartupload */ resumeMultipartUpload(pathname: string, uploadId: string): BlobMultipartUpload; /** * Handle the multipart upload request. * Make sure your route includes `[action]` and `[...pathname]` params. * * @see https://hub.nuxt.com/docs/features/blob#handlemultipartupload */ handleMultipartUpload(event: H3Event, options?: BlobMultipartOptions): Promise<HandleMPUResponse>; /** * Handle a file upload. * * @param event The H3 event (needed to set headers for the response) * @param options The upload options * * @see https://hub.nuxt.com/docs/features/blob#handleupload */ handleUpload(event: H3Event, options?: BlobUploadOptions): Promise<BlobObject[]>; /** * Creates temporary access credentials that can be optionally scoped to prefixes or objects. * * Useful to create a signed url to upload directory to R2 from client-side. * * Only available in production or in development with `--remote` flag. * * @example ```ts * const { accountId, bucketName, accessKeyId, secretAccessKey, sessionToken } = await hubBlob().createCredentials() * ``` */ createCredentials(options?: BlobCredentialsOptions): Promise<BlobCredentials>; } /** * Access the Blob storage. * * @example ```ts * const blob = hubBlob() * const { blobs } = await blob.list() * ``` * * @see https://hub.nuxt.com/docs/features/blob */ export declare function hubBlob(): HubBlob; /** * Access the remote Blob storage. * * @param projectUrl The project URL (e.g. https://my-deployed-project.nuxt.dev) * @param secretKey The secret key to authenticate to the remote endpoint * @param headers The headers to send with the request to the remote endpoint * * @example ```ts * const blob = proxyHubBlob('https://my-deployed-project.nuxt.dev', 'my-secret-key') * const { blobs } = await blob.list() * ``` * * @see https://hub.nuxt.com/docs/features/blob */ export declare function proxyHubBlob(projectUrl: string, secretKey?: string, headers?: HeadersInit): HubBlob; /** * Ensure the blob is valid and meets the specified requirements. * * @param blob The blob to check * @param options The options to check against * @param options.maxSize The maximum size of the blob (e.g. '1MB') * @param options.types The allowed types of the blob (e.g. ['image/png', 'application/json', 'video']) * * @throws If the blob does not meet the requirements */ export declare function ensureBlob(blob: Blob, options?: BlobEnsureOptions): void; export {};