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
107
src/state.rs
107
src/state.rs
|
@ -1,12 +1,109 @@
|
|||
use jsondb::JsonDb;
|
||||
|
||||
mod v0 {
|
||||
pub type State = crate::store::StoredFiles;
|
||||
mod prelude {
|
||||
pub use std::collections::HashMap;
|
||||
|
||||
impl jsondb::SchemaV0 for State {
|
||||
const VERSION_OPTIONAL: bool = true;
|
||||
pub use jsondb::Schema;
|
||||
pub use serde::{Deserialize, Serialize};
|
||||
pub use serde_with::serde_as;
|
||||
pub use serde_with::skip_serializing_none;
|
||||
pub use time::OffsetDateTime;
|
||||
}
|
||||
|
||||
mod v0;
|
||||
|
||||
pub mod v1 {
|
||||
//! Schema version 1
|
||||
//!
|
||||
//! Changes:
|
||||
//!
|
||||
//! * Represent times in RFC3339 format instead of epoch seconds
|
||||
//! * Ditch some pre-JsonDb ad-hoc migrations
|
||||
//! * Stored files now have optional passwords for
|
||||
//! deleting/extending them, stored in plaintext because the
|
||||
//! threat model doesn't warrant anything stronger
|
||||
|
||||
use super::prelude::*;
|
||||
|
||||
#[serde_as]
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
pub struct UploadedFile {
|
||||
pub name: String,
|
||||
pub size: u64,
|
||||
#[serde_as(as = "time::format_description::well_known::Rfc3339")]
|
||||
pub modtime: OffsetDateTime,
|
||||
}
|
||||
impl From<super::v0::UploadedFile> for UploadedFile {
|
||||
fn from(old: super::v0::UploadedFile) -> Self {
|
||||
UploadedFile {
|
||||
name: old.name,
|
||||
size: old.size,
|
||||
modtime: old.modtime,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
pub struct FileSet {
|
||||
pub files: Vec<UploadedFile>,
|
||||
// Optional for backwards compatibility only
|
||||
pub directory_name: Option<String>,
|
||||
}
|
||||
impl From<super::v0::FileSet> for FileSet {
|
||||
fn from(old: super::v0::FileSet) -> Self {
|
||||
FileSet {
|
||||
files: old.files.into_iter().map(UploadedFile::from).collect(),
|
||||
directory_name: old.directory_name,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[serde_as]
|
||||
#[skip_serializing_none]
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
pub struct StoredFile {
|
||||
pub name: String,
|
||||
pub size: u64,
|
||||
#[serde_as(as = "time::format_description::well_known::Rfc3339")]
|
||||
pub modtime: OffsetDateTime,
|
||||
#[serde_as(as = "time::format_description::well_known::Rfc3339")]
|
||||
pub expiry: OffsetDateTime,
|
||||
pub contents: Option<FileSet>,
|
||||
/// None password means the admin page can't be accessed
|
||||
pub password: Option<String>,
|
||||
}
|
||||
impl From<super::v0::StoredFile> for StoredFile {
|
||||
fn from(old: super::v0::StoredFile) -> Self {
|
||||
StoredFile {
|
||||
name: old.name,
|
||||
size: old.size,
|
||||
modtime: old.modtime,
|
||||
expiry: old.expiry,
|
||||
contents: old.contents.map(FileSet::from),
|
||||
password: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Deserialize, Serialize)]
|
||||
pub struct StoredFiles(pub HashMap<String, StoredFile>);
|
||||
|
||||
pub type State = StoredFiles;
|
||||
|
||||
impl Schema for State {
|
||||
type Prev = super::v0::State;
|
||||
}
|
||||
impl From<super::v0::State> for State {
|
||||
fn from(old: super::v0::State) -> Self {
|
||||
StoredFiles(
|
||||
old.0
|
||||
.into_iter()
|
||||
.map(|(k, v)| (k, StoredFile::from(v)))
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub use v0::State;
|
||||
pub use v1::State;
|
||||
pub type StateDb = JsonDb<State>;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue