move state to jsondb
This commit is contained in:
parent
446c0f0264
commit
073feda920
8 changed files with 145 additions and 143 deletions
|
@ -15,7 +15,7 @@ use crate::{
|
|||
log_auth_failure,
|
||||
store::{self, FileAddError, StoredFile},
|
||||
zip::FileSet,
|
||||
AppState,
|
||||
AppData,
|
||||
};
|
||||
|
||||
const MAX_FILES: usize = 256;
|
||||
|
@ -86,17 +86,17 @@ impl Error {
|
|||
pub struct Uploader {
|
||||
writer: Option<Box<dyn Write>>,
|
||||
storage_filename: String,
|
||||
app_state: web::Data<AppState>,
|
||||
app_data: web::Data<AppData>,
|
||||
bytes_remaining: u64,
|
||||
ip_addr: String,
|
||||
}
|
||||
|
||||
impl Uploader {
|
||||
pub(crate) fn new(app_state: web::Data<AppState>, ip_addr: String) -> Self {
|
||||
pub(crate) fn new(app_data: web::Data<AppData>, ip_addr: String) -> Self {
|
||||
Self {
|
||||
writer: None,
|
||||
storage_filename: store::gen_storage_code(app_state.config.mnemonic_codes),
|
||||
app_state,
|
||||
storage_filename: store::gen_storage_code(app_data.config.mnemonic_codes),
|
||||
app_data,
|
||||
bytes_remaining: 0,
|
||||
ip_addr,
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ impl Actor for Uploader {
|
|||
|
||||
type Context = <Uploader as Actor>::Context;
|
||||
|
||||
#[derive(Clone, Deserialize, Serialize)]
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
pub struct UploadedFile {
|
||||
pub name: String,
|
||||
pub size: u64,
|
||||
|
@ -251,8 +251,8 @@ impl Uploader {
|
|||
if std::env::var("TRANSBEAM_UPLOAD_PASSWORD") != Ok(password) {
|
||||
return Err(Error::IncorrectPassword);
|
||||
}
|
||||
if lifetime > self.app_state.config.max_lifetime {
|
||||
return Err(Error::TooLong(self.app_state.config.max_lifetime));
|
||||
if lifetime > self.app_data.config.max_lifetime {
|
||||
return Err(Error::TooLong(self.app_data.config.max_lifetime));
|
||||
}
|
||||
info!("Received file list: {} files", raw_files.len());
|
||||
debug!("{:?}", raw_files);
|
||||
|
@ -277,11 +277,11 @@ impl Uploader {
|
|||
self.bytes_remaining += file.size;
|
||||
files.push(file);
|
||||
}
|
||||
if self.bytes_remaining > self.app_state.config.max_upload_size {
|
||||
return Err(Error::TooBig(self.app_state.config.max_upload_size));
|
||||
if self.bytes_remaining > self.app_data.config.max_upload_size {
|
||||
return Err(Error::TooBig(self.app_data.config.max_upload_size));
|
||||
}
|
||||
let storage_path = self
|
||||
.app_state
|
||||
.app_data
|
||||
.config
|
||||
.storage_dir
|
||||
.join(self.storage_filename.clone());
|
||||
|
@ -329,15 +329,12 @@ impl Uploader {
|
|||
expiry: OffsetDateTime::now_utc() + lifetime * time::Duration::DAY,
|
||||
contents,
|
||||
};
|
||||
let state = self.app_state.clone();
|
||||
let app_data = self.app_data.clone();
|
||||
let storage_filename = self.storage_filename.clone();
|
||||
ctx.spawn(
|
||||
actix::fut::wrap_future(async move {
|
||||
debug!("Spawned future to add entry {} to state", storage_filename);
|
||||
state
|
||||
.file_store
|
||||
.write()
|
||||
.await
|
||||
app_data
|
||||
.add_file(storage_filename, stored_file)
|
||||
.await
|
||||
})
|
||||
|
@ -404,15 +401,12 @@ impl Uploader {
|
|||
"Cleaning up after failed upload of {}",
|
||||
self.storage_filename
|
||||
);
|
||||
let state = self.app_state.clone();
|
||||
let app_data = self.app_data.clone();
|
||||
let filename = self.storage_filename.clone();
|
||||
ctx.wait(
|
||||
actix::fut::wrap_future(async move {
|
||||
debug!("Spawned future to remove entry {} from state", filename);
|
||||
state
|
||||
.file_store
|
||||
.write()
|
||||
.await
|
||||
app_data
|
||||
.remove_file(&filename)
|
||||
.await
|
||||
.unwrap();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue