mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-11-15 13:16:56 +00:00
chore: Clippy fixes
This commit is contained in:
1 parent
18b0a87b2d
commit
eadcea8034
14 files changed
+66
-52
No files matched your search
@@ -11,6 +11,7 @@ pub enum TesterCommand {
|
|||||||
Timer,
|
Timer,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::unused_async_trait_impl)]
|
||||||
impl crate::Context<'_> {
|
impl crate::Context<'_> {
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
async fn panic(&self) -> Result {
|
async fn panic(&self) -> Result {
|
||||||
|
|||||||
+14
-6
@@ -49,7 +49,7 @@ async fn handle_command(services: Arc<Services>, command: CommandInput) -> Proce
|
|||||||
|
|
||||||
async fn process_command(services: Arc<Services>, input: &CommandInput) -> ProcessorResult {
|
async fn process_command(services: Arc<Services>, input: &CommandInput) -> ProcessorResult {
|
||||||
let (command, args, body) = match parse(&services, input) {
|
let (command, args, body) = match parse(&services, input) {
|
||||||
| Err(error) => return Err(error),
|
| Err(error) => return Err(Box::new(error)),
|
||||||
| Ok(parsed) => parsed,
|
| Ok(parsed) => parsed,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -72,18 +72,26 @@ async fn process_command(services: Arc<Services>, input: &CommandInput) -> Proce
|
|||||||
String::from_utf8(take(output.get_mut())).expect("invalid utf8 in command output stream");
|
String::from_utf8(take(output.get_mut())).expect("invalid utf8 in command output stream");
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
| Ok(()) if logs.is_empty() =>
|
| Ok(()) if logs.is_empty() => Ok(Some(Box::new(reply(
|
||||||
Ok(Some(reply(RoomMessageEventContent::notice_markdown(output), context.reply_id))),
|
RoomMessageEventContent::notice_markdown(output),
|
||||||
|
context.reply_id,
|
||||||
|
)))),
|
||||||
|
|
||||||
| Ok(()) => {
|
| Ok(()) => {
|
||||||
logs.write_str(output.as_str()).expect("output buffer");
|
logs.write_str(output.as_str()).expect("output buffer");
|
||||||
Ok(Some(reply(RoomMessageEventContent::notice_markdown(logs), context.reply_id)))
|
Ok(Some(Box::new(reply(
|
||||||
|
RoomMessageEventContent::notice_markdown(logs),
|
||||||
|
context.reply_id,
|
||||||
|
))))
|
||||||
},
|
},
|
||||||
| Err(error) => {
|
| Err(error) => {
|
||||||
write!(&mut logs, "Command failed with error:\n```\n{error:#?}\n```")
|
write!(&mut logs, "Command failed with error:\n```\n{error:#?}\n```")
|
||||||
.expect("output buffer");
|
.expect("output buffer");
|
||||||
|
|
||||||
Err(reply(RoomMessageEventContent::notice_markdown(logs), context.reply_id))
|
Err(Box::new(reply(
|
||||||
|
RoomMessageEventContent::notice_markdown(logs),
|
||||||
|
context.reply_id,
|
||||||
|
)))
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -94,7 +102,7 @@ fn handle_panic(error: &Error, command: &CommandInput) -> ProcessorResult {
|
|||||||
let msg = format!("Panic occurred while processing command:\n```\n{error:#?}\n```\n{link}");
|
let msg = format!("Panic occurred while processing command:\n```\n{error:#?}\n```\n{link}");
|
||||||
let content = RoomMessageEventContent::notice_markdown(msg);
|
let content = RoomMessageEventContent::notice_markdown(msg);
|
||||||
error!("Panic while processing command: {error:?}");
|
error!("Panic while processing command: {error:?}");
|
||||||
Err(reply(content, command.reply_id.as_deref()))
|
Err(Box::new(reply(content, command.reply_id.as_deref())))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse and process a message from the admin room
|
/// Parse and process a message from the admin room
|
||||||
|
|||||||
@@ -68,8 +68,7 @@ pub(crate) async fn update_device_route(
|
|||||||
|
|
||||||
services
|
services
|
||||||
.users
|
.users
|
||||||
.update_device_metadata(sender_user, &body.device_id, &device)
|
.update_device_metadata(sender_user, &body.device_id, &device)?;
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(update_device::v3::Response::new())
|
Ok(update_device::v3::Response::new())
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -104,12 +104,15 @@ where
|
|||||||
{
|
{
|
||||||
type Rejection = ClientIpError;
|
type Rejection = ClientIpError;
|
||||||
|
|
||||||
async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {
|
fn from_request_parts(
|
||||||
Self::for_config(
|
parts: &mut Parts,
|
||||||
|
state: &S,
|
||||||
|
) -> impl Future<Output = Result<Self, Self::Rejection>> {
|
||||||
|
std::future::ready(Self::for_config(
|
||||||
parts,
|
parts,
|
||||||
&state.config.accepted_ip_sources,
|
&state.config.accepted_ip_sources,
|
||||||
state.config.request_ip_source.as_ref(),
|
state.config.request_ip_source.as_ref(),
|
||||||
)
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -331,14 +331,14 @@ impl CheckAuth for AppserviceTokenOptional {
|
|||||||
impl CheckAuth for NoAuthentication {
|
impl CheckAuth for NoAuthentication {
|
||||||
type Identity = ();
|
type Identity = ();
|
||||||
|
|
||||||
async fn verify<B: AsRef<[u8]> + Sync>(
|
fn verify<B: AsRef<[u8]> + Sync>(
|
||||||
_services: &Services,
|
_services: &Services,
|
||||||
_output: Self::Output,
|
_output: Self::Output,
|
||||||
_request: &hyper::Request<B>,
|
_request: &hyper::Request<B>,
|
||||||
_query: AuthQueryParams,
|
_query: AuthQueryParams,
|
||||||
_route: TypeId,
|
_route: TypeId,
|
||||||
) -> Result<Self::Identity> {
|
) -> impl Future<Output = Result<Self::Identity>> {
|
||||||
Ok(())
|
std::future::ready(Ok(()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,12 +49,14 @@ impl Console {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn start(self: &Arc<Self>) {
|
pub fn start(self: &Arc<Self>) -> impl Future<Output = ()> {
|
||||||
let mut worker_join = self.worker_join.lock();
|
let mut worker_join = self.worker_join.lock();
|
||||||
if worker_join.is_none() {
|
if worker_join.is_none() {
|
||||||
let self_ = Arc::clone(self);
|
let self_ = Arc::clone(self);
|
||||||
_ = worker_join.insert(self.server.runtime().spawn(self_.worker()));
|
_ = worker_join.insert(self.server.runtime().spawn(self_.worker()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::future::ready(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn close(self: &Arc<Self>) {
|
pub async fn close(self: &Arc<Self>) {
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ pub type ProcessorFuture = Pin<Box<dyn Future<Output = ProcessorResult> + Send>>
|
|||||||
/// events which have digested any prior errors. The wrapping preserves whether
|
/// events which have digested any prior errors. The wrapping preserves whether
|
||||||
/// the command failed without interpreting the text. Ok(None) outputs are
|
/// the command failed without interpreting the text. Ok(None) outputs are
|
||||||
/// dropped to produce no response.
|
/// dropped to produce no response.
|
||||||
pub type ProcessorResult = Result<Option<CommandOutput>, CommandOutput>;
|
pub type ProcessorResult = Result<Option<Box<CommandOutput>>, Box<CommandOutput>>;
|
||||||
|
|
||||||
/// Alias for the output structure.
|
/// Alias for the output structure.
|
||||||
pub type CommandOutput = RoomMessageEventContent;
|
pub type CommandOutput = RoomMessageEventContent;
|
||||||
@@ -204,7 +204,7 @@ impl Service {
|
|||||||
.text_to_file(message_content.body())
|
.text_to_file(message_content.body())
|
||||||
.await
|
.await
|
||||||
.expect("failed to create text file");
|
.expect("failed to create text file");
|
||||||
let size_u64: u64 = message_content.body().len().try_into().map_or(0, |n| n);
|
let size_u64: u64 = message_content.body().len().try_into().unwrap_or(0);
|
||||||
|
|
||||||
let mut metadata = FileInfo::new();
|
let mut metadata = FileInfo::new();
|
||||||
metadata.mimetype = Some("text/markdown".to_owned());
|
metadata.mimetype = Some("text/markdown".to_owned());
|
||||||
@@ -365,7 +365,7 @@ impl Service {
|
|||||||
match self.process_command(command).await {
|
match self.process_command(command).await {
|
||||||
| Ok(None) => debug!("Command successful with no response"),
|
| Ok(None) => debug!("Command successful with no response"),
|
||||||
| Ok(Some(output)) | Err(output) => self
|
| Ok(Some(output)) | Err(output) => self
|
||||||
.handle_response(output)
|
.handle_response(*output)
|
||||||
.await
|
.await
|
||||||
.unwrap_or_else(default_log),
|
.unwrap_or_else(default_log),
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-13
@@ -65,7 +65,7 @@ impl Manager {
|
|||||||
|
|
||||||
debug!("Starting service workers...");
|
debug!("Starting service workers...");
|
||||||
for service in services {
|
for service in services {
|
||||||
self.start_worker(&mut workers, &service).await?;
|
self.start_worker(&mut workers, &service)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -108,20 +108,14 @@ impl Manager {
|
|||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let (service, result) = result;
|
let (service, result) = result;
|
||||||
match result {
|
match result {
|
||||||
| Ok(()) => self.handle_finished(workers, &service).await,
|
| Ok(()) => {
|
||||||
|
debug!("service {:?} worker finished", service.name());
|
||||||
|
Ok(())
|
||||||
|
},
|
||||||
| Err(error) => self.handle_error(workers, &service, error).await,
|
| Err(error) => self.handle_error(workers, &service, error).await,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_finished(
|
|
||||||
&self,
|
|
||||||
_workers: &mut WorkersLocked<'_>,
|
|
||||||
service: &Arc<dyn Service>,
|
|
||||||
) -> Result<()> {
|
|
||||||
debug!("service {:?} worker finished", service.name());
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn handle_error(
|
async fn handle_error(
|
||||||
&self,
|
&self,
|
||||||
workers: &mut WorkersLocked<'_>,
|
workers: &mut WorkersLocked<'_>,
|
||||||
@@ -144,11 +138,11 @@ impl Manager {
|
|||||||
warn!("service {name:?} worker restarting after {} delay", time::pretty(delay));
|
warn!("service {name:?} worker restarting after {} delay", time::pretty(delay));
|
||||||
sleep(delay).await;
|
sleep(delay).await;
|
||||||
|
|
||||||
self.start_worker(workers, service).await
|
self.start_worker(workers, service)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Start the worker in a task for the service.
|
/// Start the worker in a task for the service.
|
||||||
async fn start_worker(
|
fn start_worker(
|
||||||
&self,
|
&self,
|
||||||
workers: &mut WorkersLocked<'_>,
|
workers: &mut WorkersLocked<'_>,
|
||||||
service: &Arc<dyn Service>,
|
service: &Arc<dyn Service>,
|
||||||
|
|||||||
@@ -49,18 +49,22 @@ pub struct UrlPreviewData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Service {
|
impl Service {
|
||||||
pub async fn remove_url_preview(&self, url: &str) -> Result<()> {
|
pub fn remove_url_preview(&self, url: &str) -> impl Future<Output = Result<()>> {
|
||||||
// TODO: also remove the downloaded image
|
// TODO: also remove the downloaded image
|
||||||
self.db.remove_url_preview(url)
|
std::future::ready(self.db.remove_url_preview(url))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn clear_url_previews(&self) { self.db.clear_url_previews().await; }
|
pub async fn clear_url_previews(&self) { self.db.clear_url_previews().await; }
|
||||||
|
|
||||||
pub async fn set_url_preview(&self, url: &str, data: &UrlPreviewData) -> Result<()> {
|
pub fn set_url_preview(
|
||||||
|
&self,
|
||||||
|
url: &str,
|
||||||
|
data: &UrlPreviewData,
|
||||||
|
) -> impl Future<Output = Result<()>> {
|
||||||
let now = SystemTime::now()
|
let now = SystemTime::now()
|
||||||
.duration_since(SystemTime::UNIX_EPOCH)
|
.duration_since(SystemTime::UNIX_EPOCH)
|
||||||
.expect("valid system time");
|
.expect("valid system time");
|
||||||
self.db.set_url_preview(url, data, now)
|
std::future::ready(self.db.set_url_preview(url, data, now))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_url_preview(&self, url: &Url) -> Result<UrlPreviewData> {
|
pub async fn get_url_preview(&self, url: &Url) -> Result<UrlPreviewData> {
|
||||||
|
|||||||
@@ -48,8 +48,10 @@ impl Data {
|
|||||||
.map_err(|_| err!(Request(NotFound("auth_chain not found"))))?;
|
.map_err(|_| err!(Request(NotFound("auth_chain not found"))))?;
|
||||||
|
|
||||||
let chain = chain
|
let chain = chain
|
||||||
.chunks_exact(size_of::<u64>())
|
.as_chunks::<{ size_of::<u64>() }>()
|
||||||
.map(utils::u64_from_u8)
|
.0
|
||||||
|
.iter()
|
||||||
|
.map(|s| utils::u64_from_u8(s))
|
||||||
.collect::<Arc<[u64]>>();
|
.collect::<Arc<[u64]>>();
|
||||||
|
|
||||||
// Cache in RAM
|
// Cache in RAM
|
||||||
|
|||||||
@@ -136,14 +136,14 @@ impl Service {
|
|||||||
|
|
||||||
/// Returns a stack with info on shortstatehash, full state, added diff and
|
/// Returns a stack with info on shortstatehash, full state, added diff and
|
||||||
/// removed diff for the selected shortstatehash and each parent layer.
|
/// removed diff for the selected shortstatehash and each parent layer.
|
||||||
async fn cache_shortstatehash_info(
|
fn cache_shortstatehash_info(
|
||||||
&self,
|
&self,
|
||||||
shortstatehash: ShortStateHash,
|
shortstatehash: ShortStateHash,
|
||||||
stack: ShortStateInfoVec,
|
stack: ShortStateInfoVec,
|
||||||
) -> Result {
|
) -> impl Future<Output = Result> {
|
||||||
self.stateinfo_cache.lock().insert(shortstatehash, stack);
|
self.stateinfo_cache.lock().insert(shortstatehash, stack);
|
||||||
|
|
||||||
Ok(())
|
std::future::ready(Ok(()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Inserts a new shortstatehash info entry.
|
/// Inserts a new shortstatehash info entry.
|
||||||
|
|||||||
@@ -82,8 +82,7 @@ impl super::Service {
|
|||||||
))));
|
))));
|
||||||
},
|
},
|
||||||
| StateEventType::RoomServerAcl =>
|
| StateEventType::RoomServerAcl =>
|
||||||
self.assert_allowed_to_send_room_server_acl_event(room_id, json)
|
self.assert_allowed_to_send_room_server_acl_event(room_id, json)?,
|
||||||
.await?,
|
|
||||||
| StateEventType::RoomEncryption =>
|
| StateEventType::RoomEncryption =>
|
||||||
// Forbid m.room.encryption if encryption is disabled
|
// Forbid m.room.encryption if encryption is disabled
|
||||||
if !self.services.config.allow_encryption {
|
if !self.services.config.allow_encryption {
|
||||||
@@ -109,7 +108,7 @@ impl super::Service {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn assert_allowed_to_send_room_server_acl_event(
|
fn assert_allowed_to_send_room_server_acl_event(
|
||||||
&self,
|
&self,
|
||||||
room_id: &RoomId,
|
room_id: &RoomId,
|
||||||
json: &Raw<AnyStateEventContent>,
|
json: &Raw<AnyStateEventContent>,
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ enum TransactionStatus {
|
|||||||
Retrying(u32), // number of times failed
|
Retrying(u32), // number of times failed
|
||||||
}
|
}
|
||||||
|
|
||||||
type SendingError = (Destination, Error);
|
type SendingError = (Destination, Box<Error>);
|
||||||
type SendingResult = Result<Destination, SendingError>;
|
type SendingResult = Result<Destination, SendingError>;
|
||||||
type SendingFuture<'a> = BoxFuture<'a, SendingResult>;
|
type SendingFuture<'a> = BoxFuture<'a, SendingResult>;
|
||||||
type SendingFutures<'a> = FuturesUnordered<SendingFuture<'a>>;
|
type SendingFutures<'a> = FuturesUnordered<SendingFuture<'a>>;
|
||||||
@@ -779,7 +779,7 @@ impl Service {
|
|||||||
let Some(appservice) = self.services.appservice.get_registration(&id).await else {
|
let Some(appservice) = self.services.appservice.get_registration(&id).await else {
|
||||||
return Err((
|
return Err((
|
||||||
Destination::Appservice(id.clone()),
|
Destination::Appservice(id.clone()),
|
||||||
err!(Database(warn!(?id, "Missing appservice registration"))),
|
Box::new(err!(Database(warn!(?id, "Missing appservice registration")))),
|
||||||
));
|
));
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -827,7 +827,7 @@ impl Service {
|
|||||||
|
|
||||||
match self.send_appservice_request(appservice, request).await {
|
match self.send_appservice_request(appservice, request).await {
|
||||||
| Ok(_) => Ok(Destination::Appservice(id)),
|
| Ok(_) => Ok(Destination::Appservice(id)),
|
||||||
| Err(e) => Err((Destination::Appservice(id), e)),
|
| Err(e) => Err((Destination::Appservice(id), Box::new(e))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -848,7 +848,7 @@ impl Service {
|
|||||||
let Ok(pusher) = self.services.pusher.get_pusher(&user_id, &pushkey).await else {
|
let Ok(pusher) = self.services.pusher.get_pusher(&user_id, &pushkey).await else {
|
||||||
return Err((
|
return Err((
|
||||||
Destination::Push(user_id.clone(), pushkey.clone()),
|
Destination::Push(user_id.clone(), pushkey.clone()),
|
||||||
err!(Database(error!(%user_id, ?pushkey, "Missing pusher"))),
|
Box::new(err!(Database(error!(%user_id, ?pushkey, "Missing pusher")))),
|
||||||
));
|
));
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -990,17 +990,17 @@ impl Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
| Err(error) => Err((Destination::Federation(server), error)),
|
| Err(error) => Err((Destination::Federation(server), Box::new(error))),
|
||||||
| Ok(_) => Ok(Destination::Federation(server)),
|
| Ok(_) => Ok(Destination::Federation(server)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts and sanitises an outgoing PDU object for federation
|
/// Converts and sanitises an outgoing PDU object for federation
|
||||||
/// transmission.
|
/// transmission.
|
||||||
pub async fn convert_to_outgoing_federation_event(
|
pub fn convert_to_outgoing_federation_event(
|
||||||
&self,
|
&self,
|
||||||
mut pdu_json: CanonicalJsonObject,
|
mut pdu_json: CanonicalJsonObject,
|
||||||
) -> Box<RawJsonValue> {
|
) -> impl Future<Output = Box<RawJsonValue>> {
|
||||||
if let Some(unsigned) = pdu_json
|
if let Some(unsigned) = pdu_json
|
||||||
.get_mut("unsigned")
|
.get_mut("unsigned")
|
||||||
.and_then(|val| val.as_object_mut())
|
.and_then(|val| val.as_object_mut())
|
||||||
@@ -1012,6 +1012,8 @@ impl Service {
|
|||||||
// so we can safely remove it here.
|
// so we can safely remove it here.
|
||||||
pdu_json.remove("event_id");
|
pdu_json.remove("event_id");
|
||||||
|
|
||||||
to_raw_value(&pdu_json).expect("CanonicalJson is valid serde_json::Value")
|
std::future::ready(
|
||||||
|
to_raw_value(&pdu_json).expect("CanonicalJson is valid serde_json::Value"),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -263,7 +263,7 @@ impl super::Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Updates device metadata and increments the device list version.
|
/// Updates device metadata and increments the device list version.
|
||||||
pub async fn update_device_metadata(
|
pub fn update_device_metadata(
|
||||||
&self,
|
&self,
|
||||||
user_id: &UserId,
|
user_id: &UserId,
|
||||||
device_id: &DeviceId,
|
device_id: &DeviceId,
|
||||||
|
|||||||
Reference in new issue
Block a user