1 /*
2 * Copyright (C) 2023 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
16 #![allow(unused_must_use)]
17 extern crate request;
18
19 use request::{enumration::*, form_item::*, task_config::*, task_manager::*};
20 use std::{collections::HashMap, fs::File, sync::Arc};
21
construct_download_task( task_id: &mut u32, uid: u64, file_name: &str, mode: Mode, version: Version, ) -> ErrorCode22 pub fn construct_download_task(
23 task_id: &mut u32,
24 uid: u64,
25 file_name: &str,
26 mode: Mode,
27 version: Version,
28 ) -> ErrorCode {
29 let conf = TaskConfig {
30 bundle: "xxx".into(),
31 url: "http://110.41.6.210:9029/fota-tmp/UltraEdit_x64.xp510.com.rar".into(),
32 title: "test".into(),
33 description: "xxxx".into(),
34 method: "get".into(),
35 headers: HashMap::<String, String>::new(),
36 data: "xxx".into(),
37 token: "12312".into(),
38 extras: HashMap::<String, String>::new(),
39 version,
40 form_items: vec![FormItem {
41 name: "name".to_string(),
42 value: "123".to_string(),
43 }],
44 file_specs: {
45 vec![FileSpec {
46 name: "file".to_string(),
47 path: "test.txt".to_string(),
48 file_name: "test.txt".to_string(),
49 mime_type: "txt".to_string(),
50 }]
51 },
52 common_data: CommonTaskConfig {
53 action: Action::DOWNLOAD,
54 mode,
55 cover: true,
56 network: Network::ANY,
57 metered: false,
58 roaming: true,
59 retry: true,
60 redirect: true,
61 index: 10,
62 begins: 0,
63 ends: -1,
64 gauge: false,
65 precise: false,
66 background: true,
67 },
68 };
69 let files = vec![File::create(file_name).expect("create file failed")];
70 TaskManager::get_instance().construct_task(Arc::new(conf), uid, task_id, files)
71 }
72
remove_files(paths: Vec<String>)73 pub fn remove_files(paths: Vec<String>) {
74 TaskManager::get_instance().clear_all_task();
75 for path in paths.iter() {
76 std::fs::remove_file(path);
77 }
78 }
79