import { Environment } from '../environment'; import { IUploadMetadata, IListFileInfo, IFileInfo, ITempUrlInfo, IResponseInfo } from '../interfaces'; import { IStorageConfig } from '../utils/storage-config'; import { IUploadObjectHttpOptions, IUploadObjectHttpResult, IDeleteObjectHttpOptions, IDeleteObjectHttpResult, IDeleteObjectsHttpOptions, IDeletedObjectInfo, ICopyObjectHttpOptions, ICopyObjectHttpResult, IMoveObjectHttpOptions, IMoveObjectHttpResult, IListObjectsHttpOptions, IListObjectsHttpResult, ISignObjectHttpOptions, ISignObjectHttpResult, ISignObjectsHttpOptions, ISignObjectsHttpResult, ISignUploadObjectHttpOptions, ISignUploadObjectHttpResult, IUploadObjectBySignHttpOptions, IUploadObjectBySignHttpResult, IDownloadAuthenticatedObjectHttpOptions, IDownloadObjectHttpOptions, IDownloadPublicObjectHttpOptions, IDownloadObjectBySignHttpOptions, IDownloadObjectHttpResult, IGetObjectInfoAuthenticatedHttpOptions, IGetObjectInfoPublicHttpOptions, IGetObjectInfoHttpResult, IConsistentUploadOptions, IConsistentUploadResult, ILocalManifestItem, IManifestDiffResult, IManifestVerifyResult, IPruneResult, IRemoteManifestItem } from './type'; export interface IProgressData { loaded: number; total: number; speed: number; percent: number; } export interface IOptions { onProgress?: OnProgress; onFileFinish?: OnFileFinish; ignore?: string | string[]; fileId?: boolean; parallel?: number; } export interface IFileOptions extends IOptions { localPath: string; cloudPath?: string; entryFiles?: string[]; parallel?: number; retryCount?: number; retryInterval?: number; } export interface IFilesOptions extends IOptions { ignore?: string | string[]; files: { localPath: string; cloudPath?: string; }[]; retryCount?: number; retryInterval?: number; } export interface ICustomOptions { bucket: string; region: string; /** * 共享桶(ExternalStorage)内的目录前缀。*Custom 方法不会自动读取环境的 BasePath, * 未传时按 COS 原始 Key 处理;传入后入参按逻辑路径处理,返回的 Key 映射回逻辑路径 */ basePath?: string; } export interface IWalkCloudDirOptions { prefix: string; bucket: string; region: string; marker?: string; /** 同 ICustomOptions.basePath */ basePath?: string; } export interface IGetRemoteManifestOptions extends ICustomOptions { /** 云端前缀,无前导斜杠(如 'dist');空串表示整桶 */ prefix: string; /** 列举起始 Marker;默认 '/' 会排除 . 开头的 Key,列举备份目录时需传 '' */ marker?: string; } /** 一致性发布:远端备份选项 */ export interface IBackupRemoteOptions extends IGetRemoteManifestOptions { /** 备份目标前缀,须以 .cloudbase-backup/ 开头,如 .cloudbase-backup/1724073600000/ */ backupPrefix: string; /** 复制并发数,默认 20 */ parallel?: number; } /** 一致性发布:从备份恢复选项 */ export interface IRestoreFromBackupOptions extends ICustomOptions { /** 备份前缀,与 backupRemote 所传一致 */ backupPrefix: string; /** 待恢复的覆盖文件 Key(相对桶根),来自 diffManifest().overwritten */ overwrittenKeys: string[]; /** 待删除的新增文件 Key(相对桶根),来自 diffManifest().added */ addedKeys: string[]; /** 恢复复制并发数,默认 20 */ parallel?: number; } /** 一致性发布:清理备份选项 */ export interface ICleanupBackupOptions extends ICustomOptions { /** 需要清理的备份前缀,与 backupRemote 所传一致 */ backupPrefix: string; } /** 一致性发布:远端冗余文件清理选项 */ export interface IPruneRemoteOptions extends ICustomOptions { /** 限定清理范围的前缀,无前导斜杠;空串表示根目录 */ prefix: string; /** 待删除 Key(相对桶根),来自 diffManifest().removed;越界与备份 Key 会被自动过滤 */ removedKeys: string[]; /** 删除并发数,默认 20 */ parallel?: number; } export interface IRoutingRules { keyPrefixEquals?: string; httpErrorCodeReturnedEquals?: string; replaceKeyWith?: string; replaceKeyPrefixWith?: string; } export interface IBucketWebsiteOptions { indexDocument: string; errorDocument?: string; /** 错误文档是否保留原始 HTTP 状态码:Enabled / Disabled(SPA 回退需 Disabled,否则 404 状态码使前端路由失效) */ originalHttpStatus?: string; /** 404 是否展示腾讯云公益页面:Enabled / Disabled(SPA 回退需 Disabled,否则覆盖错误文档) */ charity404?: string; /** 忽略 HTML 扩展名:Enabled / Disabled(未传则保持默认 Disabled) */ autoAddressing?: string; routingRules?: Array; region: string; bucket: string; } export interface IGetBucketOpions { bucket?: string; region?: string; prefix?: string; marker?: string; maxKeys?: number; /** 同 ICustomOptions.basePath:传入后 prefix / marker 按逻辑路径处理,返回的 Contents.Key、NextMarker 映射回逻辑路径 */ basePath?: string; } export type AclType = 'READONLY' | 'PRIVATE' | 'ADMINWRITE' | 'ADMINONLY' | 'CUSTOM'; export interface IStorageAclRule { /** 读权限规则,true 表示所有用户可读,字符串表示自定义规则表达式 */ read: boolean | string; /** 写权限规则,true 表示所有用户可写,字符串表示自定义规则表达式 */ write: boolean | string; } /** 复制文件选项 */ export interface ICopyOptions { /** 源路径(云端路径,如 images/a.jpg) */ sourcePath: string; /** 目标路径(云端路径,如 backup/a.jpg) */ destPath: string; /** 是否强制覆盖已存在的文件 */ force?: boolean; /** 是否跳过已存在的文件 */ skipExisting?: boolean; } /** 复制目录选项 */ export interface ICopyDirectoryOptions extends ICopyOptions { /** 包含模式(glob 格式) */ include?: string | string[]; /** 排除模式(glob 格式) */ exclude?: string | string[]; /** 并发数,默认 20 */ parallel?: number; /** 进度回调 */ onProgress?: (info: ICopyProgress) => void; } /** 复制进度信息 */ export interface ICopyProgress { /** 已复制数量 */ copied: number; /** 已跳过数量 */ skipped: number; /** 总数量 */ total: number; /** 当前正在处理的文件 */ currentFile: string; } /** 复制结果状态 */ export type CopyStatus = 'copied' | 'skipped' | 'failed'; /** 复制结果 */ export interface ICopyResult { /** 是否成功 */ success: boolean; /** 源路径 */ sourcePath: string; /** 目标路径 */ destPath: string; /** 文件大小 (bytes) */ size?: number; /** 复制状态 */ status: CopyStatus; /** 失败时的错误信息 */ error?: string; } /** 搜索文件选项 */ export interface ISearchOptions { /** 搜索模式(glob 或正则表达式) */ pattern: string; /** 搜索目录路径(不指定则搜索根目录) */ path?: string; /** 是否为正则表达式 */ isRegex?: boolean; /** 文件类型过滤(如 jpg, png) */ fileType?: string; /** 限制数量,默认 100 */ limit?: number; /** 是否包含详细信息 */ includeDetails?: boolean; } /** 搜索结果 */ export interface ISearchResult { /** 文件路径(云端路径) */ key: string; /** 类型:file 或 directory */ type: 'file' | 'directory'; /** 文件大小 (bytes),仅文件有效 */ size?: number; /** 最后修改时间 (ISO 格式),仅文件有效 */ lastModified?: string; } type OnProgress = (progressData: IProgressData) => void; type OnFileFinish = (error: Error, res: any, fileData: any) => void; export { md5File } from './helper'; export interface IBatchDeleteFailure { fileId: string; cloudPath: string | undefined; code: string; } /** * 整理 storage.batchDeleteFile 的逐文件删除结果,取出失败项并回填对应的 cloudPath * * 该接口逐文件返回 code,未失败的文件已经删除成功。把结果汇总成一条错误消息会丢掉逐项信息, * 调用方无法区分「删掉了哪些」和「哪些本来就不存在」,因此保留结构化失败列表。 * 接口未保证 delete_list 与入参同序,这里按 fileID 反查。 */ export declare function collectBatchDeleteFailures(deleteList: { fileID: string; code: string; }[], fileIdList: string[], cloudPathList: string[]): IBatchDeleteFailure[]; export declare class StorageService { private environment; private tcbService; constructor(environment: Environment); /** * 获取远端 manifest(默认 Storage 桶):返回指定前缀下文件的 key / etag / size, * 过滤目录占位对象。prefix 无前导斜杠,空串表示整桶(Hosting 桶请用 getRemoteManifestCustom)。 */ getRemoteManifest(prefix: string): Promise; /** * 获取远端 manifest,支持自定义 Bucket 和 Region。prefix 规则同 getRemoteManifest。 * 不会自动拼接环境的共享桶 BasePath,需要时显式传入 basePath */ getRemoteManifestCustom(options: IGetRemoteManifestOptions): Promise; /** * 生成本地 manifest:计算每个文件的云端 Key、MD5 与 Size。 * - filePaths 须来自 walkLocalDir(localPath),目录不计入 * - key = cloudPath + 文件相对路径;cloudPath 为空表示桶根 * - MD5 以受控并发计算,避免阻塞事件循环 */ buildLocalManifest(options: { localPath: string; cloudPath?: string; filePaths: string[]; parallel?: number; }): Promise; /** * 计算本地 manifest 与远端 manifest 的差异: * - added:本地有、远端无;overwritten:两边都有;removed:远端有、本地无 * - 两份 manifest 的 key 须基于同一 cloudPath(removed 自动排除 .cloudbase-backup/) */ diffManifest(localManifest: ILocalManifestItem[], remoteManifest: IRemoteManifestItem[]): IManifestDiffResult; /** * 校验远端 manifest 与本地 manifest 是否一致: * - 远端缺失 → missing;ETag 为纯 MD5 → 按 md5 比对;分块上传 ETag → 降级按 size 比对 */ verifyManifest(localManifest: ILocalManifestItem[], remoteManifest: IRemoteManifestItem[]): IManifestVerifyResult; /** * 将指定前缀下的远端文件服务端复制到备份前缀(不产生下载流量)。 * 始终跳过 .cloudbase-backup/ 下的历史备份,避免根目录发布时递归备份。 */ backupRemote(options: IBackupRemoteOptions): Promise; /** * 从备份恢复被覆盖旧文件(服务端复制回原 Key),并删除本次新增文件。 * 任一阶段失败都会抛错,由上层决定是否保留备份供人工恢复。 */ restoreFromBackup(options: IRestoreFromBackupOptions): Promise; /** * 删除备份前缀下的全部对象。 * 备份目录以 . 开头,内部使用空 Marker 列举,不受默认排除规则影响。 */ cleanupBackup(options: ICleanupBackupOptions): Promise; /** * 清理发布后远端残留的冗余文件。 * 仅删除 removedKeys 中位于 prefix 范围内的 Key,排除 .cloudbase-backup/; * 单个删除失败记入 failedKeys,不影响其他文件。 */ pruneRemote(options: IPruneRemoteOptions): Promise; /** * 一致性目录上传编排(safe、verify、prune) * * 执行流程(按顺序): * 1. 扫描本地目录,生成 manifest(key/md5/size) * 2. safe 或 prune 开启时:拉取远端快照 manifest,与本地做 diff * (safe 用 diff 判定回滚范围;prune 用 diff.removed 判定待清理文件) * 3. safe 开启时:将远端文件服务端复制到备份前缀 .cloudbase-backup/<时间戳>/ * 4. 执行目录上传(资源文件先传,入口文件 entries 最后传) * 5. verify 开启时:重新拉取远端 manifest,逐文件校验 ETag/MD5 与 size * 6. 上传与校验全部成功后,prune 开启时:删除 diff.removed 中仍冗余的远端文件 * 7. 返回 uploadedKeys / verified / backupPrefix / prune 结果 * * 失败时的行为: * - 步骤 4/5 失败且 safe 开启:自动从备份回滚(恢复被覆盖文件、删除本次新增 * 文件),回滚成功后抛出“已自动回滚”错误,备份保留供人工核查 * - 回滚失败:保留备份并在错误信息中给出备份位置,供人工恢复 * - 备份一律不由本编排自动清理,均需调用方确认后通过 cleanupBackup 显式删除 * - prune 仅在步骤 4/5 全部成功后执行,失败发布绝不会触发远端删除 * * ⚠️ 危险参数:prune * prune 会删除云端 cloudPath 前缀下、本次本地构建中不存在的全部文件。 * 若调用方误传了错误的 localPath/cloudPath,整目录都会被判定为“冗余”而删除。 * 发布成功后备份默认保留、不自动清理:prune 误删的文件可从备份前缀 * (.cloudbase-backup/<时间戳>/)人工恢复;调用方确认无误后应通过 * cleanupBackup 显式清理备份。调用方(CLI)仍须在开启 prune 前要求用户二次确认。 */ uploadDirectoryConsistent(options: IConsistentUploadOptions): Promise; /** * 上传文件 * localPath 为文件夹时,会尝试在文件夹中寻找 cloudPath 中的文件名 * @param {string} localPath 本地文件的绝对路径 * @param {string} cloudPath 云端文件路径,如 img/test.png * @returns {Promise} */ uploadFile(options: IFileOptions): Promise; /** * 批量上传文件,默认并发 5 * @param options */ uploadFiles(options: IFilesOptions): Promise; /** * 上传文件,支持自定义 Bucket 和 Region * 不会自动拼接环境的共享桶 BasePath,需要时显式传入 basePath;fileId 始终按逻辑路径 cloudPath 获取 * @param {string} localPath * @param {string} cloudPath * @param {string} bucket * @param {string} region */ uploadFileCustom(options: IFileOptions & ICustomOptions): Promise; /** * 上传文件夹 * @param {string} localPath 本地文件夹路径 * @param {string} cloudPath 云端文件夹 * @param {number} parallel 并发量 * @param {number} retryCount 重试次数 * @param {number} retryInterval 重试时间间隔(毫秒) * @param {(string | string[])} ignore * @param {(string | string[])} ignore * @returns {Promise} */ uploadDirectory(options: IFileOptions): Promise; /** * 上传文件夹,支持自定义 Region 和 Bucket * 不会自动拼接环境的共享桶 BasePath,需要时显式传入 basePath * @param {string} localPath * @param {string} cloudPath * @param {number} parallel * @param {number} retryCount * @param {number} retryInterval * @param {string} bucket * @param {string} region * @param {IOptions} options * @returns {Promise} */ uploadDirectoryCustom(options: IFileOptions & ICustomOptions): Promise; uploadFilesCustom(options: IFilesOptions & ICustomOptions): Promise; /** * 串行安全模式:逐文件上传(类似自定义脚本 deploy.js 的方式) * 特点: * - 每个文件独立 HTTP 连接,不会出现 socket hang up * - 单线程串行,稳定性最高 * - 适合大规模目录(>1000 文件)或有网络问题的场景 */ private uploadFilesSerial; /** * 并发模式:使用 cos.uploadFiles() 批量上传 * 特点: * - 速度快,利用 SDK 内部并行能力 * - 分批上传 + 自动刷新凭证 * - 适合小规模目录或网络良好的场景 * * @returns 失败的文件列表(空的表示全部成功) */ private uploadFilesParallel; /** * 创建一个空的文件夹 * @param {string} cloudPath */ createCloudDirectroy(cloudPath: string): Promise; /** * 创建一个空的文件夹,支持自定义 Region 和 Bucket * 不会自动拼接环境的共享桶 BasePath,需要时显式传入 basePath * @param {string} cloudPath * @param {string} bucket * @param {string} region */ createCloudDirectroyCustom(options: ICustomOptions & { cloudPath: string; }): Promise; /** * 下载文件 * @param {string} cloudPath 云端文件路径 * @param {string} localPath 文件本地存储路径,文件需指定文件名称 * @returns {Promise} */ downloadFile(options: { cloudPath: string; localPath?: string; }): Promise; /** * 下载文件夹 * @param {string} cloudPath 云端文件路径 * @param {string} localPath 本地文件夹存储路径 * @returns {Promise<(NodeJS.ReadableStream | string)[]>} */ downloadDirectory(options: { cloudPath: string; localPath?: string; parallel?: number; }): Promise<(NodeJS.ReadableStream | string)[]>; /** * 列出文件夹下的文件 * @link https://cloud.tencent.com/document/product/436/7734 * @param {string} cloudPath 云端文件夹,如果为空字符串,则表示根目录 * @returns {Promise} */ listDirectoryFiles(cloudPath: string): Promise; /** * 获取文件临时下载链接 * @param {((string | ITempUrlInfo)[])} fileList 文件路径或文件信息数组 * @returns {Promise<{ fileId: string; url: string }[]>} */ getTemporaryUrl(fileList: (string | ITempUrlInfo)[]): Promise<{ fileId: string; url: string; }[]>; /** * 删除文件 * @param {string[]} cloudPathList 云端文件路径数组 * @returns {Promise} */ deleteFile(cloudPathList: string[]): Promise; /** * 删除文件,可以指定 Bucket 和 Region * 不会自动拼接环境的共享桶 BasePath,cloudPathList 按 COS 原始 Key 处理 * @param {string[]} cloudPathList * @param {string} bucket * @param {string} region * @returns {Promise} */ deleteFileCustom(cloudPathList: string[], bucket: string, region: string): Promise; /** * 获取文件信息 * @param {string} cloudPath 云端文件路径 * @returns {Promise} */ getFileInfo(cloudPath: string): Promise; /** * 删除文件夹 * @param {string} cloudPath 云端文件夹路径 * @returns {Promise} */ deleteDirectory(cloudPath: string): Promise<{ Deleted: { Key: string; }[]; Error: Object[]; }>; /** * 删除文件,可以指定 bucket 和 region * 不会自动拼接环境的共享桶 BasePath,需要时显式传入 basePath;返回的 Key 为逻辑路径 * @param {string} cloudPath * @param {string} bucket * @param {string} region * @returns {Promise} */ deleteDirectoryCustom(options: { cloudPath: string; /** 列举起始 Marker,默认 '/' 会排除 . 开头的 Key;清理备份目录时需传 '' */ marker?: string; } & ICustomOptions): Promise<{ Deleted: { Key: string; }[]; Error: Object[]; }>; /** * 获取文件存储权限 * READONLY:所有用户可读,仅创建者和管理员可写 * PRIVATE:仅创建者及管理员可读写 * ADMINWRITE:所有用户可读,仅管理员可写 * ADMINONLY:仅管理员可读写 * CUSTOM:自定义安全规则 * * @param options.withRule 是否返回自定义安全规则,默认 false 以保持向后兼容 * @returns 不传参数时返回 AclType(向后兼容),传入 { withRule: true } 时返回 { acl: AclType, rule?: IStorageAclRule } * * @example * // 向后兼容的简单用法(返回 AclType) * const acl = await storage.getStorageAcl() * if (acl === 'READONLY') { ... } * * // 获取自定义安全规则(返回对象) * const result = await storage.getStorageAcl({ withRule: true }) * console.log(result.acl, result.rule) */ getStorageAcl(): Promise; getStorageAcl(options: { withRule: true; }): Promise<{ acl: AclType; rule?: IStorageAclRule; }>; /** * 设置文件存储权限 * READONLY:所有用户可读,仅创建者和管理员可写 * PRIVATE:仅创建者及管理员可读写 * ADMINWRITE:所有用户可读,仅管理员可写 * ADMINONLY:仅管理员可读写 * CUSTOM:自定义安全规则(需要传入 rule 参数) * @param {AclType} acl 权限类型 * @param {IStorageAclRule} [rule] 自定义安全规则,当 acl 为 CUSTOM 时必填 * @returns * @example * // 设置简易权限 * await storage.setStorageAcl('READONLY') * * // 设置自定义安全规则 * await storage.setStorageAcl('CUSTOM', { * read: true, * write: 'resource.openid == auth.uid' * }) */ setStorageAcl(acl: AclType, rule?: IStorageAclRule): Promise; /** * 遍历云端文件夹 * @param {string} prefix * @param {string} [marker] 路径开始标志 * @returns {Promise} */ walkCloudDir(prefix: string, marker?: string): Promise; /** * 遍历云端文件夹,支持自定义 Bucket 和 Region * 不会自动拼接环境的共享桶 BasePath,需要时显式传入 basePath;传入后返回的 Key 为逻辑路径 * @param {string} prefix * @param {string} [marker] * @param {string} bucket * @param {string} region * @returns {Promise} */ walkCloudDirCustom(options: IWalkCloudDirOptions): Promise; /** * 列出指定目录下的文件和子目录(不递归,只列当前层) * 使用 COS Delimiter 参数实现 * @param {string} dirPath 目录路径,空字符串表示根目录 * @returns {Promise<{ files: IListFileInfo[], directories: string[] }>} */ listCurrentDirectory(dirPath?: string): Promise<{ files: IListFileInfo[]; directories: string[]; }>; /** * 遍历本地文件夹 * 忽略不包含 dir 路径,即如果 ignore 匹配 dir,dir 也不会被忽略 * @private * @param {string} dir * @param {(string | string[])} [ignore] * @returns */ walkLocalDir(dir: string, ignore?: string | string[]): Promise; /** * 获取文件上传链接属性 */ getUploadMetadata(path: string): Promise; /** * 获取静态网站配置 */ getWebsiteConfig(options: { bucket: string; region: string; }): Promise; /** * 配置文档 */ putBucketWebsite(options: IBucketWebsiteOptions): Promise; /** * 查询object列表 * @param {IGetBucketOpions} options * @memberof StorageService */ getBucket(options: IGetBucketOpions): Promise; /** * 复制单个文件 * @param options.sourcePath 源文件路径(云端路径,如 images/a.jpg) * @param options.destPath 目标文件路径(云端路径,如 backup/a.jpg) * @param options.force 是否强制覆盖 * @param options.skipExisting 是否跳过已存在的文件 * @returns 复制结果 */ copyFile(options: ICopyOptions): Promise; /** * 复制目录 * 遍历源目录下的所有文件,并行复制到目标目录 * @param options.sourcePath 源目录路径 * @param options.destPath 目标目录路径 * @param options.include 包含模式(glob 格式) * @param options.exclude 排除模式(glob 格式) * @param options.force 是否强制覆盖 * @param options.skipExisting 是否跳过已存在的文件 * @param options.parallel 并发数,默认 20 * @param options.onProgress 进度回调 * @returns 复制结果数组 */ copyDirectory(options: ICopyDirectoryOptions): Promise; /** * 移动文件(复制后删除源文件) * 注意:移动操作是「复制 + 删除」的两步操作,如果删除失败,文件会同时存在于源和目标位置 * @param options 与 copyFile 相同的选项 * @returns 移动结果,如果删除源文件失败会在 error 字段说明 */ moveFile(options: ICopyOptions): Promise; /** * 移动目录(复制后删除源目录) * 注意:移动操作是「复制 + 删除」的两步操作,如果部分删除失败,文件会同时存在于源和目标位置 * @param options 与 copyDirectory 相同的选项 * @returns 移动结果数组,删除失败的文件会在对应结果的 error 字段说明 */ moveDirectory(options: ICopyDirectoryOptions): Promise; /** * 搜索文件和目录(只搜索当前目录,不递归) * @param options.pattern 搜索模式(支持 glob 或正则表达式) * @param options.path 搜索目录路径(不指定则搜索根目录) * @param options.isRegex 是否为正则表达式模式 * @param options.fileType 文件类型过滤 * @param options.limit 限制返回数量,默认 100 * @param options.includeDetails 是否包含详细信息(大小、修改时间) * @returns 搜索结果数组(包含文件和目录) */ searchFiles(options: ISearchOptions): Promise; /** * 通过 CloudBase HTTP API 上传对象(Binary 直传) * POST/PUT /v1/storages/object/:bucketId/*objectName */ uploadObject(options: IUploadObjectHttpOptions): Promise; /** * 通过 CloudBase HTTP API 删除单个对象 * DELETE /v1/storages/object/:bucketId/*objectName */ deleteObject(options: IDeleteObjectHttpOptions): Promise; /** * 通过 CloudBase HTTP API 批量删除对象(单次最多 20 个) * DELETE /v1/storages/object/:bucketId */ deleteObjects(options: IDeleteObjectsHttpOptions): Promise; /** * 通过 CloudBase HTTP API 复制对象 * POST /v1/storages/object/copy */ copyObject(options: ICopyObjectHttpOptions): Promise; /** * 通过 CloudBase HTTP API 移动对象(复制后删除源对象,由服务端一次性完成) * POST /v1/storages/object/move */ moveObject(options: IMoveObjectHttpOptions): Promise; /** * 通过 CloudBase HTTP API 列出对象 * POST /v1/storages/object/list/:bucketId */ listObjects(options: IListObjectsHttpOptions): Promise; /** * 通过 CloudBase HTTP API 生成签名下载 URL * POST /v1/storages/object/sign/:bucketId/*objectName */ signObject(options: ISignObjectHttpOptions): Promise; /** * 通过 CloudBase HTTP API 批量生成签名下载 URL * POST /v1/storages/object/sign/:bucketId */ signObjects(options: ISignObjectsHttpOptions): Promise; /** * 通过 CloudBase HTTP API 生成签名上传 URL * POST /v1/storages/object/upload/sign/:bucketId/*objectName */ signUploadObject(options: ISignUploadObjectHttpOptions): Promise; /** * 通过 CloudBase HTTP API 使用签名 URL 上传对象(无需 Authorization) * PUT /v1/storages/object/upload/sign/:bucketId/*objectName?token=xxx */ uploadObjectBySign(options: IUploadObjectBySignHttpOptions): Promise; /** * 通过 CloudBase HTTP API 下载对象(需认证) * GET/HEAD /v1/storages/object/authenticated/:bucketId/*objectName */ downloadAuthenticatedObject(options: IDownloadAuthenticatedObjectHttpOptions): Promise; /** * 通过 CloudBase HTTP API 下载对象(可选认证) * GET/HEAD /v1/storages/object/:bucketId/*objectName */ downloadObject(options: IDownloadObjectHttpOptions): Promise; /** * 通过 CloudBase HTTP API 下载公开对象(无需认证) * GET/HEAD /v1/storages/object/public/:bucketId/*objectName */ downloadPublicObject(options: IDownloadPublicObjectHttpOptions): Promise; /** * 通过 CloudBase HTTP API 使用签名 URL 下载对象(无需 Authorization) * GET/HEAD /v1/storages/object/sign/:bucketId/*objectName?token=xxx */ downloadObjectBySign(options: IDownloadObjectBySignHttpOptions): Promise; /** * 通过 CloudBase HTTP API 获取对象元信息(需认证) * GET/HEAD /v1/storages/object/info/authenticated/:bucketId/*objectName */ getObjectInfoAuthenticated(options: IGetObjectInfoAuthenticatedHttpOptions): Promise; /** * 通过 CloudBase HTTP API 获取公开对象元信息(无需认证) * GET /v1/storages/object/info/public/:bucketId/*objectName */ getObjectInfoPublic(options: IGetObjectInfoPublicHttpOptions): Promise; /** * 获取 COS 配置 * @param parallel 并发数量 */ private getCos; /** * 将 cloudPath 转换成 cloudPath/ 形式 */ private getCloudKey; /** * 将 cloudPath 转换成 fileId */ private cloudPathToFileId; /** * 获取存储桶配置,兼容共享桶(ExternalStorage)环境 * basePath 为共享桶内的目录前缀,普通环境为空串 */ getStorageConfig(): IStorageConfig; /** * 带重试功能的上传多文件函数 * @param uploadFiles sdk上传函数 * @param options sdk上传函数参数 * @param times 重试次数 * @param interval 重试时间间隔(毫秒) * @param failedFiles 失败文件列表 * @returns */ private uploadFilesWithRetry; /** * 拼接路径下载单文件 * @param file * @param cloudDirectoryKey * @param resolveLocalPath * @returns */ private downloadWithFilePath; /** * 根据下载结果返回错误列表 * @param res * @returns */ private determineDownLoadResultIsError; private resolveUploadContentType; private inferMimeByExtension; private inferMimeByMagicBytes; private assertValidContentType; }