Main: Allow downloading unencrypted media from positional mxc url argument

This commit is contained in:
networkException 2024-09-05 20:54:10 +02:00
parent db19efbede
commit e4cecf1bf5
Signed by: networkException
GPG key ID: E3877443AE684391

View file

@ -9,7 +9,7 @@ use log::{info, debug, error};
use serde::Deserialize; use serde::Deserialize;
use rustyline_async::{Readline, ReadlineEvent}; 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}}; 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 // 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 /// Homeserver URL or Name
#[clap(long, env)] #[clap(long, env)]
server: Option<String>, server: Option<String>,
mxc_url: Option<String>,
} }
#[tokio::main] #[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")); env_logger::init_from_env(env_logger::Env::default().filter_or(env_logger::DEFAULT_FILTER_ENV, "matrix_media_event_decrypt=debug"));
let Arguments { let Arguments {
server server,
mxc_url,
} = Arguments::parse(); } = 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"); info!("Enter decrypted event source, confirm with Ctrl+D");
let (mut readline, mut _stdout) = Readline::new("> ".to_owned()).unwrap(); let (mut readline, mut _stdout) = Readline::new("> ".to_owned()).unwrap();