use url::Url;
use crate::file::remote_file::RemoteFile;
pub struct UrlBuilder;
impl UrlBuilder {
pub fn download(file: &RemoteFile, secret: bool) -> Url {
let mut url = file.url().clone();
if secret && file.has_secret() {
url.set_fragment(Some(&file.secret()));
} else {
url.set_fragment(None);
}
url
}
fn api(endpoint: &str, file: &RemoteFile) -> Url {
let mut url = file.url().clone();
url.set_path(format!("/api/{}/{}", endpoint, file.id()).as_str());
url.set_fragment(None);
url
}
pub fn api_metadata(file: &RemoteFile) -> Url {
Self::api("metadata", file)
}
pub fn api_download(file: &RemoteFile) -> Url {
Self::api("download", file)
}
pub fn api_password(file: &RemoteFile) -> Url {
Self::api("password", file)
}
pub fn api_params(file: &RemoteFile) -> Url {
Self::api("params", file)
}
pub fn api_info(file: &RemoteFile) -> Url {
Self::api("info", file)
}
pub fn api_exists(file: &RemoteFile) -> Url {
Self::api("exists", file)
}
pub fn api_delete(file: &RemoteFile) -> Url {
Self::api("delete", file)
}
}