cargo clippy and fmt

This commit is contained in:
xenofem 2022-04-28 05:18:35 -04:00
parent 127d7e9c67
commit bda6da33e8
6 changed files with 129 additions and 68 deletions

View file

@ -1,6 +1,6 @@
use std::{collections::HashSet, io::Write, task::Waker};
use actix::{Actor, ActorContext, AsyncContext, StreamHandler, Message, Handler};
use actix::{Actor, ActorContext, AsyncContext, Handler, Message, StreamHandler};
use actix_http::ws::{CloseReason, Item};
use actix_web_actors::ws::{self, CloseCode};
use bytes::Bytes;
@ -82,7 +82,11 @@ pub(crate) struct WakerMessage(pub Waker);
impl Handler<WakerMessage> for Uploader {
type Result = ();
fn handle(&mut self, msg: WakerMessage, _: &mut Self::Context) {
self.writer.as_mut().map(|w| w.add_waker(msg.0));
if let Some(w) = self.writer.as_mut() {
w.add_waker(msg.0);
} else {
error!("Got a wakeup request before creating a file");
}
}
}
@ -198,36 +202,38 @@ impl Uploader {
let size = zip_writer.total_size();
let download_filename =
super::APP_NAME.to_owned() + &now.format(FILENAME_DATE_FORMAT)? + ".zip";
(Box::new(zip_writer), DownloadableFile {
name: download_filename,
size,
modtime: now,
uploader: addr,
})
(
Box::new(zip_writer),
DownloadableFile {
name: download_filename,
size,
modtime: now,
uploader: addr,
},
)
} else {
(Box::new(writer), DownloadableFile {
name: files[0].name.clone(),
size: files[0].size,
modtime: files[0].modtime,
uploader: addr,
})
(
Box::new(writer),
DownloadableFile {
name: files[0].name.clone(),
size: files[0].size,
modtime: files[0].modtime,
uploader: addr,
},
)
};
self.writer = Some(writer);
let data = self.app_data.clone();
let storage_filename_copy = storage_filename.clone();
ctx.spawn(actix::fut::wrap_future(async move {
data
.write()
data.write()
.await
.add_file(
storage_filename_copy,
downloadable_file,
).await.unwrap();
.add_file(storage_filename, downloadable_file)
.await
.unwrap();
}));
ctx.text(self.storage_filename.as_str());
}
ws::Message::Binary(data)
| ws::Message::Continuation(Item::Last(data)) => {
ws::Message::Binary(data) | ws::Message::Continuation(Item::Last(data)) => {
let result = self.handle_data(data)?;
ack(ctx);
return Ok(result);
@ -272,10 +278,7 @@ impl Uploader {
let data = self.app_data.clone();
let filename = self.storage_filename.clone();
ctx.spawn(actix::fut::wrap_future(async move {
data
.write()
.await
.remove_file(&filename).await.unwrap();
data.write().await.remove_file(&filename).await.unwrap();
}));
}
}