import { S3Client } from '@aws-sdk/client-s3'; /** * @deprecated 腾讯云 COS 专用实现已迁移为通用 S3 兼容实现(见 ./s3)。 * * 本文件**保留腾讯云 COS 原有调用接口**(SecretId / SecretKey / Region 等参数形状不变), * 内部自动映射到 S3 兼容实现,并对返回值做形状适配,确保旧项目无需修改即可继续工作。 * 新项目请直接使用 `Common.utils.s3`。 * * 兼容映射规则: * - `SecretId` -> `accessKeyId` * - `SecretKey` -> `secretAccessKey` * - `Region` -> 自动拼接腾讯云 COS 兼容端点 `https://cos..myqcloud.com`,并使用虚拟主机风格 * (即默认公开 URL 形如 `https://.cos..myqcloud.com/`,与原 COS SDK 一致) * * 返回值适配: * - `uploadFile` / `putObject`:补充 `statusCode`、`headers` 字段 * - `getFile`:将 `Body` 从 ReadableStream 转为 Buffer(与原 COS SDK 一致),补充 `statusCode` * - `checkExists`:404/403 返回 false,其他错误向上抛出 */ /** 兼容原腾讯云 COS 配置,同时兼容已迁移的 S3 配置(可混用) */ export interface COSOptions { /** 腾讯云 SecretId(映射到 accessKeyId) */ SecretId?: string; /** 腾讯云 SecretKey(映射到 secretAccessKey) */ SecretKey?: string; /** 地域,如 ap-guangzhou */ Region?: string; /** 已迁移的 S3 凭证(与 SecretId 二选一) */ accessKeyId?: string; /** 已迁移的 S3 凭证(与 SecretKey 二选一) */ secretAccessKey?: string; region?: string; endpoint?: string; forcePathStyle?: boolean; /** 对外公开 URL 的域名模板(支持 ${Bucket} / ${Region} 等变量),覆盖默认腾讯云域名 */ domain?: string; bucket?: string; } /** COS 兼容的上传参数(形状同原 COS.UploadFileParams / COS.PutObjectParams) */ export interface COSUploadParams { Bucket: string; Region?: string; Key: string; Body?: Buffer | Uint8Array | string | NodeJS.ReadableStream; FilePath?: string; ContentType?: string; Metadata?: Record; /** 原 COS SDK 的 Headers 字段(兼容旧调用方,自动映射到 S3 的 ContentType / Metadata 等) */ Headers?: Record; } /** COS 兼容的获取参数 */ export interface COSGetParams { Bucket: string; Region?: string; Key: string; } /** COS 兼容的 URL 参数 */ export interface COSUrlParams { Bucket: string; Region?: string; Key: string; Sign?: boolean; Expires?: number; } /** COS 兼容的返回值(补充 statusCode / headers 以兼容旧调用方) */ export interface COSResult { statusCode?: number; headers?: Record; Location?: string; ETag?: string; Body?: Buffer; $metadata?: any; [key: string]: any; } /** * 创建客户端(兼容原腾讯云 COS 的 createClient({ SecretId, SecretKey, Region }))。 */ export declare function createClient(option: COSOptions): S3Client; /** * 分片上传文件(适合大文件),参数形状同原 COS uploadFile。 * 返回值适配:补充 statusCode、headers、Location 字段。 */ export declare function uploadFile(params: COSUploadParams, cos?: S3Client | COSOptions): Promise; /** * 简单上传(适合小文件),参数形状同原 COS putObject。 * 返回值适配:补充 statusCode、headers、Location 字段。 */ export declare function putObject(params: COSUploadParams, cos?: S3Client | COSOptions): Promise; /** * 获取文件内容,参数形状同原 COS getObject。 * 返回值适配:将 Body 从 ReadableStream 转为 Buffer(与原 COS SDK 一致),补充 statusCode。 */ export declare function getFile(params: COSGetParams, cos?: S3Client | COSOptions): Promise; /** * 获取文件 URL,参数形状同原 COS getObjectUrl(Sign / Expires 均兼容)。 * - Sign=false:返回与原 COS 一致的虚拟主机公开 URL。 * - Sign=true:返回带签名的预签名 URL。 */ export declare function getObjectUrl(params: COSUrlParams, cos?: S3Client | COSOptions): Promise; /** * 检查文件是否存在(404/403 返回 false),参数形状同原 COS headObject。 * 其他错误(网络故障、服务端 500 等)向上抛出。 */ export declare function checkExists(params: COSGetParams, cos?: S3Client | COSOptions): Promise; declare const _default: { createClient: typeof createClient; uploadFile: typeof uploadFile; putObject: typeof putObject; getFile: typeof getFile; getObjectUrl: typeof getObjectUrl; checkExists: typeof checkExists; }; export default _default;