From 0e68c5e8bc5f4f3022ed2eeffcca5272c7322d77 Mon Sep 17 00:00:00 2001 From: GyDi <segydi@foxmail.com> Date: Fri, 6 May 2022 10:52:59 +0800 Subject: [PATCH] feat: supports more remote headers close #81 --- src-tauri/src/core/prfitem.rs | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/src-tauri/src/core/prfitem.rs b/src-tauri/src/core/prfitem.rs index 512700b..640c7b6 100644 --- a/src-tauri/src/core/prfitem.rs +++ b/src-tauri/src/core/prfitem.rs @@ -16,13 +16,13 @@ pub struct PrfItem { /// profile name pub name: Option<String>, + /// profile file + pub file: Option<String>, + /// profile description #[serde(skip_serializing_if = "Option::is_none")] pub desc: Option<String>, - /// profile file - pub file: Option<String>, - /// source url #[serde(skip_serializing_if = "Option::is_none")] pub url: Option<String>, @@ -156,7 +156,7 @@ impl PrfItem { let desc = item.desc.unwrap_or("".into()); PrfItem::from_script(name, desc) } - typ @ _ => bail!("invalid type \"{typ}\""), + typ @ _ => bail!("invalid profile item type \"{typ}\""), } } @@ -224,9 +224,30 @@ impl PrfItem { None => None, }; + // parse the Content-Disposition + let filename = match header.get("Content-Disposition") { + Some(value) => { + let filename = value.to_str().unwrap_or(""); + help::parse_str::<String>(filename, "filename=") + } + None => None, + }; + + // parse the profile-update-interval + let option = match header.get("profile-update-interval") { + Some(value) => match value.to_str().unwrap_or("").parse::<u64>() { + Ok(val) => Some(PrfOption { + update_interval: Some(val * 60), // hour -> min + ..PrfOption::default() + }), + Err(_) => None, + }, + None => None, + }; + let uid = help::get_uid("r"); let file = format!("{uid}.yaml"); - let name = name.unwrap_or(uid.clone()); + let name = name.unwrap_or(filename.unwrap_or("Remote File".into())); let data = resp.text_with_charset("utf-8").await?; // check the data whether the valid yaml format -- GitLab