1use std::sync::Arc;
2use url::Url;
3
4#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5#[derive(Debug, Clone, PartialEq, Eq)]
6pub struct UrlInfo {
7 pub size: u64,
8 #[cfg_attr(
10 feature = "sanitize-filename",
11 doc = "用 [`UrlInfo::filename()`] 方法处理文件名"
12 )]
13 #[cfg_attr(
14 not(feature = "sanitize-filename"),
15 doc = "开启 `sanitize-filename` 特性后,可使用 `filename()` 方法处理文件名。"
16 )]
17 pub raw_name: String,
18 pub supports_range: bool,
19 pub fast_download: bool,
20 pub final_url: Url,
21 pub file_id: FileId,
22 pub content_type: Option<String>,
23}
24
25#[cfg(feature = "sanitize-filename")]
26impl UrlInfo {
27 #[must_use]
28 pub fn filename(&self) -> String {
29 path_helper::sanitize_filename(&self.raw_name, 255)
30 }
31}
32
33#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
34#[derive(Debug, Clone, PartialEq, Eq, Default)]
35pub struct FileId {
36 pub etag: Option<Arc<str>>,
37 pub last_modified: Option<Arc<str>>,
38}
39
40impl FileId {
41 pub fn new(etag: Option<&str>, last_modified: Option<&str>) -> Self {
42 Self {
43 etag: etag.map(Arc::from),
44 last_modified: last_modified.map(Arc::from),
45 }
46 }
47}