matrix-ipfs-bot

git clone git://archive.git.mtrnord.blog/MTRNord/matrix-ipfs-bot.git
Log | Files | Refs | LICENSE

utils.rs (949B)


      1 use serde::{Deserialize, Serialize};
      2 use url::Url;
      3 
      4 pub fn get_media_download_url(mxc_url: String) -> String {
      5     let url_parts_raw = mxc_url.replace("mxc://", "");
      6     let url_parts: Vec<&str> = url_parts_raw.split('/').collect();
      7     let server_name = (*url_parts.first().unwrap()).to_string();
      8     let media_id = (*url_parts.last().unwrap()).to_string();
      9     let new_path = format!("_matrix/media/r0/download/{}/{}", server_name, media_id,);
     10     // FIX this madness
     11     let mut new_url = Url::parse(format!("https://matrix.{}", server_name).as_str()).unwrap();
     12     new_url.set_path(new_path.as_str());
     13     println!("{}", new_url);
     14     new_url.to_string()
     15 }
     16 
     17 #[derive(Clone, Debug, Serialize, Deserialize)]
     18 pub struct Session {
     19     /// The access token used for this session.
     20     pub access_token: String,
     21     /// The user the access token was issued for.
     22     pub user_id: String,
     23     /// The ID of the client device
     24     pub device_id: String,
     25 }