/** * Copyright (c) 2014 Baidu.com, Inc. All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. * * @file src/bos_client.ts * @author leeight */ import * as fs from 'fs'; import * as stream from 'stream'; import BceBaseClient from './bce_base_client'; import SuperUpload from './bos/super_upload'; import type { BceConfig, BceResponse, HttpMethod } from './types/common'; import type { RequestArgs } from './bce_base_client'; import type { ListObjectsResponse, ListBucketsResponse, ObjectMetadata, PutObjectResponse, PutBucketResponse, DeleteObjectResponse, DeleteBucketResponse, CopyObjectResponse, MultipartUploadResponse, ListPartsResponse, StorageClass, ServerSideEncryption, WebsiteConfiguration, EncryptionConfiguration, BosClientOptions, ListObjectsOptions, PutObjectOptions, GetObjectOptions, CopyObjectOptions, MultipartUploadOptions, SuperUploadOptions } from './bos/types'; /** * BOS service client for Baidu Object Storage * * @see http://gollum.baidu.com/BOS_API#BOS-API文档 */ export default class BosClient extends BceBaseClient { /** * Create a new BOS client instance * * @param config - The BOS client configuration */ constructor(config: BceConfig); /** * Generate a presigned URL with expiration time and optional arguments * * @param bucketName - The target bucket name * @param key - The target object name * @param timestamp - A number representing timestamp in seconds * @param expirationInSeconds - Expire time in seconds * @param headers - Optional HTTP request headers * @param params - Optional sign params * @param headersToSign - Optional request headers list to calculate in the signature * @param config - The client configuration * @returns The presigned URL with authorization string */ generatePresignedUrl(bucketName: string, key: string, timestamp: number, expirationInSeconds: number, headers?: Record, params?: Record, headersToSign?: string[], config?: Partial): string; /** * Generate a URL for object access with optional image processing pipeline * * @param bucketName - The bucket name * @param key - The object key * @param pipeline - Image processing pipeline configuration * @param cdn - CDN domain * @param config - Optional configuration * @returns The generated URL */ generateUrl(bucketName: string, key: string, pipeline?: string | Record[], cdn?: string, config?: Partial): string; /** * List all buckets * * @param options - Optional configuration * @returns Promise resolving to the list of buckets */ listBuckets(options?: BosClientOptions): Promise>; /** * Create a new bucket * * @param bucketName - The bucket name to create * @param options - Optional bucket configuration * @returns Promise resolving to the creation response */ createBucket(bucketName: string, options?: { body?: { enableMultiAZ?: boolean; }; config?: Partial; }): Promise>; /** * Alias for createBucket */ putBucket: (bucketName: string, options?: { body?: { enableMultiAZ?: boolean; }; config?: Partial; }) => Promise>; /** * Delete a bucket * * @param bucketName - The bucket name to delete * @param options - Optional configuration * @returns Promise resolving to the deletion response */ deleteBucket(bucketName: string, options?: BosClientOptions): Promise>; /** * Check if a bucket exists * * @param bucketName - The bucket name to check * @param options - Optional configuration * @returns Promise resolving to true if bucket exists, false otherwise */ headBucket(bucketName: string, options?: BosClientOptions): Promise; /** * Alias for headBucket */ doesBucketExist: (bucketName: string, options?: BosClientOptions) => Promise; /** * Get bucket location * * @param bucketName - The bucket name * @param options - Optional configuration * @returns Promise resolving to the bucket location */ getBucketLocation(bucketName: string, options?: BosClientOptions): Promise>; /** * Set bucket static website hosting configuration * * @param bucketName - The bucket name * @param body - Website configuration * @param options - Optional configuration * @returns Promise resolving to the response */ putBucketStaticWebsite(bucketName: string, body: WebsiteConfiguration, options?: BosClientOptions): Promise>; /** * Get bucket static website hosting configuration * * @param bucketName - The bucket name * @param options - Optional configuration * @returns Promise resolving to the website configuration */ getBucketStaticWebsite(bucketName: string, options?: BosClientOptions): Promise>; /** * Delete bucket static website hosting configuration * * @param bucketName - The bucket name * @param options - Optional configuration * @returns Promise resolving to the response */ deleteBucketStaticWebsite(bucketName: string, options?: BosClientOptions): Promise>; /** * Enable bucket encryption * * @param bucketName - The bucket name * @param options - Encryption options * @returns Promise resolving to the response */ putBucketEncryption(bucketName: string, options: { headers: { encryptionAlgorithm: ServerSideEncryption; }; config?: Partial; }): Promise>; /** * Get bucket encryption configuration * * @param bucketName - The bucket name * @param options - Optional configuration * @returns Promise resolving to the encryption configuration */ getBucketEncryption(bucketName: string, options?: BosClientOptions): Promise>; /** * Delete bucket encryption configuration * * @param bucketName - The bucket name * @param options - Optional configuration * @returns Promise resolving to the response */ deleteBucketEncryption(bucketName: string, options?: BosClientOptions): Promise>; /** * Set bucket default storage class * * @param bucketName - The bucket name * @param storageClass - The storage class to set * @param options - Optional configuration * @returns Promise resolving to the response */ putBucketStorageClass(bucketName: string, storageClass: StorageClass, options?: BosClientOptions): Promise>; /** * Get bucket default storage class * * @param bucketName - The bucket name * @param options - Optional configuration * @returns Promise resolving to the storage class */ getBucketStorageClass(bucketName: string, options?: BosClientOptions): Promise>; /** * Alias for getBucketStorageClass (lowercase c) * * @param bucketName - The bucket name * @param options - Optional configuration * @returns Promise resolving to the storage class */ getBucketStorageclass: (bucketName: string, options?: BosClientOptions) => Promise>; /** * List objects in a bucket * * @param bucketName - The bucket name * @param options - List options * @returns Promise resolving to the list of objects */ listObjects(bucketName: string, options?: ListObjectsOptions & { config?: Partial; }): Promise>; /** * Delete multiple objects * * @param bucketName - The bucket name * @param objects - Array of object keys to delete * @param options - Optional configuration * @returns Promise resolving to the deletion response */ deleteMultipleObjects(bucketName: string, objects: string[], options?: BosClientOptions): Promise>; /** * Delete a single object * * @param bucketName - The bucket name * @param key - The object key * @param options - Optional configuration * @returns Promise resolving to the deletion response */ deleteObject(bucketName: string, key: string, options?: BosClientOptions): Promise>; /** * Upload an object to BOS * * @param bucketName - The bucket name * @param key - The object key * @param data - The object data * @param options - Upload options * @returns Promise resolving to the upload response */ putObject(bucketName: string, key: string, data: string | Buffer | stream.Readable, options?: PutObjectOptions): Promise>; /** * Upload an object from a Blob (browser environment) * * @param bucketName - The bucket name * @param key - The object key * @param blob - The Blob data * @param options - Upload options * @returns Promise resolving to the upload response */ putObjectFromBlob(bucketName: string, key: string, blob: Blob, options?: PutObjectOptions): Promise>; /** * Upload an object from a base64 data URL * * @param bucketName - The bucket name * @param key - The object key * @param data - Base64 encoded data * @param options - Upload options * @returns Promise resolving to the upload response */ putObjectFromDataUrl(bucketName: string, key: string, data: string, options?: PutObjectOptions): Promise>; /** * Upload an object from a string * * @param bucketName - The bucket name * @param key - The object key * @param data - String data * @param options - Upload options * @returns Promise resolving to the upload response */ putObjectFromString(bucketName: string, key: string, data: string, options?: PutObjectOptions): Promise>; /** * Upload an object from a file * * @param bucketName - The bucket name * @param key - The object key * @param filename - Path to the file * @param options - Upload options * @returns Promise resolving to the upload response */ putObjectFromFile(bucketName: string, key: string, filename: string, options?: PutObjectOptions): Promise>; /** * Get object metadata (HEAD request) * * @param bucketName - The bucket name * @param key - The object key * @param options - Optional configuration * @returns Promise resolving to the object metadata */ getObjectMetadata(bucketName: string, key: string, options?: BosClientOptions): Promise>; /** * Get an object from BOS * * @param bucketName - The bucket name * @param key - The object key * @param range - Optional byte range * @param options - Get options * @returns Promise resolving to the object data */ getObject(bucketName: string, key: string, range?: string, options?: GetObjectOptions): Promise>; /** * Copy an object within BOS * * @param sourceBucketName - Source bucket name * @param sourceKey - Source object key * @param targetBucketName - Target bucket name * @param targetKey - Target object key * @param options - Copy options * @returns Promise resolving to the copy response */ copyObject(sourceBucketName: string, sourceKey: string, targetBucketName: string, targetKey: string, options?: CopyObjectOptions): Promise>; /** * Initiate multipart upload * * @param bucketName - The bucket name * @param key - The object key * @param options - Upload options * @returns Promise resolving to the initiation response */ initiateMultipartUpload(bucketName: string, key: string, options?: MultipartUploadOptions): Promise>; /** * Upload part from file * * @param bucketName - The bucket name * @param key - The object key * @param uploadId - The upload ID * @param partNumber - The part number * @param partSize - The part size * @param filename - The file path * @param offset - The file offset * @param options - Upload options * @returns Promise resolving to the upload response */ uploadPartFromFile(bucketName: string, key: string, uploadId: string, partNumber: number, partSize: number, filename: string, offset: number, options?: MultipartUploadOptions): Promise>; /** * Upload part from Blob * * @param bucketName - The bucket name * @param key - The object key * @param uploadId - The upload ID * @param partNumber - The part number * @param partSize - The part size * @param blob - The Blob data * @param options - Upload options * @returns Promise resolving to the upload response */ uploadPartFromBlob(bucketName: string, key: string, uploadId: string, partNumber: number, partSize: number, blob: Blob, options?: MultipartUploadOptions): Promise>; /** * Upload part from data URL * * @param bucketName - The bucket name * @param key - The object key * @param uploadId - The upload ID * @param partNumber - The part number * @param partSize - The part size * @param dataUrl - Base64 encoded data * @param options - Upload options * @returns Promise resolving to the upload response */ uploadPartFromDataUrl(bucketName: string, key: string, uploadId: string, partNumber: number, partSize: number, dataUrl: string, options?: MultipartUploadOptions): Promise>; /** * Upload a part for multipart upload * * @param bucketName - The bucket name * @param key - The object key * @param uploadId - The upload ID * @param partNumber - The part number * @param partSize - The part size * @param partFp - The part file stream * @param options - Upload options * @returns Promise resolving to the upload response */ uploadPart(bucketName: string, key: string, uploadId: string, partNumber: number, partSize: number, partFp: fs.ReadStream, options?: MultipartUploadOptions): Promise>; /** * List parts for a multipart upload * * @param bucketName - The bucket name * @param key - The object key * @param uploadId - The upload ID * @param options - List options * @returns Promise resolving to the list of parts */ listParts(bucketName: string, key: string, uploadId: string, options?: { partNumberMarker?: number; config?: Partial; }): Promise>; /** * Complete multipart upload * * @param bucketName - The bucket name * @param key - The object key * @param uploadId - The upload ID * @param partList - List of completed parts * @param options - Complete options * @returns Promise resolving to the completion response */ completeMultipartUpload(bucketName: string, key: string, uploadId: string, partList: Array<{ partNumber: number; eTag: string; }>, options?: MultipartUploadOptions): Promise>; /** * Adaptive multipart upload for large files * * @param params - Upload parameters * @returns SuperUpload instance for managing the upload */ putSuperObject(params: SuperUploadOptions): SuperUpload; /** * Check and normalize options for API calls * * @param options - Input options * @param allowedParams - Allowed parameter names * @returns Normalized options */ _checkOptions(options: any, allowedParams?: string[]): { config: Partial; headers: Record; params: Record; }; /** * Prepare and validate object headers * * @param options - Input options * @returns Validated headers */ _prepareObjectHeaders(options: any): Record; sendRequest(httpMethod: HttpMethod, resource: string, varArgs?: Partial): Promise>; sendRequest(httpMethod: string, varArgs: any, requestUrl?: string): Promise>; private sendBosRequest; } //# sourceMappingURL=bos_client.d.ts.map