@uploadx/gcs
Version:
Uploadx GCS module
75 lines (74 loc) • 2.48 kB
TypeScript
import { BaseStorage, BaseStorageOptions, File, FileInit, FilePart, FileQuery, HttpError, IncomingMessage, LocalMetaStorageOptions, MetaStorage } from '@uploadx/core';
import { GoogleAuth, GoogleAuthOptions } from 'google-auth-library';
import { GCSMetaStorageOptions } from './gcs-meta-storage';
export interface ClientError extends Error {
code: string;
response?: Record<string, any>;
config: Record<string, any>;
}
export declare function getRangeEnd(range: string): number;
export declare function buildContentRange(part: Partial<FilePart> & GCSFile): string;
export interface GCStorageOptions extends BaseStorageOptions<GCSFile>, GoogleAuthOptions {
/**
* Google Cloud Storage bucket
*/
bucket?: string;
/**
* Force compatible client upload directly to GCS
*/
clientDirectUpload?: boolean;
/**
* Configure metafiles storage
* @example
* ```ts
* Using local metafiles
* const storage = new GCStorage({
* bucket: 'uploads',
* metaStorageConfig: { directory: '/tmp/upload-metafiles' }
* })
* ```
* Using a separate bucket for metafiles
* ```ts
* const storage = new GCStorage({
* bucket: 'uploads',
* metaStorageConfig: { bucket: 'upload-metafiles' }
* })
* ```
*/
metaStorageConfig?: LocalMetaStorageOptions | GCSMetaStorageOptions;
}
export declare class GCSFile extends File {
GCSUploadURI?: string;
uri?: string;
}
/**
* Google cloud storage based backend.
* @example
* ```ts
* const storage = new GCStorage({
* bucket: <YOUR_BUCKET>,
* keyFile: <PATH_TO_KEY_FILE>,
* metaStorage: new MetaStorage(),
* clientDirectUpload: true,
* maxUploadSize: '15GB',
* allowMIME: ['video/*', 'image/*'],
* filename: file => file.originalName
* });
* ```
*/
export declare class GCStorage extends BaseStorage<GCSFile> {
config: GCStorageOptions;
bucket: string;
authClient: GoogleAuth;
storageBaseURI: string;
uploadBaseURI: string;
meta: MetaStorage<GCSFile>;
constructor(config?: GCStorageOptions);
normalizeError(error: ClientError): HttpError;
accessCheck(): Promise<any>;
create(req: IncomingMessage, config: FileInit): Promise<GCSFile>;
write(part: FilePart | FileQuery): Promise<GCSFile>;
delete({ id }: FileQuery): Promise<GCSFile[]>;
protected _write(part: Partial<FilePart> & GCSFile): Promise<number>;
private _onComplete;
}