diff --git a/src/service/admin/mod.rs b/src/service/admin/mod.rs index 60269d90..72ea506a 100644 --- a/src/service/admin/mod.rs +++ b/src/service/admin/mod.rs @@ -589,7 +589,8 @@ impl Service { RoomMessageEventContent::text_plain( "Expected code block in command body. Add --help for details.", ) - }.into() + } + .into() } AdminCommand::UnregisterAppservice { appservice_identifier, @@ -602,7 +603,8 @@ impl Service { Err(e) => RoomMessageEventContent::text_plain(format!( "Failed to unregister appservice: {e}" )), - }.into(), + } + .into(), AdminCommand::ListAppservices => { let appservices = services().appservice.iter_ids().await; let output = format!( @@ -640,7 +642,8 @@ impl Service { RoomMessageEventContent::text_plain(&msg) } Err(e) => RoomMessageEventContent::text_plain(e.to_string()), - }.into(), + } + .into(), AdminCommand::IncomingFederation => { let map = services().globals.roomid_federationhandletime.read().await; let mut msg: String = format!("Handling {} incoming pdus:\n", map.len()); @@ -681,7 +684,8 @@ impl Service { )) } else { RoomMessageEventContent::text_plain("Event not found.") - }.into() + } + .into() } AdminCommand::ParsePdu => { if body.len() > 2 && body[0].trim() == "```" && body.last().unwrap().trim() == "```" @@ -715,7 +719,8 @@ impl Service { } } else { RoomMessageEventContent::text_plain("Expected code block in command body.") - }.into() + } + .into() } AdminCommand::GetPdu { event_id } => { let mut outlier = false; @@ -753,7 +758,8 @@ impl Service { ) } None => RoomMessageEventContent::text_plain("PDU not found."), - }.into() + } + .into() } AdminCommand::MemoryUsage => { let response1 = services().memory_usage().await; @@ -761,7 +767,8 @@ impl Service { RoomMessageEventContent::text_plain(format!( "Services:\n{response1}\n\nDatabase:\n{response2}" - )).into() + )) + .into() } AdminCommand::ClearDatabaseCaches { amount } => { services().globals.db.clear_caches(amount); @@ -786,7 +793,8 @@ impl Service { Err(e) => { return Ok(RoomMessageEventContent::text_plain(format!( "The supplied username is not a valid username: {e}" - )).into()) + )) + .into()) } }; @@ -794,7 +802,8 @@ impl Service { if user_id.server_name() != services().globals.server_name() { return Ok(RoomMessageEventContent::text_plain( "The specified user is not from this server!", - ).into()); + ) + .into()); }; // Check if the specified user is valid @@ -808,7 +817,8 @@ impl Service { { return Ok(RoomMessageEventContent::text_plain( "The specified user does not exist!", - ).into()); + ) + .into()); } let new_password = utils::random_string(AUTO_GEN_PASSWORD_LENGTH); @@ -823,7 +833,8 @@ impl Service { Err(e) => RoomMessageEventContent::text_plain(format!( "Couldn't reset the password for user {user_id}: {e}" )), - }.into() + } + .into() } AdminCommand::CreateUser { username, password } => { let password = @@ -837,7 +848,8 @@ impl Service { Err(e) => { return Ok(RoomMessageEventContent::text_plain(format!( "The supplied username is not a valid username: {e}" - )).into()) + )) + .into()) } }; @@ -845,18 +857,21 @@ impl Service { if user_id.server_name() != services().globals.server_name() { return Ok(RoomMessageEventContent::text_plain( "The specified user is not from this server!", - ).into()); + ) + .into()); }; if user_id.is_historical() { return Ok(RoomMessageEventContent::text_plain(format!( "Userid {user_id} is not allowed due to historical" - )).into()); + )) + .into()); } if services().users.exists(&user_id)? { return Ok(RoomMessageEventContent::text_plain(format!( "Userid {user_id} already exists" - )).into()); + )) + .into()); } // Create user services().users.create(&user_id, Some(password.as_str()))?; @@ -893,26 +908,26 @@ impl Service { // Inhibit login does not work for guests RoomMessageEventContent::text_plain(format!( "Created user with user_id: {user_id} and password: {password}" - )).into() + )) + .into() } - AdminCommand::AllowRegistration { status } => { - if let Some(status) = status { - services().globals.set_registration(status).await; - RoomMessageEventContent::text_plain(if status { - "Registration is now enabled" - } else { - "Registration is now disabled" - }) + AdminCommand::AllowRegistration { status } => if let Some(status) = status { + services().globals.set_registration(status).await; + RoomMessageEventContent::text_plain(if status { + "Registration is now enabled" } else { - RoomMessageEventContent::text_plain( - if services().globals.allow_registration().await { - "Registration is currently enabled" - } else { - "Registration is currently disabled" - }, - ) - }.into() + "Registration is now disabled" + }) + } else { + RoomMessageEventContent::text_plain( + if services().globals.allow_registration().await { + "Registration is currently enabled" + } else { + "Registration is currently disabled" + }, + ) } + .into(), AdminCommand::DisableRoom { room_id } => { services().rooms.metadata.disable_room(&room_id, true)?; RoomMessageEventContent::text_plain("Room disabled.").into() @@ -1031,7 +1046,10 @@ impl Service { let mut message = format!("Deactivated {deactivation_count} accounts."); if !admins.is_empty() { - message.push_str(&format!("\nSkipped admin accounts: {:?}. Use --force to deactivate admin accounts",admins.join(", "))); + message.push_str(&format!( + "\nSkipped admin accounts: {:?}. Use --force to deactivate admin accounts", + admins.join(", ") + )); } if failed_count != 0 { message.push_str(&format!( @@ -1044,14 +1062,19 @@ impl Service { RoomMessageEventContent::text_plain( "Expected code block in command body. Add --help for details.", ) - }.into() + } + .into() } AdminCommand::QueryMedia { mxc } => { let Ok((server_name, media_id)) = mxc.parts() else { return Ok(RoomMessageEventContent::text_plain("Invalid media MXC").into()); }; - let MediaQuery{ is_blocked, source_file, thumbnails } = services().media.query(server_name, media_id)?; + let MediaQuery { + is_blocked, + source_file, + thumbnails, + } = services().media.query(server_name, media_id)?; let mut message = format!("Is blocked Media ID: {is_blocked}"); if let Some(MediaQueryFileInfo { @@ -1062,14 +1085,16 @@ impl Service { unauthenticated_access_permitted, is_blocked_via_filehash, file_info: time_info, - }) = source_file { + }) = source_file + { message.push_str("\n\nInformation on full (non-thumbnail) file:\n"); if let Some(FileInfo { creation, last_access, size, - }) = time_info { + }) = time_info + { message.push_str(&format!("\nIs stored: true\nCreated at: {}\nLast accessed at: {}\nSize of file: {}", DateTime::from_timestamp(creation.try_into().unwrap_or(i64::MAX),0).expect("Timestamp is within range"), DateTime::from_timestamp(last_access.try_into().unwrap_or(i64::MAX),0).expect("Timestamp is within range"), @@ -1098,7 +1123,7 @@ impl Service { message.push_str("\n\nInformation on thumbnails of media:"); } - for MediaQueryThumbInfo{ + for MediaQueryThumbInfo { width, height, sha256_hex, @@ -1107,13 +1132,15 @@ impl Service { unauthenticated_access_permitted, is_blocked_via_filehash, file_info: time_info, - } in thumbnails { + } in thumbnails + { message.push_str(&format!("\n\nDimensions: {width}x{height}")); if let Some(FileInfo { creation, last_access, size, - }) = time_info { + }) = time_info + { message.push_str(&format!("\nIs stored: true\nCreated at: {}\nLast accessed at: {}\nSize of file: {}", DateTime::from_timestamp(creation.try_into().unwrap_or(i64::MAX),0).expect("Timestamp is within range"), DateTime::from_timestamp(last_access.try_into().unwrap_or(i64::MAX),0).expect("Timestamp is within range"), @@ -1147,7 +1174,8 @@ impl Service { file, content_type, content_disposition, - } = client_server::media::get_content(server_name, media_id.to_owned(), true, true).await?; + } = client_server::media::get_content(server_name, media_id.to_owned(), true, true) + .await?; if let Ok(image) = image::load_from_memory(&file) { let filename = content_disposition.and_then(|cd| cd.filename); @@ -1187,10 +1215,7 @@ impl Service { } } AdminCommand::ListMedia { - user_server_filter: ListMediaArgs { - user, - server, - }, + user_server_filter: ListMediaArgs { user, server }, include_thumbnails, content_type, uploaded_before, @@ -1203,7 +1228,7 @@ impl Service { r#"
MXC URI | Dimensions (if thumbnail) | Created/Downloaded at | Uploader | Content-Type | Filename | Size |
---|