UNPKG

@fine-dev/fine-js

Version:

Javascript client for Fine BaaS

72 lines 2.42 kB
import { Fetch } from "./types"; export type EntityReference = { table: string; id: string | number; field: string; }; export type UploadMetadata = Record<string, string>; export type FileDetails = { key: string; size: number; uploadedAt: string; etag: string; httpMetadata?: { contentType: string; }; customMetadata?: Record<string, string>; }; export type StorageClientOptions = { baseUrl: string; fetch?: Fetch; headers?: HeadersInit; }; export default class FineStorageClient { private fetch; private baseUrl; constructor({ baseUrl, headers, fetch: customFetch }: StorageClientOptions); /** * Builds the base URL path for an entity and file * @param entity The entity reference * @param filename The filename * @returns The formatted URL path */ private getEntityPath; /** * Upload a file associated with an entity * @param entity The entity reference * @param file The file to upload * @param metadata Optional metadata for the file * @param isPublic Whether the file should be publicly accessible * @returns Promise with file details */ upload(entity: EntityReference, file: File, metadata?: UploadMetadata, isPublic?: boolean): Promise<FileDetails>; /** * Generate a download URL for a file * @param entity The entity reference * @param filename The filename * @returns The download URL */ getDownloadUrl(entity: EntityReference, filename: string): string; /** * Download a file associated with an entity * @param entity The entity reference * @param filename The filename * @returns Promise that resolves when the download starts */ download(entity: EntityReference, filename: string): Promise<void>; /** * Get the file content as a Blob without triggering a download * @param entity The entity reference * @param filename The filename * @returns Promise with the file blob */ getFileBlob(entity: EntityReference, filename: string): Promise<Blob>; /** * Delete a file associated with an entity * @param entity The entity reference * @param filename The filename * @returns Promise that resolves when the deletion is complete */ delete(entity: EntityReference, filename: string): Promise<void>; } //# sourceMappingURL=storage.d.ts.map