From caf809eaccd6a3da289d74271900ce11084829a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miss=E6=B7=B1=E6=B5=B7=E9=B1=BC?= Date: Sat, 26 Mar 2022 08:41:28 +0000 Subject: [PATCH] update api/@system.request.d.ts. Signed-off-by: miss-deep-sea-fish --- api/@system.request.d.ts | 870 +++++++++++++++++++++++++++++---------- 1 file changed, 658 insertions(+), 212 deletions(-) diff --git a/api/@system.request.d.ts b/api/@system.request.d.ts index 6054f120dc..d6d8b43ee2 100644 --- a/api/@system.request.d.ts +++ b/api/@system.request.d.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * 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 @@ -12,283 +12,729 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import { AsyncCallback } from './basic'; /** - * @syscap SystemCapability.Miscservices.Upload + * upload and download + * + * @import request from '@ohos.request'; + * @permission ohos.permission.INTERNET */ -export interface UploadResponse { - /** - * Status code returned by the server. - * @syscap SystemCapability.Miscservices.Upload - * @since 3 - */ - code: number; +declare namespace request { /** - * Content returned by the server. - * The value type is determined by the returned content. - * @syscap SystemCapability.Miscservices.Upload - * @since 3 + * Bit flag indicating download is allowed when using the cellular network. + * @syscap SystemCapability.MiscServices.Download + * @since 6 + * @permission ohos.permission.INTERNET */ - data: string; + const NETWORK_MOBILE: number; /** - * Headers returned by the server. - * @syscap SystemCapability.Miscservices.Upload - * @since 3 - */ - headers: Object; -} + * Bit flag indicating download is allowed when using the WLAN. + * @syscap SystemCapability.MiscServices.Download + * @since 6 + * @permission ohos.permission.INTERNET + */ + const NETWORK_WIFI: number; -/** - * @syscap SystemCapability.Miscservices.Download - */ -export interface DownloadResponse { /** - * Download token, which is used to obtain the download status. - * @syscap SystemCapability.Miscservices.Download - * @since 3 + * Indicates that the download cannot be resumed for some temporary errors. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @permission ohos.permission.INTERNET */ - token: string; -} + const ERROR_CANNOT_RESUME: number; -/** - * @syscap SystemCapability.Miscservices.Download - */ -export interface OnDownloadCompleteResponse { /** - * URI of the download file. - * @syscap SystemCapability.Miscservices.Download - * @since 3 + * Indicates that no storage device, such as an SD card, is found. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @permission ohos.permission.INTERNET */ - uri: string; -} + const ERROR_DEVICE_NOT_FOUND: number; -/** - * @syscap SystemCapability.Miscservices.Upload - */ -export interface RequestFile { /** - * File name in the header when multipart is used. - * @syscap SystemCapability.Miscservices.Upload - * @since 3 + * Indicates that files to be downloaded already exist, and that the download session cannot overwrite the existing files. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @permission ohos.permission.INTERNET */ - filename?: string; + const ERROR_FILE_ALREADY_EXISTS: number; /** - * Name of a form item when multipart is used. The default value is file. - * @syscap SystemCapability.Miscservices.Upload - * @since 3 + * Indicates that a file operation fails. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @permission ohos.permission.INTERNET */ - name?: string; + const ERROR_FILE_ERROR: number; /** - * Local storage directory of a file. - * @syscap SystemCapability.Miscservices.Upload - * @since 3 + * Indicates that the HTTP transmission fails. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @permission ohos.permission.INTERNET */ - uri: string; + const ERROR_HTTP_DATA_ERROR: number; /** - * Type of the file content. - * By default, the type is obtained based on the suffix of the file name or URI. - * @syscap SystemCapability.Miscservices.Upload - * @since 3 + * Indicates insufficient storage space. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @permission ohos.permission.INTERNET */ - type?: string; -} + const ERROR_INSUFFICIENT_SPACE: number; -/** - * @syscap SystemCapability.Miscservices.Upload - */ -export interface RequestData { /** - * Name of the form element. - * @syscap SystemCapability.Miscservices.Upload - * @since 3 + * Indicates an error caused by too many network redirections. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @permission ohos.permission.INTERNET */ - name: string; + const ERROR_TOO_MANY_REDIRECTS: number; /** - * Value of the form element. - * @syscap SystemCapability.Miscservices.Upload - * @since 3 + * Indicates an HTTP code that cannot be identified. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @permission ohos.permission.INTERNET */ - value: string; -} - -/** - * @syscap SystemCapability.Miscservices.Upload - */ -export interface UploadRequestOptions { - /** - * Resource URL. - * @syscap SystemCapability.Miscservices.Upload - * @since 3 - */ - url: string; - - /** - * Form data in the request body. - * @syscap SystemCapability.Miscservices.Upload - * @since 3 - */ - data?: Array; + const ERROR_UNHANDLED_HTTP_CODE: number; /** - * List of files to upload, which is submitted through multipart/form-data. - * @syscap SystemCapability.Miscservices.Upload - * @since 3 + * Indicates an undefined error. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @permission ohos.permission.INTERNET */ - files: Array; + const ERROR_UNKNOWN: number; /** - * Request header. - * @syscap SystemCapability.Miscservices.Upload - * @since 3 + * Indicates that the download is paused and waiting for a WLAN connection, because the file size exceeds the maximum allowed for a session using the cellular network. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @permission ohos.permission.INTERNET */ - header?: Object; + const PAUSED_QUEUED_FOR_WIFI: number; /** - * Request methods available: POST and PUT. The default value is POST. - * @syscap SystemCapability.Miscservices.Upload - * @since 3 + * Indicates that the download is paused for some reasons. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @permission ohos.permission.INTERNET */ - method?: string; + const PAUSED_UNKNOWN: number; /** - * Called when the files are uploaded successfully. - * @syscap SystemCapability.Miscservices.Upload - * @since 3 + * Indicates that the download is paused due to a network problem, for example, network disconnection. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @permission ohos.permission.INTERNET */ - success?: (data: UploadResponse) => void; + const PAUSED_WAITING_FOR_NETWORK: number; /** - * Called when uploading fails. - * @syscap SystemCapability.Miscservices.Upload - * @since 3 + * Indicates that a network error occurs, and the download session will be retried. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @permission ohos.permission.INTERNET */ - fail?: (data: any, code: number) => void; + const PAUSED_WAITING_TO_RETRY: number; /** - * Called when the execution is completed. - * @syscap SystemCapability.Miscservices.Upload - * @since 3 + * Indicates that the download session has failed and will not be retried. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @permission ohos.permission.INTERNET */ - complete?: () => void; -} + const SESSION_FAILED: number; -/** - * @syscap SystemCapability.Miscservices.Download - */ -export interface DownloadRequestOptions { /** - * Resource URL. - * @syscap SystemCapability.Miscservices.Download - * @since 3 + * Indicates that the download session has been paused. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @permission ohos.permission.INTERNET */ - url: string; + const SESSION_PAUSED: number; /** - * Name of the file to downloaded. - * The value is obtained from the current request or resource URL by default. - * @syscap SystemCapability.Miscservices.Download - * @since 3 + * Indicates that the download session is being scheduled. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @permission ohos.permission.INTERNET */ - filename?: string; + const SESSION_PENDING: number; /** - * Request header. - * @syscap SystemCapability.Miscservices.Download - * @since 3 + * Indicates that the download session is in progress. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @permission ohos.permission.INTERNET */ - header?: string; + const SESSION_RUNNING: number; /** - * Download description. - * The default value is the file name. - * @syscap SystemCapability.Miscservices.Download - * @since 3 + * Indicates that the download session is completed. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @permission ohos.permission.INTERNET */ - description?: string; + const SESSION_SUCCESSFUL: number; /** - * Called when the files are successfully downloaded. - * @syscap SystemCapability.Miscservices.Download - * @since 3 + * Starts a download session. + * @syscap SystemCapability.MiscServices.Download + * @since 6 + * @param config download config + * @param callback Indicate the callback function to receive DownloadTask. + * @permission ohos.permission.INTERNET + * @return - */ - success?: (data: DownloadResponse) => void; + function download(config: DownloadConfig, callback: AsyncCallback): void; /** - * Called when downloading fails. - * @syscap SystemCapability.Miscservices.Download - * @since 3 - */ - fail?: (data: any, code: number) => void; - - /** - * Called when the execution is completed. - * @syscap SystemCapability.Miscservices.Download - * @since 3 - */ - complete?: () => void; -} - -/** - * @syscap SystemCapability.Miscservices.Download - */ -export interface OnDownloadCompleteOptions { - /** - * Token of the result returned by the download function. - * @syscap SystemCapability.Miscservices.Download - * @since 3 - */ - token: string; - - /** - * Called when the downloads are successfully obtained - * @syscap SystemCapability.Miscservices.Download - * @since 3 - */ - success?: (data: OnDownloadCompleteResponse) => void; - - /** - * Called when the downloads fail to be obtained. - * @syscap SystemCapability.Miscservices.Download - * @since 3 - */ - fail?: (data: any, code: number) => void; - - /** - * Called when the execution is completed. - * @syscap SystemCapability.Miscservices.Download - * @since 3 - */ - complete?: () => void; + * Starts a download session. + * @syscap SystemCapability.MiscServices.Download + * @since 6 + * @param config download config + * @permission ohos.permission.INTERNET + * @return - + */ + function download(config: DownloadConfig): Promise; + + /** + * Starts a upload session. + * @syscap SystemCapability.MiscServices.Upload + * @since 6 + * @param config upload config + * @param callback Indicate the callback function to receive UploadTask. + * @permission ohos.permission.INTERNET + * @return - + */ + function upload(config: UploadConfig, callback: AsyncCallback): void; + + /** + * Starts a upload session. + * @syscap SystemCapability.MiscServices.Upload + * @since 6 + * @param config upload config + * @permission ohos.permission.INTERNET + * @return - + */ + function upload(config: UploadConfig): Promise; + + /** + * DownloadConfig data Structure + * + * @name DownloadConfig + * @since 6 + * @syscap SystemCapability.MiscServices.Download + * @permission ohos.permission.INTERNET + */ + interface DownloadConfig { + /** + * Resource address. + * + * @since 6 + * @permission ohos.permission.INTERNET + */ + url: string; + /** + * Adds an HTTP or HTTPS header to be included with the download request. + * + * @since 6 + * @permission ohos.permission.INTERNET + */ + header?: Object; + /** + * Allows download under a metered connection. + * + * @since 6 + * @permission ohos.permission.INTERNET + */ + enableMetered?: boolean; + /** + * Allows download in a roaming network. + * + * @since 6 + * @permission ohos.permission.INTERNET + */ + enableRoaming?: boolean; + /** + * Sets the description of a download session. + * + * @since 6 + * @permission ohos.permission.INTERNET + */ + description?: string; + /** + * Sets the network type allowed for download. + * + * @since 6 + * @permission ohos.permission.INTERNET + */ + networkType?: number; + /** + * Sets the path for downloads. + * + * @since 7 + * @permission ohos.permission.INTERNET + */ + filePath?: string; + /** + * Sets a download session title. + * + * @since 6 + * @permission ohos.permission.INTERNET + */ + title?: string; + } + + /** + * DownloadInfo data Structure + * + * @name DownloadInfo + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @permission ohos.permission.INTERNET + */ + interface DownloadInfo { + /** + * the description of a file to be downloaded. + * + * @since 7 + * @permission ohos.permission.INTERNET + */ + description: string; + /** + * the real-time downloads size (in bytes). + * + * @since 7 + * @permission ohos.permission.INTERNET + */ + downloadedBytes: number; + /** + * the ID of a file to be downloaded. + * + * @since 7 + * @permission ohos.permission.INTERNET + */ + downloadId: number; + /** + * a download failure cause, which can be any DownloadSession.ERROR_* constant. + * + * @since 7 + * @permission ohos.permission.INTERNET + */ + failedReason: number; + /** + * the name of a file to be downloaded. + * + * @since 7 + * @permission ohos.permission.INTERNET + */ + fileName: string; + /** + * the URI of a stored file. + * + * @since 7 + * @permission ohos.permission.INTERNET + */ + filePath: string; + /** + * the reason why a session is paused, which can be any DownloadSession.PAUSED_* constant. + * + * @since 7 + * @permission ohos.permission.INTERNET + */ + pausedReason: number; + /** + * the download status code, which can be any DownloadSession.SESSION_* constant. + * + * @since 7 + * @permission ohos.permission.INTERNET + */ + status: number; + /** + * the URI of files to be downloaded. + * + * @since 7 + * @permission ohos.permission.INTERNET + */ + targetURI: string; + /** + * the title of a file to be downloaded. + * + * @since 7 + * @permission ohos.permission.INTERNET + */ + downloadTitle: string; + /** + * the total size of files to be downloaded (in bytes). + * + * @since 7 + * @permission ohos.permission.INTERNET + */ + downloadTotalBytes: number; + } + + interface DownloadTask { + /** + * Called when the current download session is in process. + * @syscap SystemCapability.MiscServices.Download + * @since 6 + * @param type progress Indicates the download task progress. + * @param callback The callback function for the download progress change event + * receivedSize the length of downloaded data, in bytes + * totalSize he length of data expected to be downloaded, in bytes. + * @permission ohos.permission.INTERNET + * @return - + */ + on(type: 'progress', callback: (receivedSize: number, totalSize: number) => void): void; + + /** + * Called when the current download session is in process. + * @syscap SystemCapability.MiscServices.Download + * @since 6 + * @param type progress Indicates the download task progress. + * @param callback The callback function for the download progress change event + * receivedSize the length of downloaded data, in bytes + * totalSize he length of data expected to be downloaded, in bytes. + * @permission ohos.permission.INTERNET + * @return - + */ + off(type: 'progress', callback?: (receivedSize: number, totalSize: number) => void): void; + + /** + * Called when the current download session complete、pause or remove. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @param type Indicates the download session event type + * complete: download task completed, + * pause: download task stopped, + * remove: download task deleted. + * @param callback The callback function for the download complete、pause or remove change event. + * @permission ohos.permission.INTERNET + * @return - + */ + on(type: 'complete' | 'pause' | 'remove', callback: () => void): void; + + /** + * Called when the current download session complete、pause or remove. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @param type Indicates the download session event type + * complete: download task completed, + * pause: download task stopped, + * remove: download task deleted. + * @param callback The callback function for the download complete、pause or remove change event. + * @permission ohos.permission.INTERNET + * @return - + */ + off(type: 'complete' | 'pause' | 'remove', callback?: () => void): void; + + /** + * Called when the current download session fails. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @param type Indicates the download session type, fail: download task has failed. + * @param callback The callback function for the download fail change event + * err The error code for download task. + * @permission ohos.permission.INTERNET + * @return - + */ + on(type: 'fail', callback: (err: number) => void): void; + + /** + * Called when the current download session fails. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @param type Indicates the download session type, fail: download task has failed. + * @param callback Indicate the callback function to receive err. + * err The error code for download task. + * @permission ohos.permission.INTERNET + * @return - + */ + off(type: 'fail', callback?: (err: number) => void): void; + + /** + * Deletes a download session and the downloaded files. + * @syscap SystemCapability.MiscServices.Download + * @since 6 + * @param callback Indicates asynchronous invoking Result. + * @permission ohos.permission.INTERNET + * @return - + */ + remove(callback: AsyncCallback): void; + + /** + * Deletes a download session and the downloaded files. + * @syscap SystemCapability.MiscServices.Download + * @since 6 + * @permission ohos.permission.INTERNET + * @return - + */ + remove(): Promise; + + /** + * Pause a download session. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @param callback Indicates asynchronous invoking Result. + * @permission ohos.permission.INTERNET + * @return - + */ + pause(callback: AsyncCallback): void; + + /** + * Pause a download session. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @permission ohos.permission.INTERNET + * @return - + */ + pause(): Promise; + + /** + * Resume a paused download session. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @param callback Indicates asynchronous invoking Result. + * @permission ohos.permission.INTERNET + * @return - + */ + resume(callback: AsyncCallback): void; + + /** + * Resume a paused download session. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @permission ohos.permission.INTERNET + * @return - + */ + resume(): Promise; + + /** + * Queries download information of a session, which is defined in DownloadSession.DownloadInfo. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @param callback Indicate the callback function to receive download info. + * @permission ohos.permission.INTERNET + * @return - + */ + query(callback: AsyncCallback): void; + + /** + * Queries download information of a session, which is defined in DownloadSession.DownloadInfo. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @permission ohos.permission.INTERNET + * @return - + */ + query(): Promise; + + /** + * Queries the MIME type of the download file. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @param callback Indicate the callback function to receive download file MIME type. + * @permission ohos.permission.INTERNET + * @return - + */ + queryMimeType(callback: AsyncCallback): void; + + /** + * Queries the MIME type of the download file. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @permission ohos.permission.INTERNET + * @return - + */ + queryMimeType(): Promise; + } + + /** + * File data Structure + * + * @name File + * @since 6 + * @syscap SystemCapability.MiscServices.Download + * @permission ohos.permission.INTERNET + */ + interface File { + /** + * When multipart is submitted, the file name in the request header. + * + * @since 6 + * @permission ohos.permission.INTERNET + */ + filename: string; + /** + * When multipart is submitted, the name of the form item. The default is file. + * + * @since 6 + * @permission ohos.permission.INTERNET + */ + name: string; + /** + * The local storage path of the file (please refer to the storage directory definition for path usage). + * + * @since 6 + * @permission ohos.permission.INTERNET + */ + uri: string; + /** + * The content type of the file is obtained by default according to the suffix of the file name or path. + * + * @since 6 + * @permission ohos.permission.INTERNET + */ + type: string; + } + + /** + * RequestData data Structure + * + * @name RequestData + * @since 6 + * @syscap SystemCapability.MiscServices.Download + * @permission ohos.permission.INTERNET + */ + interface RequestData { + /** + * Represents the name of the form element. + * + * @since 6 + * @permission ohos.permission.INTERNET + */ + name: string; + /** + * Represents the value of the form element. + * + * @since 6 + * @permission ohos.permission.INTERNET + */ + value: string; + } + + /** + * UploadConfig data Structure + * + * @name UploadConfig + * @since 6 + * @syscap SystemCapability.MiscServices.Upload + * @permission ohos.permission.INTERNET + */ + interface UploadConfig { + /** + * Resource address. + * + * @since 6 + * @permission ohos.permission.INTERNET + */ + url: string; + /** + * Adds an HTTP or HTTPS header to be included with the upload request. + * + * @since 6 + * @permission ohos.permission.INTERNET + */ + header: Object; + /** + * Request method: POST, PUT. The default POST. + * + * @since 6 + * @permission ohos.permission.INTERNET + */ + method: string; + /** + * A list of files to be uploaded. Please use multipart/form-data to submit. + * + * @since 6 + * @permission ohos.permission.INTERNET + */ + files: Array; + /** + * The requested form data. + * + * @since 6 + * @permission ohos.permission.INTERNET + */ + data: Array; + } + + interface UploadTask { + /** + * Called when the current upload session is in process. + * @syscap SystemCapability.MiscServices.Upload + * @since 6 + * @param type progress Indicates the upload task progress. + * @param callback The callback function for the upload progress change event + * uploadedSize The length of uploaded data, in bytes + * totalSize The length of data expected to be uploaded, in bytes. + * @permission ohos.permission.INTERNET + * @return - + */ + on(type: 'progress', callback: (uploadedSize: number, totalSize: number) => void): void; + + /** + * Called when the current upload session is in process. + * @syscap SystemCapability.MiscServices.Upload + * @since 6 + * @param type progress Indicates the upload task progress. + * @param callback The callback function for the upload progress change event + * uploadedSize The length of uploaded data, in bytes + * totalSize The length of data expected to be uploaded, in bytes. + * @permission ohos.permission.INTERNET + * @return - + */ + off(type: 'progress', callback?: (uploadedSize: number, totalSize: number) => void): void; + + /** + * Called when the header of the current upload session has been received. + * @syscap SystemCapability.MiscServices.Upload + * @since 7 + * @param type headerReceive Indicates the upload task headed receive. + * @param callback The callback function for the HTTP Response Header event + * header HTTP Response Header returned by the developer server. + * @permission ohos.permission.INTERNET + * @return - + */ + on(type: 'headerReceive', callback: (header: object) => void): void; + + /** + * Called when the header of the current upload session has been received. + * @syscap SystemCapability.MiscServices.Upload + * @since 7 + * @param type headerReceive Indicates the upload task headed receive. + * @param callback The callback function for the HTTP Response Header event + * header HTTP Response Header returned by the developer server. + * @permission ohos.permission.INTERNET + * @return - + */ + off(type: 'headerReceive', callback?: (header: object) => void): void; + + /** + * Deletes a upload session. + * @syscap SystemCapability.MiscServices.Upload + * @since 6 + * @param callback Indicates asynchronous invoking Result. + * @permission ohos.permission.INTERNET + * @return - + */ + remove(callback: AsyncCallback): void; + + /** + * Deletes a upload session. + * @syscap SystemCapability.MiscServices.Upload + * @since 6 + * @permission ohos.permission.INTERNET + * @return - + */ + remove(): Promise; + } } -/** - * @devices tv, phone, tablet, wearable - */ -export default class Request { - /** - * Upload files. - * @param options Options. - * @syscap SystemCapability.Miscservices.Upload - */ - static upload(options: UploadRequestOptions): void; - - /** - * This API is used to download files. - * @param options Options. - * @syscap SystemCapability.Miscservices.Download - */ - static download(options: DownloadRequestOptions): void; - - /** - * Listens to download task status. - * @param options Options. - * @syscap SystemCapability.Miscservices.Download - */ - static onDownloadComplete(options: OnDownloadCompleteOptions): void; -} +export default request; + -- Gitee