more cleanup and refactoring and moving
move models.rs and schema.rs into database::inner create util module (with hash and jobs)feat/vaults
parent
754c315cd2
commit
2b6886645b
|
@ -1,4 +1,4 @@
|
||||||
use crate::hash::{decode, encode, Hash, Hashable};
|
use crate::util::hash::{decode, encode, Hash, Hashable};
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use serde::de::Visitor;
|
use serde::de::Visitor;
|
||||||
use serde::{de, ser, Deserialize, Deserializer, Serialize, Serializer};
|
use serde::{de, ser, Deserialize, Deserializer, Serialize, Serializer};
|
||||||
|
@ -135,7 +135,7 @@ mod tests {
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use crate::addressing::Address;
|
use crate::addressing::Address;
|
||||||
use crate::hash::Hash;
|
use crate::util::hash::Hash;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_hash_codec() {
|
fn test_hash_codec() {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::addressing::{Address, Addressable};
|
use crate::addressing::{Address, Addressable};
|
||||||
use crate::hash::{decode, hash, Hash, Hashable};
|
use crate::database::inner::models;
|
||||||
use crate::models;
|
use crate::util::hash::{decode, hash, Hash, Hashable};
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
pub mod models;
|
||||||
|
pub mod schema;
|
|
@ -2,7 +2,7 @@ use chrono::NaiveDateTime;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
use super::schema::{data, files};
|
use super::schema::{data, files};
|
||||||
use crate::hash::Hash;
|
use crate::util::hash::Hash;
|
||||||
|
|
||||||
#[derive(Queryable, Serialize, Debug)]
|
#[derive(Queryable, Serialize, Debug)]
|
||||||
pub struct File {
|
pub struct File {
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::addressing::Address;
|
use crate::addressing::Address;
|
||||||
use crate::database::entry::EntryValue;
|
use crate::database::entry::EntryValue;
|
||||||
use crate::schema::data;
|
use crate::database::inner::schema::data;
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use diesel::expression::operators::{And, Or};
|
use diesel::expression::operators::{And, Or};
|
||||||
use diesel::sql_types::Bool;
|
use diesel::sql_types::Bool;
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
pub mod constants;
|
pub mod constants;
|
||||||
pub mod entry;
|
pub mod entry;
|
||||||
|
pub mod inner;
|
||||||
pub mod lang;
|
pub mod lang;
|
||||||
|
|
||||||
use crate::addressing::Address;
|
use crate::addressing::Address;
|
||||||
|
@ -9,10 +10,10 @@ use crate::database::constants::{
|
||||||
IS_OF_TYPE_ATTR, TYPE_ADDR, TYPE_ID_ATTR, TYPE_INVARIANT, TYPE_IS_ATTR,
|
IS_OF_TYPE_ATTR, TYPE_ADDR, TYPE_ID_ATTR, TYPE_INVARIANT, TYPE_IS_ATTR,
|
||||||
};
|
};
|
||||||
use crate::database::entry::{Entry, EntryValue};
|
use crate::database::entry::{Entry, EntryValue};
|
||||||
|
use crate::database::inner::models;
|
||||||
|
use crate::database::inner::schema::data;
|
||||||
use crate::database::lang::Query;
|
use crate::database::lang::Query;
|
||||||
use crate::hash::{Hash, Hashable};
|
use crate::util::hash::{Hash, Hashable};
|
||||||
use crate::models;
|
|
||||||
use crate::schema::data;
|
|
||||||
use crate::util::LoggerSink;
|
use crate::util::LoggerSink;
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use diesel::debug_query;
|
use diesel::debug_query;
|
||||||
|
@ -59,7 +60,7 @@ pub fn insert_file<C: Connection<Backend = Sqlite>>(
|
||||||
connection: &C,
|
connection: &C,
|
||||||
file: models::NewFile,
|
file: models::NewFile,
|
||||||
) -> Result<usize> {
|
) -> Result<usize> {
|
||||||
use crate::schema::files;
|
use crate::database::inner::schema::files;
|
||||||
|
|
||||||
debug!(
|
debug!(
|
||||||
"Inserting {} ({})...",
|
"Inserting {} ({})...",
|
||||||
|
@ -76,7 +77,7 @@ pub fn retrieve_file<C: Connection<Backend = Sqlite>>(
|
||||||
connection: &C,
|
connection: &C,
|
||||||
obj_hash: Hash,
|
obj_hash: Hash,
|
||||||
) -> Result<Vec<models::File>> {
|
) -> Result<Vec<models::File>> {
|
||||||
use crate::schema::files::dsl::*;
|
use crate::database::inner::schema::files::dsl::*;
|
||||||
|
|
||||||
let matches = files
|
let matches = files
|
||||||
.filter(valid.eq(true))
|
.filter(valid.eq(true))
|
||||||
|
@ -89,7 +90,7 @@ pub fn retrieve_file<C: Connection<Backend = Sqlite>>(
|
||||||
pub fn retrieve_all_files<C: Connection<Backend = Sqlite>>(
|
pub fn retrieve_all_files<C: Connection<Backend = Sqlite>>(
|
||||||
connection: &C,
|
connection: &C,
|
||||||
) -> Result<Vec<models::File>> {
|
) -> Result<Vec<models::File>> {
|
||||||
use crate::schema::files::dsl::*;
|
use crate::database::inner::schema::files::dsl::*;
|
||||||
let matches = files.load::<models::File>(connection)?;
|
let matches = files.load::<models::File>(connection)?;
|
||||||
Ok(matches)
|
Ok(matches)
|
||||||
}
|
}
|
||||||
|
@ -98,7 +99,7 @@ pub fn get_latest_files<C: Connection<Backend = Sqlite>>(
|
||||||
connection: &C,
|
connection: &C,
|
||||||
count: i64,
|
count: i64,
|
||||||
) -> Result<Vec<models::File>> {
|
) -> Result<Vec<models::File>> {
|
||||||
use crate::schema::files::dsl::*;
|
use crate::database::inner::schema::files::dsl::*;
|
||||||
|
|
||||||
let matches = files
|
let matches = files
|
||||||
.order_by(added.desc())
|
.order_by(added.desc())
|
||||||
|
@ -113,7 +114,7 @@ pub fn file_set_valid<C: Connection<Backend = Sqlite>>(
|
||||||
file_id: i32,
|
file_id: i32,
|
||||||
is_valid: bool,
|
is_valid: bool,
|
||||||
) -> Result<usize> {
|
) -> Result<usize> {
|
||||||
use crate::schema::files::dsl::*;
|
use crate::database::inner::schema::files::dsl::*;
|
||||||
|
|
||||||
debug!("Setting file ID {} to valid = {}", file_id, is_valid);
|
debug!("Setting file ID {} to valid = {}", file_id, is_valid);
|
||||||
|
|
||||||
|
@ -126,7 +127,7 @@ pub fn retrieve_object<C: Connection<Backend = Sqlite>>(
|
||||||
connection: &C,
|
connection: &C,
|
||||||
object_address: Address,
|
object_address: Address,
|
||||||
) -> Result<Vec<Entry>> {
|
) -> Result<Vec<Entry>> {
|
||||||
use crate::schema::data::dsl::*;
|
use crate::database::inner::schema::data::dsl::*;
|
||||||
|
|
||||||
let matches = data
|
let matches = data
|
||||||
.filter(entity.eq(object_address.encode()?))
|
.filter(entity.eq(object_address.encode()?))
|
||||||
|
@ -145,7 +146,7 @@ pub fn bulk_retrieve_objects<C: Connection<Backend = Sqlite>>(
|
||||||
connection: &C,
|
connection: &C,
|
||||||
object_addresses: Vec<Address>,
|
object_addresses: Vec<Address>,
|
||||||
) -> Result<Vec<Entry>> {
|
) -> Result<Vec<Entry>> {
|
||||||
use crate::schema::data::dsl::*;
|
use crate::database::inner::schema::data::dsl::*;
|
||||||
|
|
||||||
let matches = data
|
let matches = data
|
||||||
.filter(
|
.filter(
|
||||||
|
@ -170,7 +171,7 @@ pub fn remove_object<C: Connection<Backend = Sqlite>>(
|
||||||
connection: &C,
|
connection: &C,
|
||||||
object_address: Address,
|
object_address: Address,
|
||||||
) -> Result<usize> {
|
) -> Result<usize> {
|
||||||
use crate::schema::data::dsl::*;
|
use crate::database::inner::schema::data::dsl::*;
|
||||||
|
|
||||||
debug!("Deleting {}!", object_address);
|
debug!("Deleting {}!", object_address);
|
||||||
|
|
||||||
|
@ -183,7 +184,7 @@ pub fn remove_object<C: Connection<Backend = Sqlite>>(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn query<C: Connection<Backend = Sqlite>>(connection: &C, query: Query) -> Result<Vec<Entry>> {
|
pub fn query<C: Connection<Backend = Sqlite>>(connection: &C, query: Query) -> Result<Vec<Entry>> {
|
||||||
use crate::schema::data::dsl::*;
|
use crate::database::inner::schema::data::dsl::*;
|
||||||
|
|
||||||
trace!("Querying: {:?}", query);
|
trace!("Querying: {:?}", query);
|
||||||
|
|
||||||
|
|
|
@ -4,15 +4,14 @@ use crate::database::constants::{
|
||||||
TYPE_REQUIRES_ATTR,
|
TYPE_REQUIRES_ATTR,
|
||||||
};
|
};
|
||||||
use crate::database::entry::{Entry, EntryValue, InvariantEntry};
|
use crate::database::entry::{Entry, EntryValue, InvariantEntry};
|
||||||
|
use crate::database::inner::models;
|
||||||
use crate::database::lang::{EntryQuery, Query, QueryComponent, QueryPart};
|
use crate::database::lang::{EntryQuery, Query, QueryComponent, QueryPart};
|
||||||
use crate::database::{
|
use crate::database::{
|
||||||
bulk_retrieve_objects, file_set_valid, insert_entry, insert_file, query, retrieve_all_files,
|
bulk_retrieve_objects, file_set_valid, insert_entry, insert_file, query, retrieve_all_files,
|
||||||
DbPool, DATABASE_FILENAME,
|
DbPool, DATABASE_FILENAME,
|
||||||
};
|
};
|
||||||
use crate::hash::Hashable;
|
use crate::util::hash::Hashable;
|
||||||
use crate::jobs::{Job, JobContainer, JobId, State};
|
use crate::util::jobs::{Job, JobContainer, JobId, State};
|
||||||
use crate::models;
|
|
||||||
use crate::models::File;
|
|
||||||
use anyhow::{anyhow, Error, Result};
|
use anyhow::{anyhow, Error, Result};
|
||||||
use chrono::prelude::*;
|
use chrono::prelude::*;
|
||||||
use diesel::sqlite::Sqlite;
|
use diesel::sqlite::Sqlite;
|
||||||
|
@ -504,7 +503,7 @@ fn _process_directory_entry<P: AsRef<Path>>(
|
||||||
db_pool: &Arc<RwLock<DbPool>>,
|
db_pool: &Arc<RwLock<DbPool>>,
|
||||||
path: PathBuf,
|
path: PathBuf,
|
||||||
directory_path: &P,
|
directory_path: &P,
|
||||||
existing_files: &Arc<RwLock<Vec<File>>>,
|
existing_files: &Arc<RwLock<Vec<models::File>>>,
|
||||||
) -> UpdatePathResult {
|
) -> UpdatePathResult {
|
||||||
info!("Processing: {:?}", path);
|
info!("Processing: {:?}", path);
|
||||||
|
|
||||||
|
|
|
@ -18,11 +18,7 @@ use std::sync::{Arc, RwLock};
|
||||||
mod addressing;
|
mod addressing;
|
||||||
mod database;
|
mod database;
|
||||||
mod filesystem;
|
mod filesystem;
|
||||||
mod hash;
|
|
||||||
mod jobs;
|
|
||||||
mod models;
|
|
||||||
mod routes;
|
mod routes;
|
||||||
mod schema;
|
|
||||||
mod util;
|
mod util;
|
||||||
|
|
||||||
const VERSION: &str = env!("CARGO_PKG_VERSION");
|
const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||||
|
@ -75,7 +71,7 @@ fn main() -> Result<()> {
|
||||||
info!("Starting UpEnd {}...", VERSION);
|
info!("Starting UpEnd {}...", VERSION);
|
||||||
let sys = actix::System::new("upend");
|
let sys = actix::System::new("upend");
|
||||||
|
|
||||||
let job_container = Arc::new(RwLock::new(jobs::JobContainer::default()));
|
let job_container = Arc::new(RwLock::new(util::jobs::JobContainer::default()));
|
||||||
|
|
||||||
let vault_path = PathBuf::from(matches.value_of("DIRECTORY").unwrap());
|
let vault_path = PathBuf::from(matches.value_of("DIRECTORY").unwrap());
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,8 @@ use crate::database::{
|
||||||
get_latest_files, insert_entry, query, remove_object, retrieve_file, retrieve_object, DbPool,
|
get_latest_files, insert_entry, query, remove_object, retrieve_file, retrieve_object, DbPool,
|
||||||
};
|
};
|
||||||
use crate::filesystem::{list_directory, UPath};
|
use crate::filesystem::{list_directory, UPath};
|
||||||
use crate::hash::{decode, encode};
|
use crate::util::hash::{decode, encode};
|
||||||
use crate::jobs::JobContainer;
|
use crate::util::jobs::JobContainer;
|
||||||
use actix_files::NamedFile;
|
use actix_files::NamedFile;
|
||||||
use actix_web::error::{ErrorBadRequest, ErrorInternalServerError, ErrorNotFound};
|
use actix_web::error::{ErrorBadRequest, ErrorInternalServerError, ErrorNotFound};
|
||||||
use actix_web::{delete, error, get, post, put, web, Error, HttpResponse};
|
use actix_web::{delete, error, get, post, put, web, Error, HttpResponse};
|
||||||
|
|
|
@ -103,7 +103,7 @@ pub fn decode<T: AsRef<str>>(string: T) -> Result<Vec<u8>> {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::hash::{decode, encode};
|
use crate::util::hash::{decode, encode};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_encode_decode() {
|
fn test_encode_decode() {
|
|
@ -1,3 +1,6 @@
|
||||||
|
pub mod hash;
|
||||||
|
pub mod jobs;
|
||||||
|
|
||||||
use log::debug;
|
use log::debug;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
Loading…
Reference in New Issue