From e01f2030e17a1bbacec97d419384b176ec0d459c Mon Sep 17 00:00:00 2001 From: sigoden Date: Thu, 9 Jun 2022 21:35:52 +0800 Subject: [PATCH] chore: optimize code --- src/server.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/server.rs b/src/server.rs index 150d4e6..f8029c5 100644 --- a/src/server.rs +++ b/src/server.rs @@ -816,10 +816,12 @@ struct PathItem { impl PathItem { pub fn to_dav_xml(&self, prefix: &str) -> String { let mtime = Utc.timestamp_millis(self.mtime as i64).to_rfc2822(); + let href = encode_uri(&format!("{}{}", prefix, &self.name)); + let displayname = escape_str_pcdata(&self.base_name); match self.path_type { PathType::Dir | PathType::SymlinkDir => format!( r#" -{}{} +{} {} @@ -829,14 +831,11 @@ impl PathItem { HTTP/1.1 200 OK "#, - prefix, - encode_uri(&self.name), - escape_str_pcdata(&self.base_name), - mtime + href, displayname, mtime ), PathType::File | PathType::SymlinkFile => format!( r#" -{}{} +{} {} @@ -847,9 +846,8 @@ impl PathItem { HTTP/1.1 200 OK "#, - prefix, - encode_uri(&self.name), - escape_str_pcdata(&self.base_name), + href, + displayname, self.size.unwrap_or_default(), mtime ),