remove InnerEntry, consolidate into Entry
parent
2b42f4dc1a
commit
99f6c6c052
|
@ -25,14 +25,6 @@ use std::time::Duration;
|
|||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Entry {
|
||||
pub identity: Hash,
|
||||
pub target: Address,
|
||||
pub key: String,
|
||||
pub value: EntryValue,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct InnerEntry {
|
||||
pub target: Address,
|
||||
pub key: String,
|
||||
pub value: EntryValue,
|
||||
|
@ -64,7 +56,6 @@ impl TryFrom<models::Entry> for Entry {
|
|||
|
||||
fn try_from(e: models::Entry) -> Result<Self, Self::Error> {
|
||||
Ok(Entry {
|
||||
identity: Hash(e.identity),
|
||||
target: Address::decode(&e.target)?,
|
||||
key: e.key,
|
||||
value: e.value.parse().unwrap(),
|
||||
|
@ -72,14 +63,14 @@ impl TryFrom<models::Entry> for Entry {
|
|||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for InnerEntry {
|
||||
impl std::fmt::Display for Entry {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{} | {} | {}", self.target, self.key, self.value)
|
||||
}
|
||||
}
|
||||
|
||||
impl Hashable for InnerEntry {
|
||||
fn hash(self: &InnerEntry) -> Result<Hash> {
|
||||
impl Hashable for Entry {
|
||||
fn hash(self: &Entry) -> Result<Hash> {
|
||||
let mut result = Cursor::new(vec![0u8; 0]);
|
||||
result.write_all(self.target.encode()?.as_slice())?;
|
||||
result.write_all(self.key.as_bytes())?;
|
||||
|
@ -618,7 +609,7 @@ pub fn query_entries<C: Connection<Backend = Sqlite>>(
|
|||
|
||||
pub fn insert_entry<C: Connection<Backend = Sqlite>>(
|
||||
connection: &C,
|
||||
entry: InnerEntry,
|
||||
entry: Entry,
|
||||
) -> Result<usize> {
|
||||
debug!("Inserting: {}", entry);
|
||||
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
use crate::addressing::Address;
|
||||
use crate::database::{
|
||||
bulk_retrieve_objects, file_set_valid, insert_entry, insert_file, query_entries,
|
||||
retrieve_all_files, DbPool, Entry, EntryQuery, EntryValue, InnerEntry, QueryComponent,
|
||||
DATABASE_FILENAME,
|
||||
retrieve_all_files, DbPool, Entry, EntryQuery, EntryValue, QueryComponent, DATABASE_FILENAME,
|
||||
};
|
||||
use crate::hash::Hashable;
|
||||
use crate::models;
|
||||
|
@ -234,7 +233,7 @@ pub fn fetch_or_create_dir<C: Connection<Backend = Sqlite>>(
|
|||
0 => {
|
||||
if create {
|
||||
let new_directory_address = Address::UUID(Uuid::new_v4());
|
||||
let directory_entry = InnerEntry {
|
||||
let directory_entry = Entry {
|
||||
target: new_directory_address.clone(),
|
||||
key: String::from(DIR_KEY),
|
||||
value: dir_value,
|
||||
|
@ -242,7 +241,7 @@ pub fn fetch_or_create_dir<C: Connection<Backend = Sqlite>>(
|
|||
let _ = insert_entry(connection, directory_entry)?;
|
||||
|
||||
if let Some(parent_addr) = parent {
|
||||
let has_entry = InnerEntry {
|
||||
let has_entry = Entry {
|
||||
target: parent_addr,
|
||||
key: String::from(DIR_HAS_KEY),
|
||||
value: EntryValue::Address(new_directory_address.clone()),
|
||||
|
@ -434,7 +433,7 @@ fn _process_directory_entry<P: AsRef<Path>>(
|
|||
connection.transaction::<_, Error, _>(|| {
|
||||
let file_address = Address::UUID(Uuid::new_v4());
|
||||
|
||||
let name_entry = InnerEntry {
|
||||
let name_entry = Entry {
|
||||
target: file_address.clone(),
|
||||
key: FILENAME_KEY.to_string(),
|
||||
value: EntryValue::Value(Value::String(
|
||||
|
@ -443,7 +442,7 @@ fn _process_directory_entry<P: AsRef<Path>>(
|
|||
};
|
||||
let _ = insert_entry(&connection, name_entry)?;
|
||||
|
||||
let identity_entry = InnerEntry {
|
||||
let identity_entry = Entry {
|
||||
target: file_address.clone(),
|
||||
key: FILE_IDENTITY_KEY.to_string(),
|
||||
value: EntryValue::Address(Address::Hash(digest.clone())),
|
||||
|
@ -451,7 +450,7 @@ fn _process_directory_entry<P: AsRef<Path>>(
|
|||
|
||||
let _ = insert_entry(&connection, identity_entry)?;
|
||||
|
||||
let dir_has_entry = InnerEntry {
|
||||
let dir_has_entry = Entry {
|
||||
target: parent_dir.clone(),
|
||||
key: DIR_HAS_KEY.to_string(),
|
||||
value: EntryValue::Address(file_address),
|
||||
|
|
|
@ -7,6 +7,12 @@ use tiny_keccak::{Hasher, KangarooTwelve};
|
|||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct Hash(pub Vec<u8>);
|
||||
|
||||
impl AsRef<[u8]> for Hash {
|
||||
fn as_ref(&self) -> &[u8] {
|
||||
self.0.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
// impl Hash {
|
||||
// pub fn encode(&self) -> String {
|
||||
// encode(self.0.clone()).into_string()
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::addressing::Address;
|
||||
use crate::database::{query, remove_object, retrieve_file, retrieve_object, DbPool, Entry, Query};
|
||||
use crate::filesystem::{list_directory, lookup_by_filename, UPath};
|
||||
use crate::hash::{decode, encode};
|
||||
use crate::hash::{decode, encode, Hashable};
|
||||
use actix_files::NamedFile;
|
||||
use actix_web::error::{ErrorBadRequest, ErrorInternalServerError, ErrorNotFound};
|
||||
use actix_web::{delete, error, get, post, web, Error, HttpResponse};
|
||||
|
@ -55,7 +55,10 @@ pub async fn get_object(
|
|||
|
||||
let mut result: HashMap<String, serde_json::Value> = HashMap::new();
|
||||
for entry in response.map_err(error::ErrorInternalServerError)? {
|
||||
result.insert(encode(&entry.identity.0), entry.as_json());
|
||||
result.insert(
|
||||
encode(entry.hash().map_err(ErrorInternalServerError)?),
|
||||
entry.as_json(),
|
||||
);
|
||||
}
|
||||
Ok(HttpResponse::Ok().json(result))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue