@metatime/pinning-service
Version:
Pinning service that is built on Google Cloud Storage on top of IPFS.
72 lines (71 loc) • 2.39 kB
TypeScript
import { Bucket, File, GetBucketsResponse } from "@google-cloud/storage";
/**
* An interface that provides BucketHelper class' typings
* @typedef {IBucketHelper}
*/
export interface IBucketHelper {
getBucket(name: string): Bucket | null;
getBuckets(): Promise<GetBucketsResponse>;
createBucket(name: string): Promise<{
bucket: Bucket;
response: any;
}>;
getFileFromBucket(bucketName: string, filePath: string): File | null;
uploadFileToBucket(bucketName: string, filePath: string, data: any): Promise<string | null>;
}
/**
* A class that provides GCP storage interactions
* @class BucketHelper
* @implements {IBucketHelper} - BucketHelper class interface
* @property {any} credentials - Google Cloud Storage credentials
*/
declare class BucketHelper implements IBucketHelper {
baseUri: string;
/** @private */
private credentials;
/**
* @param {string} _baseUri
* @param {any} _credentials
*/
constructor(_baseUri: string, _credentials: any);
/**
* @returns {Storage} - Google Cloud Storage instance
*/
private get storage();
/**
* Returns bucket from its name
* @param {string} name - Bucket name
* @returns Bucket | null
*/
getBucket(name: string): Bucket | null;
/**
* Returns buckets with the define GCP storage credentials
* @returns Promise<GetBucketsResponse>
*/
getBuckets(): Promise<GetBucketsResponse>;
/**
* Creates bucket from given name
* @param {string} name
* @returns Promise<{ bucket: Bucket, response: any; }>
*/
createBucket(name: string): Promise<{
bucket: Bucket;
response: any;
}>;
/**
* Returns file from bucket with the given file path
* @param {string} bucketName - Bucket name
* @param {string} filePath - File path in bucket
* @returns File | null
*/
getFileFromBucket(bucketName: string, filePath: string): File | null;
/**
* Uploads file to given bucket name and file path with the given data
* @param {string} bucketName - Bucket name
* @param {string} filePath - File path in bucket
* @param {any} data - File data as string or buffer
* @returns Promise<any>
*/
uploadFileToBucket(bucketName: string, filePath: string, data: any): Promise<string | null>;
}
export default BucketHelper;