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 pub raw_name: String,
10 pub supports_range: bool,
11 pub fast_download: bool,
12 pub final_url: Url,
13 pub file_id: FileId,
14}
15
16#[cfg(feature = "sanitize-filename")]
17impl UrlInfo {
18 pub fn filename(&self) -> String {
19 sanitize_filename::sanitize_with_options(
20 &self.raw_name,
21 sanitize_filename::Options {
22 windows: cfg!(windows),
23 truncate: true,
24 replacement: "_",
25 },
26 )
27 }
28}
29
30#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
31#[derive(Debug, Clone, PartialEq, Eq, Default)]
32pub struct FileId {
33 pub etag: Option<Arc<str>>,
34 pub last_modified: Option<Arc<str>>,
35}
36
37impl FileId {
38 pub fn new(etag: Option<&str>, last_modified: Option<&str>) -> Self {
39 Self {
40 etag: etag.map(Arc::from),
41 last_modified: last_modified.map(Arc::from),
42 }
43 }
44}