make cosmetic changes to state schema, add fileset passwords for forthcoming functionality
This commit is contained in:
parent
073feda920
commit
aef58d133b
9 changed files with 327 additions and 119 deletions
34
src/store.rs
34
src/store.rs
|
|
@ -1,7 +1,7 @@
|
|||
use std::{
|
||||
collections::HashMap,
|
||||
io::ErrorKind,
|
||||
path::{Path, PathBuf}, ops::DerefMut,
|
||||
ops::DerefMut,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use log::{debug, error, info};
|
||||
|
|
@ -9,15 +9,9 @@ use rand::{
|
|||
distributions::{Alphanumeric, DistString},
|
||||
thread_rng, Rng,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_with::skip_serializing_none;
|
||||
use serde_with::{serde_as, FromInto, PickFirst};
|
||||
use time::OffsetDateTime;
|
||||
use tokio::fs::File;
|
||||
|
||||
use crate::upload::UploadedFile;
|
||||
use crate::zip::FileSet;
|
||||
|
||||
const MAX_STORAGE_FILES: usize = 1024;
|
||||
|
||||
pub fn gen_storage_code(use_mnemonic: bool) -> String {
|
||||
|
|
@ -34,23 +28,7 @@ pub fn is_valid_storage_code(s: &str) -> bool {
|
|||
.all(|c| c.is_ascii_alphanumeric() || c == &b'-')
|
||||
}
|
||||
|
||||
#[serde_as]
|
||||
#[skip_serializing_none]
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
pub struct StoredFile {
|
||||
pub name: String,
|
||||
pub size: u64,
|
||||
#[serde(with = "crate::timestamp")]
|
||||
pub modtime: OffsetDateTime,
|
||||
#[serde(with = "crate::timestamp")]
|
||||
pub expiry: OffsetDateTime,
|
||||
#[serde_as(as = "Option<PickFirst<(_, FromInto<Vec<UploadedFile>>)>>")]
|
||||
#[serde(default)]
|
||||
pub contents: Option<FileSet>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Deserialize, Serialize)]
|
||||
pub struct StoredFiles(pub HashMap<String, StoredFile>);
|
||||
pub use crate::state::v1::{StoredFile, StoredFiles};
|
||||
|
||||
async fn is_valid_entry(key: &str, info: &StoredFile, storage_dir: &Path) -> bool {
|
||||
if info.expiry < OffsetDateTime::now_utc() {
|
||||
|
|
@ -130,11 +108,7 @@ impl crate::AppData {
|
|||
/// Attempts to add a file to the store. Returns an I/O error if
|
||||
/// something's broken, or a u64 of the maximum allowed file size
|
||||
/// if the file was too big, or a unit if everything worked.
|
||||
pub async fn add_file(
|
||||
&self,
|
||||
key: String,
|
||||
file: StoredFile,
|
||||
) -> Result<(), FileAddError> {
|
||||
pub async fn add_file(&self, key: String, file: StoredFile) -> Result<(), FileAddError> {
|
||||
let mut store = self.state.write().await;
|
||||
if store.full(self.config.max_storage_size) {
|
||||
return Err(FileAddError::Full);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue