@teenth/sdk-tool
Version:
sdk-tool with R2 storage support
49 lines (48 loc) • 1.46 kB
TypeScript
/// <reference types="node" />
import { S3Client } from "@aws-sdk/client-s3";
interface FileInterface {
arrayBuffer(): Promise<ArrayBuffer>;
type: string;
name: string;
size: number;
}
declare global {
interface File extends FileInterface {
}
}
export interface R2Config {
accountId: string;
accessKeyId: string;
secretAccessKey: string;
bucket: string;
region?: string;
endpoint?: string;
cdnDomain?: string;
}
export interface UploadOptions {
contentType?: string;
expiresIn?: number;
}
export interface UploadResult {
url: string;
fileName: string;
size: number;
}
export type FileInput = FileInterface | Buffer | string | Uint8Array | ArrayBuffer;
export interface MigrateUrlOptions {
fileName?: string;
contentType?: string;
expiresIn?: number;
}
export interface R2StorageInstance {
get: (fileName: string) => Promise<any>;
upload: (fileName: string, data: FileInput, options?: UploadOptions) => Promise<UploadResult>;
delete: (fileName: string) => Promise<void>;
list: (prefix?: string, maxKeys?: number) => Promise<any[]>;
getSignedUrl: (fileName: string, expiresIn?: number) => Promise<string>;
exists: (fileName: string) => Promise<boolean>;
migrateUrl: (url: string, options?: MigrateUrlOptions) => Promise<UploadResult>;
client: S3Client;
}
export declare function createR2Storage(config: R2Config): R2StorageInstance;
export {};