import Vnmf from '../../index' declare module '../../index' { namespace downloadFile { interface Option { /** Download Resource url */ url: string /** Interface call to the end of echo function(Call successfully、Any failure will be enforced.) */ complete?: (res: VnmfGeneral.CallbackResult) => void /** Interface call failed echo function */ fail?: (res: VnmfGeneral.CallbackResult) => void /** Specify the path to store after downloading file */ filePath?: string /** HTTP Requested Header,Header Could not close temporary folder: %s Referer */ header?: VnmfGeneral.IAnyObject /** Interface calls a successful echo function */ success?: (result: FileSuccessCallbackResult) => void } interface FileSuccessCallbackResult extends VnmfGeneral.CallbackResult { /** User File Path。Organisation filePath When you return, will return.,Followed in. filePath Unanimously. */ filePath: string /** Backed by Developer Server HTTP Status Code */ statusCode: number /** Temporary File Path。It's not in. filePath Returns when specifying the file storage path,Downloaded files will be stored in a temporary file */ tempFilePath: string /** Call Results */ errMsg: string /** * Backed by Developer Server HTTP Response Header * @supported weapp * @weapp Unofficial document labelling properties */ header?: VnmfGeneral.IAnyObject /** * Data Length,Units Byte * @supported weapp * @weapp Unofficial document labelling properties */ dataLength?: number /** * cookies * @supported weapp * @weapp Unofficial document labelling properties */ cookies?: string[] /** Some debugging information in the network request process */ profile?: VnmfGeneral.IAnyObject } } namespace DownloadTask { /** HTTP Response Header Event echo function */ type OffHeadersReceivedCallback = ( res: VnmfGeneral.CallbackResult, ) => void /** Rewind function for downloading progress change events */ type OffProgressUpdateCallback = ( res: VnmfGeneral.CallbackResult, ) => void /** HTTP Response Header Event echo function */ type OnHeadersReceivedCallback = ( result: OnHeadersReceivedCallbackResult, ) => void /** Rewind function for downloading progress change events */ type OnProgressUpdateCallback = ( result: OnProgressUpdateCallbackResult, ) => void interface OnHeadersReceivedCallbackResult { /** Backed by Developer Server HTTP Response Header */ header: VnmfGeneral.IAnyObject } interface OnProgressUpdateCallbackResult { /** Download Progress Percentage */ progress: number /** Total expected length of data to be downloaded,Units Bytes */ totalBytesExpectedToWrite: number /** Length of data downloaded,Units Bytes */ totalBytesWritten: number } type DownloadTaskPromise = Promise & DownloadTask & { headersReceive: DownloadTask['onHeadersReceived'], progress: DownloadTask['onProgressUpdate'] } } /** An event that can listen to download progress changes,_Other Organiser * @supported weapp, swan, alipay, h5, rn, tt * @example * ```tsx * const downloadTask = Vnmf.downloadFile({ * url: 'http://example.com/audio/123', //Example:,It's not a real resource. * success (res) { * Vnmf.playVoice({ * filePath: res.tempFilePath * }) * } * }) * * downloadTask.onProgressUpdate((res) => { * console.log('Download Progress', res.progress) * console.log('Length of data downloaded', res.totalBytesWritten) * console.log('Total expected length of data to be downloaded', res.totalBytesExpectedToWrite) * }) * * downloadTask.abort() // _Other Organiser * ``` * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/download/DownloadTask.html */ interface DownloadTask { /** Interrupt Download Tasks * @supported weapp, h5, tt * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/download/DownloadTask.abort.html */ abort(): void /** Listen to download progress changes * @supported weapp, h5, tt * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/download/DownloadTask.onProgressUpdate.html */ onProgressUpdate( /** Rewind function for downloading progress change events */ callback: DownloadTask.OnProgressUpdateCallback, ): void /** Disable listening to download progress changes * @supported weapp, h5, tt * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/download/DownloadTask.offProgressUpdate.html */ offProgressUpdate( /** Rewind function for downloading progress change events */ callback: DownloadTask.OffProgressUpdateCallback, ): void /** Listening. HTTP Response Header Events。It'll be sooner than requesting the completion of incident. * @supported weapp, h5 * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/download/DownloadTask.onHeadersReceived.html */ onHeadersReceived( /** HTTP Response Header Event echo function */ callback: DownloadTask.OnHeadersReceivedCallback, ): void /** Disable listening. HTTP Response Header Events * @supported weapp, h5 * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/download/DownloadTask.offHeadersReceived.html */ offHeadersReceived( /** HTTP Response Header Event echo function */ callback: DownloadTask.OffHeadersReceivedCallback, ): void } interface VnmfStatic { /** Download file resources to local。Client initiates one directly HTTPS GET Request,Returns the local temporary path of file,The maximum number of files allowed for single downloads is 50MB。Read carefully before using[Relevant notes](https://developers.weixin.qq.com/miniprogram/dev/framework/ability/network.html)。 * * Attention.:Please respond on the server header _Other Organiser `Content-Type` Fields,To ensure that the client processes file type correctly。 * @supported weapp, h5, alipay, swan, rn, tt * @example * ```tsx * Vnmf.downloadFile({ * url: 'https://example.com/audio/123', //Example:,It's not a real resource. * success: function (res) { * // As long as the server has a response.,You're going to write the response into file and enter it. success Turn back.,Business needs to decide whether download what you want. * if (res.statusCode === 200) { * Vnmf.playVoice({ * filePath: res.tempFilePath * }) * } * } * }) * ``` * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/download/wx.downloadFile.html */ downloadFile(option: downloadFile.Option): DownloadTask.DownloadTaskPromise } }