From e4cecf1bf53682a7cb44b34a22e9bdca1c477cb5 Mon Sep 17 00:00:00 2001 From: networkException Date: Thu, 5 Sep 2024 20:54:10 +0200 Subject: [PATCH] Main: Allow downloading unencrypted media from positional mxc url argument --- src/main.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 90f0eda..260186c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,7 +9,7 @@ use log::{info, debug, error}; use serde::Deserialize; use rustyline_async::{Readline, ReadlineEvent}; -use matrix_sdk::{matrix_auth::{MatrixSession, MatrixSessionTokens}, ruma::{api::client::{authenticated_media, media}, device_id, user_id}, Client, SessionMeta}; +use matrix_sdk::{matrix_auth::{MatrixSession, MatrixSessionTokens}, ruma::{api::client::{authenticated_media, media}, device_id, user_id, OwnedMxcUri}, Client, SessionMeta}; use matrix_sdk::ruma::events::room::{MediaSource, message::{MessageType, RoomMessageEventContent}}; // NOTE: This has been stolen from the matrix-rust-sdk to patch out checks for authenticated media @@ -155,6 +155,8 @@ struct Arguments { /// Homeserver URL or Name #[clap(long, env)] server: Option, + + mxc_url: Option, } #[tokio::main] @@ -162,9 +164,18 @@ async fn main() -> Result<()> { env_logger::init_from_env(env_logger::Env::default().filter_or(env_logger::DEFAULT_FILTER_ENV, "matrix_media_event_decrypt=debug")); let Arguments { - server + server, + mxc_url, } = Arguments::parse(); + if mxc_url.is_some() { + if let Err(error) = process_media(MediaSource::Plain(OwnedMxcUri::from(mxc_url.unwrap())), None, server).await { + error!("Unable to process media: {}", error); + } + + return Ok(()); + } + info!("Enter decrypted event source, confirm with Ctrl+D"); let (mut readline, mut _stdout) = Readline::new("> ".to_owned()).unwrap();