• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2020 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16export interface UploadResponse {
17  /**
18   * Status code returned by the server.
19   * @since 3
20   */
21  code: number;
22
23  /**
24   * Content returned by the server. The value type is determined by the returned content.
25   * @since 3
26   */
27  data: string;
28
29  /**
30   * Headers returned by the server.
31   * @since 3
32   */
33  headers: Object;
34}
35
36export interface DownloadResponse {
37  /**
38   * Download token, which is used to obtain the download status.
39   * @since 3
40   */
41  token: string;
42}
43
44export interface OnDownloadCompleteResponse {
45  /**
46   * URI of the download file.
47   * @since 3
48   */
49  uri: string;
50}
51
52export interface RequestFile {
53  /**
54   * File name in the header when multipart is used.
55   * @since 3
56   */
57  filename?: string;
58
59  /**
60   * Name of a form item when multipart is used. The default value is file.
61   * @since 3
62   */
63  name?: string;
64
65  /**
66   * Local storage directory of a file.
67   * @since 3
68   */
69  uri: string;
70
71  /**
72   * Type of the file content. By default, the type is obtained based on the suffix of the filename or URI.
73   * @since 3
74   */
75  type?: string;
76}
77
78export interface RequestData {
79  /**
80   * Name of the form element.
81   * @since 3
82   */
83  name: string;
84
85  /**
86   * Value of the form element.
87   * @since 3
88   */
89  value: string;
90}
91
92export interface UploadRequestOptions {
93  /**
94   * Resource URL.
95   * @since 3
96   */
97  url: string;
98
99  /**
100   * Form data in the request body.
101   * @since 3
102   */
103  data?: Array<RequestData>;
104
105  /**
106   * List of files to upload, which is submitted through multipart/form-data.
107   * @since 3
108   */
109  files: Array<RequestFile>;
110
111  /**
112   * Request header.
113   * @since 3
114   */
115  header?: Object;
116
117  /**
118   * Request methods available: POST and PUT. The default value is POST.
119   * @since 3
120   */
121  method?: string;
122
123  /**
124   * Called when the files are uploaded successfully.
125   * @since 3
126   */
127  success?: (data: UploadResponse) => void;
128
129  /**
130   * Called when uploading fails.
131   * @since 3
132   */
133  fail?: (data: any, code: number) => void;
134
135  /**
136   * Called when the execution is completed.
137   * @since 3
138   */
139  complete?: () => void;
140}
141
142export interface DownloadRequestOptions {
143  /**
144   * Resource URL.
145   * @since 3
146   */
147  url: string;
148
149  /**
150   * Name of the file to downloaded.
151   * The value is obtained from the current request or resource URL by default.
152   * @since 3
153   */
154  filename?: string;
155
156  /**
157   * Request header.
158   * @since 3
159   */
160  header?: string;
161
162  /**
163   * Download description.
164   * The default value is the file name.
165   * @since 3
166   */
167  description?: string;
168
169  /**
170   * Called when the files are successfully downloaded.
171   * @since 3
172   */
173  success?: (data: DownloadResponse) => void;
174
175  /**
176   * Called when downloading fails.
177   * @since 3
178   */
179  fail?: (data: any, code: number) => void;
180
181  /**
182   * Called when the execution is completed.
183   * @since 3
184   */
185  complete?: () => void;
186}
187
188export interface OnDownloadCompleteOptions {
189  /**
190   * Token of the result returned by the download function.
191   * @since 3
192   */
193  token: string;
194
195  /**
196   * Called when the downloads are successfully obtained
197   * @since 3
198   */
199  success?: (data: OnDownloadCompleteResponse) => void;
200
201  /**
202   * Called when the downloads fail to be obtained.
203   * @since 3
204   */
205  fail?: (data: any, code: number) => void;
206
207  /**
208   * Called when the execution is completed.
209   * @since 3
210   */
211  complete?: () => void;
212}
213
214/**
215 * @Syscap SysCap.ACE.UIEngine
216 */
217export default class Request {
218  /**
219   * Upload files.
220   * @param options Options.
221   */
222  static upload(options: UploadRequestOptions): void;
223
224  /**
225   * This API is used to download files.
226   * @param options Options.
227   */
228  static download(options: DownloadRequestOptions): void;
229
230  /**
231   * Listens to download task status.
232   * @param options Options.
233   */
234  static onDownloadComplete(options: OnDownloadCompleteOptions): void;
235}
236
237