1 // Copyright (C) 2023 Huawei Device Co., Ltd.
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 //
6 //     http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13 
14 use std::fs::File;
15 use std::os::fd::{IntoRawFd, RawFd};
16 
17 /// File Spec
18 #[derive(Clone, Debug)]
19 pub struct FileSpec {
20     /// Name
21     pub name: String,
22     /// path
23     pub path: String,
24     /// file_name
25     pub file_name: String,
26     /// mime_type
27     pub mime_type: String,
28     /// is_user_file
29     pub is_user_file: bool,
30     /// Only for user file.
31     pub fd: Option<RawFd>,
32 }
33 
34 impl FileSpec {
35     /// Create a new file spec with user file.
user_file(file: File) -> Self36     pub fn user_file(file: File) -> Self {
37         Self {
38             name: "".to_string(),
39             path: "".to_string(),
40             file_name: "".to_string(),
41             mime_type: "".to_string(),
42             is_user_file: true,
43             fd: Some(file.into_raw_fd()),
44         }
45     }
46 }
47 
48 #[derive(Clone, Debug)]
49 pub(crate) struct FormItem {
50     pub(crate) name: String,
51     pub(crate) value: String,
52 }
53