mirror of
https://github.com/openharmony/miscservices_request.git
synced 2026-07-19 19:43:46 -04:00
+14
-8
@@ -1,20 +1,28 @@
|
||||
# Request组件
|
||||
# 杂散子系统/Request服务
|
||||
|
||||
## 简介
|
||||
|
||||
### 内容介绍
|
||||
|
||||
Request组件向三方应用提供系统下载/上传服务能力,以支撑应用开发者方便、高效的使用以及管理下载/上传业务的功能,包含新建、移除、暂停、恢复以及查询下载/上传任务。
|
||||
|
||||
### 架构图介绍
|
||||
|
||||
**图 1** 下载子系统架构图
|
||||

|
||||
|
||||
**图 2** 上传子系统架构图
|
||||

|
||||
|
||||
#### 仓库路径
|
||||
|
||||
/base/miscservices/request
|
||||
|
||||
## 目录
|
||||
|
||||
```
|
||||
/base/miscservices/request
|
||||
├── figures # 构架图
|
||||
├── figures # 架构图
|
||||
├── download/ability # 下载服务数据库管理模块
|
||||
├── download/etc # 下载服务包含的进程配置文件
|
||||
├── interfaces/kits/js/napi # 本组件对外提供的下载服务接口代码
|
||||
@@ -31,7 +39,7 @@ Request组件向三方应用提供系统下载/上传服务能力,以支撑应
|
||||
|
||||
## 说明
|
||||
|
||||
### js接口说明
|
||||
### 接口说明
|
||||
|
||||
**表 1** Request组件的主要功能
|
||||
|
||||
@@ -465,11 +473,11 @@ internal://cache/path/to/file.txt</p>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
### js接口使用说明
|
||||
### 使用说明
|
||||
|
||||
```
|
||||
// 导入模块
|
||||
import request from '@ohos.requestability';
|
||||
import request from '@ohos.request';
|
||||
|
||||
// 1、下载服务接口使用说明
|
||||
let downloadConfig = {
|
||||
@@ -731,6 +739,4 @@ uploadTask.remove((err, result) => {
|
||||
|
||||
## 相关仓
|
||||
|
||||
1. **Misc软件服务子系统**
|
||||
|
||||
[miscservices_download](https://gitee.com/openharmony/miscservices_download/tree/master/)
|
||||
[miscservices_request](https://gitee.com/openharmony/miscservices_request/tree/master/)
|
||||
+186
-25
@@ -10,9 +10,9 @@
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
|
||||
// @ts-nocheck
|
||||
import request from '@ohos.requestability';
|
||||
import request from '@ohos.request';
|
||||
import {describe, expect, it} from 'deccjsunit/index.ets'
|
||||
|
||||
let DownloadConfig = {
|
||||
@@ -50,6 +50,136 @@ let DownloadConfig3 = {
|
||||
enableMetered: true,
|
||||
enableRoaming: true, // Allows download in a roaming network.
|
||||
}
|
||||
let DownloadConfig4 = {
|
||||
url: 'https://mirror.bjtu.edu.cn/kernel/linux/devel/binutils/autoconf-2.13-10.tar.gz',// Resource address.
|
||||
header: { }, // Adds an HTTP or HTTPS header to be included with the upload request.
|
||||
enableMetered: true,
|
||||
enableRoaming: true, // Allows download in a roaming network.
|
||||
description: 'a2', // Sets the description of a download session.
|
||||
networkType: 1, // Sets the network type allowed for download.
|
||||
filePath: '/system/lib/abc2.txt', // Sets the path for downloads.
|
||||
title: 'a2', // Sets a download session title.
|
||||
}
|
||||
let DownloadConfig5 = {
|
||||
url: 'https://mirror.bjtu.edu.cn/kernel/linux/devel/binutils/automake-1.4-8.3.tar.gz',// Resource address.
|
||||
header: { }, // Adds an HTTP or HTTPS header to be included with the upload request.
|
||||
enableMetered: true,
|
||||
enableRoaming: true, // Allows download in a roaming network.
|
||||
description: 'a2', // Sets the description of a download session.
|
||||
networkType: 1, // Sets the network type allowed for download.
|
||||
filePath: '/system/lib/abc2.txt', // Sets the path for downloads.
|
||||
title: 'a2', // Sets a download session title.
|
||||
}
|
||||
let DownloadConfig6 = {
|
||||
url: 'https://mirror.bjtu.edu.cn/kernel/linux/devel/binutils/binutils-2.10.91.0.2-2.10.91.0.4.diff.gz',// Resource address.
|
||||
header: { }, // Adds an HTTP or HTTPS header to be included with the upload request.
|
||||
enableMetered: true,
|
||||
enableRoaming: true, // Allows download in a roaming network.
|
||||
description: 'a2', // Sets the description of a download session.
|
||||
networkType: 1, // Sets the network type allowed for download.
|
||||
filePath: '/system/lib/abc2.txt', // Sets the path for downloads.
|
||||
title: 'a2', // Sets a download session title.
|
||||
}
|
||||
let DownloadConfig7 = {
|
||||
url: 'https://mirror.bjtu.edu.cn/kernel/linux/devel/binutils/binutils-2.11.90.0.23-2.11.90.0.24.sign',// Resource address.
|
||||
header: { }, // Adds an HTTP or HTTPS header to be included with the upload request.
|
||||
enableMetered: true,
|
||||
enableRoaming: true, // Allows download in a roaming network.
|
||||
description: 'a2', // Sets the description of a download session.
|
||||
networkType: 1, // Sets the network type allowed for download.
|
||||
filePath: '/system/lib/abc2.txt', // Sets the path for downloads.
|
||||
title: 'a2', // Sets a download session title.
|
||||
}
|
||||
let DownloadConfig8 = {
|
||||
url: 'https://mirror.bjtu.edu.cn/kernel/linux/devel/binutils/binutils-2.11.90.0.5-2.11.90.0.6.diff.gz',// Resource address.
|
||||
header: { }, // Adds an HTTP or HTTPS header to be included with the upload request.
|
||||
enableMetered: true,
|
||||
enableRoaming: true, // Allows download in a roaming network.
|
||||
description: 'a2', // Sets the description of a download session.
|
||||
networkType: 1, // Sets the network type allowed for download.
|
||||
filePath: '/system/lib/abc2.txt', // Sets the path for downloads.
|
||||
title: 'a2', // Sets a download session title.
|
||||
}
|
||||
let DownloadConfig9 = {
|
||||
url: 'https://mirror.bjtu.edu.cn/kernel/linux/devel/binutils/binutils-2.11.90.0.6-2.11.90.0.7.diff.gz',// Resource address.
|
||||
header: { }, // Adds an HTTP or HTTPS header to be included with the upload request.
|
||||
enableMetered: true,
|
||||
enableRoaming: true, // Allows download in a roaming network.
|
||||
description: 'a2', // Sets the description of a download session.
|
||||
networkType: 1, // Sets the network type allowed for download.
|
||||
filePath: '/system/lib/abc2.txt', // Sets the path for downloads.
|
||||
title: 'a2', // Sets a download session title.
|
||||
}
|
||||
let DownloadConfig10 = {
|
||||
url: 'https://mirror.bjtu.edu.cn/kernel/linux/devel/binutils/binutils-2.11.90.0.7-2.11.90.0.8.diff.gz',// Resource address.
|
||||
header: { }, // Adds an HTTP or HTTPS header to be included with the upload request.
|
||||
enableMetered: true,
|
||||
enableRoaming: true, // Allows download in a roaming network.
|
||||
description: 'a2', // Sets the description of a download session.
|
||||
networkType: 1, // Sets the network type allowed for download.
|
||||
filePath: '/system/lib/abc2.txt', // Sets the path for downloads.
|
||||
title: 'a2', // Sets a download session title.
|
||||
}
|
||||
let DownloadConfig11 = {
|
||||
url: 'https://mirror.bjtu.edu.cn/kernel/linux/devel/binutils/binutils-2.11.90.0.8-2.11.90.0.15.diff.gz',// Resource address.
|
||||
header: { }, // Adds an HTTP or HTTPS header to be included with the upload request.
|
||||
enableMetered: true,
|
||||
enableRoaming: true, // Allows download in a roaming network.
|
||||
description: 'a2', // Sets the description of a download session.
|
||||
networkType: 1, // Sets the network type allowed for download.
|
||||
filePath: '/system/lib/abc2.txt', // Sets the path for downloads.
|
||||
title: 'a2', // Sets a download session title.
|
||||
}
|
||||
let DownloadConfig12 = {
|
||||
url: 'https://mirror.bjtu.edu.cn/kernel/linux/devel/binutils/binutils-2.11.92.0.5-2.11.92.0.7.diff.gz',// Resource address.
|
||||
header: { }, // Adds an HTTP or HTTPS header to be included with the upload request.
|
||||
enableMetered: true,
|
||||
enableRoaming: true, // Allows download in a roaming network.
|
||||
description: 'a2', // Sets the description of a download session.
|
||||
networkType: 1, // Sets the network type allowed for download.
|
||||
filePath: '/system/lib/abc2.txt', // Sets the path for downloads.
|
||||
title: 'a2', // Sets a download session title.
|
||||
}
|
||||
let DownloadConfig13 = {
|
||||
url: 'https://mirror.bjtu.edu.cn/kernel/linux/devel/binutils/binutils-2.11.92.0.7-2.11.92.0.10.diff.gz',// Resource address.
|
||||
header: { }, // Adds an HTTP or HTTPS header to be included with the upload request.
|
||||
enableMetered: true,
|
||||
enableRoaming: true, // Allows download in a roaming network.
|
||||
description: 'a2', // Sets the description of a download session.
|
||||
networkType: 1, // Sets the network type allowed for download.
|
||||
filePath: '/system/lib/abc2.txt', // Sets the path for downloads.
|
||||
title: 'a2', // Sets a download session title.
|
||||
}
|
||||
let DownloadConfig14 = {
|
||||
url: 'https://mirror.bjtu.edu.cn/kernel/linux/devel/binutils/binutils-2.12.90.0.1-2.12.90.0.3.diff.gz',// Resource address.
|
||||
header: { }, // Adds an HTTP or HTTPS header to be included with the upload request.
|
||||
enableMetered: true,
|
||||
enableRoaming: true, // Allows download in a roaming network.
|
||||
description: 'a2', // Sets the description of a download session.
|
||||
networkType: 1, // Sets the network type allowed for download.
|
||||
filePath: '/system/lib/abc2.txt', // Sets the path for downloads.
|
||||
title: 'a2', // Sets a download session title.
|
||||
}
|
||||
let DownloadConfig15 = {
|
||||
url: 'https://mirror.bjtu.edu.cn/kernel/linux/devel/binutils/binutils-2.12.90.0.11-2.12.90.0.12.diff.gz',// Resource address.
|
||||
header: { }, // Adds an HTTP or HTTPS header to be included with the upload request.
|
||||
enableMetered: true,
|
||||
enableRoaming: true, // Allows download in a roaming network.
|
||||
description: 'a2', // Sets the description of a download session.
|
||||
networkType: 1, // Sets the network type allowed for download.
|
||||
filePath: '/system/lib/abc2.txt', // Sets the path for downloads.
|
||||
title: 'a2', // Sets a download session title.
|
||||
}
|
||||
let DownloadConfig16 = {
|
||||
url: 'https://mirror.bjtu.edu.cn/kernel/linux/devel/binutils/binutils-2.12.90.0.14-2.12.90.0.15.diff.gz',// Resource address.
|
||||
header: { }, // Adds an HTTP or HTTPS header to be included with the upload request.
|
||||
enableMetered: true,
|
||||
enableRoaming: true, // Allows download in a roaming network.
|
||||
description: 'a2', // Sets the description of a download session.
|
||||
networkType: 1, // Sets the network type allowed for download.
|
||||
filePath: '/system/lib/abc2.txt', // Sets the path for downloads.
|
||||
title: 'a2', // Sets a download session title.
|
||||
}
|
||||
const SLEEP_TIME = 1000
|
||||
|
||||
export default function exampleTestJsunit() {
|
||||
@@ -79,6 +209,7 @@ export default function exampleTestJsunit() {
|
||||
console.log("Show me the log");
|
||||
request.download(DownloadConfig, (err, data) => {
|
||||
console.log("Download_Test_0100: register download issue successful, result = " +data);
|
||||
expect(typeof(data) == 'number').assertTrue();
|
||||
done();
|
||||
});
|
||||
sleep(SLEEP_TIME);
|
||||
@@ -97,14 +228,17 @@ export default function exampleTestJsunit() {
|
||||
console.log("------------------start Download_Test_0200 on progress-------------------");
|
||||
try{
|
||||
let eventType = 'progress'
|
||||
request.download(DownloadConfig, (err, data) => {
|
||||
request.download(DownloadConfig4, (err, data) => {
|
||||
console.log("Download_Test_0200: register download issue successful, result = " +data);
|
||||
data.on(eventType,(err1,data1,data2) =>{
|
||||
console.log("Download_Test_0200: , on progress result data1 = "+data1);
|
||||
console.log("Download_Test_0200: , on progress result data2 = "+data2);
|
||||
expect(typeof(data1) == 'number').assertTrue();
|
||||
expect(typeof(data2) == 'number').assertTrue();
|
||||
done();
|
||||
})
|
||||
sleep(SLEEP_TIME);
|
||||
done();
|
||||
// done();
|
||||
});
|
||||
sleep(SLEEP_TIME);
|
||||
} catch (error) {
|
||||
@@ -120,13 +254,17 @@ export default function exampleTestJsunit() {
|
||||
it("Download_Test_0300", 0, async function(done){
|
||||
console.log("------------------start Download_Test_0300 on fail-------------------");
|
||||
try{
|
||||
let isEnter = 1
|
||||
let eventType = 'fail'
|
||||
request.download(DownloadConfig, (err, data) => {
|
||||
request.download(DownloadConfig5, (err, data) => {
|
||||
console.log("Download_Test_0300: register download issue successful, result = " +data);
|
||||
data.on(eventType,(err1,data1) =>{
|
||||
isEnter = 2
|
||||
console.log("Download_Test_0300: , on fail result = "+data1);
|
||||
expect(isEnter == 2).assertTrue();
|
||||
done();
|
||||
})
|
||||
done();
|
||||
// done();
|
||||
});
|
||||
sleep(SLEEP_TIME);
|
||||
} catch (error) {
|
||||
@@ -142,13 +280,17 @@ export default function exampleTestJsunit() {
|
||||
it("Download_Test_0400", 0, async function(done){
|
||||
console.log("------------------start Download_Test_0400-------------------");
|
||||
try{
|
||||
let isEnter = 1
|
||||
let eventType = 'complete';
|
||||
request.download(DownloadConfig, (err, data) => {
|
||||
request.download(DownloadConfig6, (err, data) => {
|
||||
console.log("Download_Test_0400: register download issue successful, result = " +data);
|
||||
data.on(eventType,(err1,data1) =>{
|
||||
isEnter = 2
|
||||
console.log("Download_Test_0400: , on complete result = "+data1);
|
||||
expect(isEnter == 2).assertTrue();
|
||||
done();
|
||||
})
|
||||
done();
|
||||
// done();
|
||||
});
|
||||
sleep(SLEEP_TIME);
|
||||
} catch (error) {
|
||||
@@ -164,18 +306,22 @@ export default function exampleTestJsunit() {
|
||||
it("Download_Test_0500", 0, async function(done){
|
||||
console.log("------------------start Download_Test_0500-------------------");
|
||||
try{
|
||||
let isEnter = 1
|
||||
let eventType = 'progress';
|
||||
request.download(DownloadConfig, (err, data) => {
|
||||
request.download(DownloadConfig7, (err, data) => {
|
||||
console.log("Download_Test_0500: register download issue successful, result = " +data);
|
||||
data.on(eventType,(err1,data1) =>{
|
||||
console.log("Download_Test_0500: , on progress result = "+data1);
|
||||
});
|
||||
sleep(SLEEP_TIME);
|
||||
data.off(eventType,(err1,data1,data2) =>{
|
||||
isEnter = 2
|
||||
console.log("Download_Test_0500: , off progress result = "+data1);
|
||||
console.log("Download_Test_0500: , off progress result = "+data2);
|
||||
expect(isEnter == 2).assertTrue();
|
||||
done();
|
||||
});
|
||||
done();
|
||||
// done();
|
||||
});
|
||||
sleep(SLEEP_TIME);
|
||||
} catch (error) {
|
||||
@@ -191,17 +337,20 @@ export default function exampleTestJsunit() {
|
||||
it("Download_Test_0600", 0, async function(done){
|
||||
console.log("------------------start Download_Test_0600-------------------");
|
||||
try{
|
||||
let isEnter = 1
|
||||
let eventType = 'fail';
|
||||
request.download(DownloadConfig, (err, data) => {
|
||||
request.download(DownloadConfig8, (err, data) => {
|
||||
console.log("Download_Test_0600: register download issue successful, result = " +data);
|
||||
data.on(eventType,(err,data) =>{
|
||||
console.log("Download_Test_0600: register on fail issue successful, result = " +data);
|
||||
});
|
||||
sleep(SLEEP_TIME);
|
||||
data.off(eventType,(err,data) =>{
|
||||
isEnter = 2
|
||||
console.log("Download_Test_0600: register off fail issue successful, result = " +data);
|
||||
expect(isEnter == 2).assertTrue();
|
||||
done();
|
||||
});
|
||||
done();
|
||||
});
|
||||
sleep(SLEEP_TIME);
|
||||
} catch (error) {
|
||||
@@ -217,17 +366,20 @@ export default function exampleTestJsunit() {
|
||||
it("Download_Test_0700", 0, async function(done){
|
||||
console.log("------------------start Download_Test_0700-------------------");
|
||||
try{
|
||||
let isEnter = 1
|
||||
let eventType = 'complete';
|
||||
request.download(DownloadConfig, (err, data) => {
|
||||
request.download(DownloadConfig9, (err, data) => {
|
||||
console.log("Download_Test_0700: register download issue successful, result = " +data);
|
||||
data.on(eventType,(err1,data1) =>{
|
||||
console.log("Download_Test_0700: , on complete result = "+data1);
|
||||
})
|
||||
sleep(SLEEP_TIME);
|
||||
data.off(eventType,(err1,data1) =>{
|
||||
isEnter = 2
|
||||
console.log("Download_Test_0700: , off complete result = "+data1);
|
||||
expect(isEnter == 2).assertTrue();
|
||||
done();
|
||||
})
|
||||
done();
|
||||
});
|
||||
sleep(SLEEP_TIME);
|
||||
} catch (error) {
|
||||
@@ -243,7 +395,7 @@ export default function exampleTestJsunit() {
|
||||
it("Download_Test_0800", 0, async function(done){
|
||||
console.log("------------------start Download_Test_0800-------------------");
|
||||
try{
|
||||
request.download(DownloadConfig, (err, data) => {
|
||||
request.download(DownloadConfig10, (err, data) => {
|
||||
let eventType = 'pause';
|
||||
console.log("Download_Test_0800: register download issue successful, result = " +data);
|
||||
data.on(eventType,(err1,data1) =>{
|
||||
@@ -251,8 +403,9 @@ export default function exampleTestJsunit() {
|
||||
})
|
||||
data.pause((err1,data1) =>{
|
||||
console.log("Download_Test_0800: , off pause result = "+data1);
|
||||
expect(data1==true).assertTrue();
|
||||
done();
|
||||
})
|
||||
done();
|
||||
});
|
||||
sleep(SLEEP_TIME);
|
||||
} catch (error) {
|
||||
@@ -268,15 +421,16 @@ export default function exampleTestJsunit() {
|
||||
it("Download_Test_0900", 0, async function(done){
|
||||
console.log("------------------start Download_Test_0900-------------------");
|
||||
try{
|
||||
request.download(DownloadConfig, (err, data) => {
|
||||
request.download(DownloadConfig11, (err, data) => {
|
||||
console.log("Download_Test_0900: register download issue successful, result = " +data);
|
||||
data.pause((err1,data1) =>{
|
||||
console.log("Download_Test_0900: , pause result = "+data1);
|
||||
})
|
||||
data.resume((err1,data1) =>{
|
||||
console.log("Download_Test_0900: , resume result = "+data1);
|
||||
expect(data1==true).assertTrue();
|
||||
done();
|
||||
})
|
||||
done();
|
||||
});
|
||||
sleep(SLEEP_TIME);
|
||||
} catch (error) {
|
||||
@@ -292,12 +446,13 @@ export default function exampleTestJsunit() {
|
||||
it("Download_Test_1000", 0, async function(done){
|
||||
console.log("------------------start Download_Test_1000-------------------");
|
||||
try{
|
||||
request.download(DownloadConfig, (err, data) => {
|
||||
request.download(DownloadConfig12, (err, data) => {
|
||||
console.log("Download_Test_1000: register download issue successful, result = " +data);
|
||||
data.remove((err1,data1) =>{
|
||||
console.log("Download_Test_1000: , remove result = "+data1);
|
||||
expect(data1==true).assertTrue();
|
||||
done();
|
||||
})
|
||||
done();
|
||||
});
|
||||
sleep(SLEEP_TIME);
|
||||
} catch (error) {
|
||||
@@ -313,16 +468,19 @@ export default function exampleTestJsunit() {
|
||||
it("Download_Test_1100", 0, async function(done){
|
||||
console.log("------------------start Download_Test_1100-------------------");
|
||||
try{
|
||||
request.download(DownloadConfig, (err, data) => {
|
||||
request.download(DownloadConfig13, (err, data) => {
|
||||
console.log("Download_Test_1100: register download issue successful, result = " +data);
|
||||
expect(typeof(data) == 'object').assertTrue();
|
||||
});
|
||||
request.download(DownloadConfig1, (err, data) => {
|
||||
request.download(DownloadConfig12, (err, data) => {
|
||||
console.log("Download_Test_1100: register download issue successful, result = " +data);
|
||||
expect(typeof(data) == 'object').assertTrue();
|
||||
});
|
||||
request.download(DownloadConfig2, (err, data) => {
|
||||
console.log("Download_Test_1100: register download issue successful, result = " +data);
|
||||
expect(typeof(data) == 'object').assertTrue();
|
||||
done();
|
||||
});
|
||||
done();
|
||||
sleep(SLEEP_TIME);
|
||||
} catch (error) {
|
||||
console.log("Download_Test_1100 multiple: error = " + error);
|
||||
@@ -337,10 +495,11 @@ export default function exampleTestJsunit() {
|
||||
it("Download_Test_1200", 0, async function(done){
|
||||
console.log("------------------start Download_Test_1200-------------------");
|
||||
try{
|
||||
request.download(DownloadConfig, (err, data) => {
|
||||
request.download(DownloadConfig14, (err, data) => {
|
||||
console.log("Download_Test_1200: register download issue successful, result = " +data);
|
||||
data.queryMimeType((err1,data1) =>{
|
||||
console.log("Download_Test_1200: register queryMimeType issue successful, result ="+data1);
|
||||
expect(typeof(data1) == 'string').assertTrue();
|
||||
})
|
||||
done();
|
||||
});
|
||||
@@ -358,10 +517,11 @@ export default function exampleTestJsunit() {
|
||||
it("Download_Test_1300", 0, async function(done){
|
||||
console.log("------------------start Download_Test_1300-------------------");
|
||||
try{
|
||||
request.download(DownloadConfig, (err, data) => {
|
||||
request.download(DownloadConfig15, (err, data) => {
|
||||
console.log("Download_Test_1300: register download issue successful, result = " +data);
|
||||
data.query((err1,data1) =>{
|
||||
console.log("Download_Test_1300: register query issue successful, result ="+JSON.stringify(data1));
|
||||
expect(typeof(data1) == 'object').assertTrue();
|
||||
})
|
||||
done();
|
||||
});
|
||||
@@ -380,6 +540,7 @@ export default function exampleTestJsunit() {
|
||||
try{
|
||||
request.download(DownloadConfig3, (err, data) => {
|
||||
console.log("Download_Test_1400: register download issue successful, result = " +data);
|
||||
expect(data==obj).assertTrue();
|
||||
done();
|
||||
});
|
||||
sleep(SLEEP_TIME);
|
||||
|
||||
Reference in New Issue
Block a user