import { IUploaderOptions } from './types'; /** * 文件上传管理器 * 单例模式,管理文件上传的 hash 码和上传请求 * @example * ```ts * // 设置上传配置 * UploadManager.setConfig({ * requestHashUrl: 'https://example.com/api/hash', * uploadFileKey: 'file', * uploadUrlPrefix: 'https://example.com/upload?hash=' * }); * * // 获取实例并上传文件 * const manager = UploadManager.getInstance(); * manager.requestUpload(file).then(res => { * console.log('上传成功:', res.url); * }); * ``` */ export declare class UploadManager { static uploadManager: UploadManager; /** * 获取 UploadManager 单例实例 * @returns UploadManager 实例 */ static getInstance(): UploadManager; /** * 设置上传配置 * @param options - 上传配置选项 * @param options.requestHashUrl - 请求 hash 码的 URL 或函数 * @param options.uploadFileKey - 上传文件的表单字段名 * @param options.uploadUrlPrefix - 上传文件的 URL 前缀 */ static setConfig(options: IUploaderOptions): void; hash: string; timestamp: number; isRequesting: boolean; options: IUploaderOptions; constructor(); /** * 更新 hash 码 * 从服务器获取新的 hash 码用于文件上传 * @returns Promise,resolve 时返回新的 hash 码 */ updateHashCode(): Promise; /** * 请求上传文件 * 自动管理 hash 码的更新,确保 hash 码有效 * @param file - 要上传的文件对象 * @returns Promise,resolve 时返回包含文件 URL 的对象 */ requestUpload(file: File): Promise<{ url: string; }>; } /** * 上传文件 * * 上传的本质: * * 1. 小程序上传文件是先用 chooseFile 获取一个文件,可以得到 * 一个临时路径,然后用 uploadFile 上传该临时路径 * * 2. H5 是 input 获取文件,然后用 FormData 上传 File 对象 * @param {File} file 文件 * @returns {Promise<{url: string}>} 上传结果 * * @example * ```ts * import { uploadFile, UploadManager } from 't-comm/lib/uploader' * * uploadFile(file).then(() => {}) * * // 可以通过 UploadManager 设置上传参数 * UploadManager.setConfig({ * requestHashUrl: `https://${location.hostname}/pvp/share/getsharecfg.php`, * uploadFileKey: 'upload_pic_input', * uploadUrlPrefix: 'https://igame.qq.com/external/uploadpic.php?_hash=', * }) * * // 可以通过 UploadManager.getInstance().updateHashCode 主动更新 hashCode * UploadManager.getInstance().updateHashCode(); * ``` */ export declare function uploadFile(file: File): Promise;