/** * 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/helper.ts * @author leeight */ import { Readable } from 'stream'; import type { BceResponse, Protocol } from './types/common'; /** 分片信息接口 */ interface PartInfo { partNumber: number; eTag: string; } /** 域名解析结果接口 */ interface DomainInfo { protocol: string; host: string; } /** BOS客户端接口(最小必需方法) */ interface BosClientLike { putObject(bucket: string, object: string, data: any, options?: any): Promise; putObjectFromFile(bucket: string, object: string, filename: string, options?: any): Promise; putObjectFromBlob(bucket: string, object: string, blob: Blob, options?: any): Promise; initiateMultipartUpload(bucket: string, object: string, options?: any): Promise>; uploadPartFromFile(bucket: string, object: string, uploadId: string, partNumber: number, partSize: number, filename: string, start: number): Promise; uploadPartFromDataUrl(bucket: string, object: string, uploadId: string, partNumber: number, partSize: number, dataUrl: string): Promise; uploadPartFromBlob(bucket: string, object: string, uploadId: string, partNumber: number, partSize: number, blob: Blob): Promise; completeMultipartUpload(bucket: string, object: string, uploadId: string, parts: PartInfo[]): Promise; emit(event: string, data: any): void; } /** 端点处理选项接口 */ interface EndpointHandleOptions { bucketName?: string; endpoint: string; protocol: Protocol; region?: string; customGenerateUrl?: (bucketName?: string, region?: string) => string; cname_enabled?: boolean; pathStyleEnable?: boolean; } /** * 过滤 null 值的工具函数 * @param value 值 * @param key 键 * @param object 对象 * @returns 是否保留该值 */ export declare function omitNull(value: any, key: string, object: any): boolean; /** * 自适应的按需上传文件 * @param client BOS 客户端实例 * @param bucket 存储桶名称 * @param object 对象名称 * @param data 要上传的数据 * @param options 请求选项 * @returns Promise */ export declare function upload(client: BosClientLike, bucket: string, object: string, data: string | Buffer | Readable | Blob, options?: any): Promise; /** * 获取域名不带协议的部分 * @param host 主机地址 * @returns 域名信息 */ declare function getDomainWithoutProtocol(host: string): DomainInfo; /** * 判断是否为虚拟主机格式 * @param host 主机地址 * @returns 是否为虚拟主机 */ declare function isVirtualHost(host: string): boolean; /** * 判断是否为 IP 主机 * @param host 主机地址 * @returns 是否为 IP 主机 */ declare function isIpHost(host: string): boolean; /** * 判断是否为 BOS 默认官方主机 * @param host 主机地址 * @returns 是否为 BOS 主机 */ declare function isBosHost(host: string): boolean; /** * 判断是否为 CNAME 类型主机 * @param host 主机地址 * @returns 是否为 CNAME 类型主机 */ declare function isCnameLikeHost(host: string): boolean; /** * 检查是否需要兼容存储桶和端点 * @param bucket 存储桶名称 * @param endpoint 端点地址 * @returns 是否需要兼容 */ declare function needCompatibleBucketAndEndpoint(bucket?: string, endpoint?: string): boolean; /** * 根据存储桶替换端点 * @param bucket 存储桶名称 * @param endpoint 端点地址 * @returns 新的端点地址 */ declare function replaceEndpointByBucket(bucket: string, endpoint: string): string; /** * 生成基础端点 * @param protocol 协议 * @param region 地域 * @returns 基础端点地址 */ declare function generateBaseEndpoint(protocol: Protocol, region: string): string; /** * 处理端点地址 * @param options 端点处理选项 * @returns 处理后的端点地址 */ declare function handleEndpoint(options: EndpointHandleOptions): string; /** 域名工具集合 */ export declare const domainUtils: { getDomainWithoutProtocol: typeof getDomainWithoutProtocol; isVirtualHost: typeof isVirtualHost; isIpHost: typeof isIpHost; isBosHost: typeof isBosHost; isCnameLikeHost: typeof isCnameLikeHost; needCompatibleBucketAndEndpoint: typeof needCompatibleBucketAndEndpoint; replaceEndpointByBucket: typeof replaceEndpointByBucket; generateBaseEndpoint: typeof generateBaseEndpoint; handleEndpoint: typeof handleEndpoint; }; declare const _default: { omitNull: typeof omitNull; upload: typeof upload; domainUtils: { getDomainWithoutProtocol: typeof getDomainWithoutProtocol; isVirtualHost: typeof isVirtualHost; isIpHost: typeof isIpHost; isBosHost: typeof isBosHost; isCnameLikeHost: typeof isCnameLikeHost; needCompatibleBucketAndEndpoint: typeof needCompatibleBucketAndEndpoint; replaceEndpointByBucket: typeof replaceEndpointByBucket; generateBaseEndpoint: typeof generateBaseEndpoint; handleEndpoint: typeof handleEndpoint; }; }; export default _default; //# sourceMappingURL=helper.d.ts.map