Abstract URL opening in utility, use Url instances

This commit is contained in:
timvisee 2018-03-18 21:01:54 +01:00
parent c2611049df
commit a4aa1b93e5
No known key found for this signature in database
GPG key ID: 109CBA0BF74036C2
5 changed files with 32 additions and 11 deletions

View file

@ -229,7 +229,8 @@ impl UploadResponse {
SendFile::new_now(
self.id,
host,
self.url,
Url::parse(&self.url)
.expect("upload response URL parse error"),
key.secret().to_vec(),
self.owner,
)

View file

@ -21,7 +21,7 @@ pub struct File {
host: Url,
/// The file URL that was provided by the server.
url: String,
url: Url,
/// The secret key that is required to download the file.
secret: Vec<u8>,
@ -36,7 +36,7 @@ impl File {
id: String,
time: DateTime<Utc>,
host: Url,
url: String,
url: Url,
secret: Vec<u8>,
owner_key: String,
) -> Self {
@ -54,7 +54,7 @@ impl File {
pub fn new_now(
id: String,
host: Url,
url: String,
url: Url,
secret: Vec<u8>,
owner_key: String,
) -> Self {
@ -79,7 +79,11 @@ impl File {
}
/// Get the download URL of the file, with the secret key included.
pub fn download_url(&self) -> String {
format!("{}#{}", self.url, self.secret())
pub fn download_url(&self) -> Url {
// Get the download URL, and add the secret fragment
let mut url = self.url.clone();
url.set_fragment(Some(&self.secret()));
url
}
}