feat: shorten video url
This commit is contained in:
parent
5aaf02f062
commit
ef898dfb76
2 changed files with 47 additions and 3 deletions
|
@ -42,6 +42,11 @@ pub struct ZiplineThumbnail {
|
|||
pub path: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Deserialize)]
|
||||
pub struct ZiplineShortUrl {
|
||||
url: String,
|
||||
}
|
||||
|
||||
impl ZiplineFileInfo {
|
||||
pub fn thumbnail_url(&self, config: &Config) -> Option<String> {
|
||||
self.thumbnail
|
||||
|
@ -169,3 +174,32 @@ pub async fn get_file_details(config: &Config, id: &str) -> Result<ZiplineFileIn
|
|||
res.json().await.map_err(Into::into)
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn shorten_url(config: &Config, to_shorten: &str) -> Result<String> {
|
||||
let url = format!("{}api/user/urls", config.fixed_url());
|
||||
|
||||
let body = serde_json::json!({
|
||||
"destination": to_shorten,
|
||||
"enabled": true,
|
||||
"vanity": null
|
||||
});
|
||||
|
||||
let res = CLIENT
|
||||
.post(url)
|
||||
.json(&body)
|
||||
.header(AUTHORIZATION, &config.zipline_token)
|
||||
.send()
|
||||
.await?;
|
||||
|
||||
if res.status() != StatusCode::OK {
|
||||
bail!(
|
||||
"an error occurred ({}): {}",
|
||||
res.status(),
|
||||
res.text().await?
|
||||
);
|
||||
} else {
|
||||
let out: ZiplineShortUrl = res.json().await?;
|
||||
|
||||
Ok(out.url)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue