UNPKG

upload-to-bunny

Version:

Upload-to-Bunny is a Node.JS library designed to simplify and speed up the process of uploading directories to BunnyCDN storage.

66 lines (65 loc) 2.5 kB
import { type LimitFunction } from "p-limit"; /** * Entry describing an item from Bunny Storage list API. * The API is not strongly consistent across docs, so we support common shapes. */ export interface BunnyListEntry { ObjectName?: string; Name?: string; Key?: string; IsDirectory?: boolean; isDirectory?: boolean; Type?: number; } /** * Options for Bunny Storage operations. */ export interface UploadOptions { /** Storage zone name to target. */ storageZoneName: string; /** Access key for the storage zone. */ accessKey: string; /** Optional region prefix, e.g. `la`, `ny`, `sg`, etc. */ region?: string; /** * When set to `simple`, remove the destination path before uploading. * When set to `avoid-deletes`, recursively prune remote files/folders that * are not present locally while preserving replacements. */ cleanDestination?: "simple" | "avoid-deletes"; /** Max concurrent uploads when sending files. Default: 10. */ maxConcurrentUploads?: number; /** * Optional custom p-limit instance. If not provided, a limiter is created * from `maxConcurrentUploads`. */ limit?: LimitFunction; } /** * Delete a file or empty directory on Bunny Storage. * * @param targetPath - Remote path relative to the storage root. * @param options - Authentication and behavior options. */ export declare const deleteFile: (targetPath: string, options: UploadOptions) => Promise<void>; /** * Upload a single file to Bunny Storage. * * @param sourcePath - Local filesystem path to read from. * @param targetPath - Remote path relative to the storage root. * @param options - Authentication and behavior options. */ export declare const uploadFile: (sourcePath: string, targetPath: string, options: UploadOptions) => Promise<void>; /** * Upload a directory to Bunny Storage. * * - When `cleanDestination` is `simple`, the destination path is deleted first. * - When `cleanDestination` is `avoid-deletes`, the remote is pruned to match the local content * without deleting files that are being replaced. * * @param sourceDirectory - Local directory to upload from. * @param targetDirectory - Remote directory at the storage root to upload into. * @param options - Optional upload settings and authentication. */ export declare const uploadDirectory: (sourceDirectory: string, targetDirectory: string, options: UploadOptions) => Promise<void>; export default uploadDirectory;