mirror of
https://github.com/spacedriveapp/spacedrive
synced 2024-07-02 08:53:32 +00:00
getting somewhere?
This commit is contained in:
parent
338b1eb0d3
commit
7c516fbd25
22
src-tauri/Cargo.lock
generated
22
src-tauri/Cargo.lock
generated
|
@ -1175,6 +1175,19 @@ dependencies = [
|
|||
"syn 1.0.74",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "env_logger"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b2cf0344971ee6c64c31be0d530793fba457d322dfec2810c453d0ef228f9c3"
|
||||
dependencies = [
|
||||
"atty",
|
||||
"humantime",
|
||||
"log",
|
||||
"regex",
|
||||
"termcolor",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "env_proxy"
|
||||
version = "0.4.1"
|
||||
|
@ -1812,6 +1825,12 @@ dependencies = [
|
|||
"itoa",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "humantime"
|
||||
version = "2.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
|
||||
|
||||
[[package]]
|
||||
name = "ico"
|
||||
version = "0.1.0"
|
||||
|
@ -3328,8 +3347,10 @@ dependencies = [
|
|||
"chrono",
|
||||
"crossbeam",
|
||||
"data-encoding",
|
||||
"env_logger",
|
||||
"futures",
|
||||
"int-enum",
|
||||
"log",
|
||||
"rebind",
|
||||
"refinery",
|
||||
"ring 0.17.0-alpha.10",
|
||||
|
@ -3354,6 +3375,7 @@ dependencies = [
|
|||
"chrono",
|
||||
"futures",
|
||||
"futures-util",
|
||||
"log",
|
||||
"rust_decimal",
|
||||
"sea-orm-macros",
|
||||
"sea-query",
|
||||
|
|
|
@ -28,7 +28,9 @@ int-enum = "0.4.0"
|
|||
rusqlite = "0.25.3"
|
||||
refinery = { version = "0.6.0", features = ["rusqlite"] }
|
||||
sqlx = { version = "0.5.7", features = ["sqlite"] }
|
||||
sea-orm = { version = "^0", features = [ "sqlx-sqlite", "runtime-async-std-rustls", "macros" ], default-features = false }
|
||||
sea-orm = { version = "^0", features = [ "sqlx-sqlite", "runtime-async-std-rustls", "macros", "debug-print" ], default-features = false }
|
||||
env_logger = "0.9.0"
|
||||
log = "0.4.14"
|
||||
|
||||
[features]
|
||||
default = [ "custom-protocol" ]
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use crate::filesystem::checksum;
|
||||
// use crate::filesystem::checksum;
|
||||
use crate::filesystem::file;
|
||||
use crate::filesystem::file::File;
|
||||
|
||||
use tauri::InvokeError;
|
||||
|
||||
|
|
41
src-tauri/src/db/entity/file.rs
Normal file
41
src-tauri/src/db/entity/file.rs
Normal file
|
@ -0,0 +1,41 @@
|
|||
use chrono::NaiveDateTime;
|
||||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
// -------------------------------------
|
||||
// Entity: File
|
||||
// Represents an item discovered on the filesystem
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, DeriveEntityModel, Default)]
|
||||
#[sea_orm(table_name = "files")]
|
||||
// -------------------------------------
|
||||
pub struct Model {
|
||||
// identity
|
||||
#[sea_orm(primary_key)]
|
||||
pub id: u32,
|
||||
pub buffer_checksum: String,
|
||||
pub meta_checksum: String,
|
||||
pub uri: String,
|
||||
// metadata
|
||||
pub name: String,
|
||||
pub extension: String,
|
||||
pub size_in_bytes: String,
|
||||
// pub encryption: crypto::Encryption,
|
||||
#[sea_orm(nullable)]
|
||||
pub ipfs_id: Option<String>,
|
||||
// ownership
|
||||
#[sea_orm(nullable)]
|
||||
pub storage_device_id: Option<u32>,
|
||||
#[sea_orm(nullable)]
|
||||
pub capture_device_id: Option<u32>,
|
||||
#[sea_orm(nullable)]
|
||||
pub parent_file_id: Option<u32>,
|
||||
// date
|
||||
pub date_created: Option<NaiveDateTime>,
|
||||
pub date_modified: Option<NaiveDateTime>,
|
||||
pub date_indexed: Option<NaiveDateTime>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
1
src-tauri/src/db/entity/mod.rs
Normal file
1
src-tauri/src/db/entity/mod.rs
Normal file
|
@ -0,0 +1 @@
|
|||
pub mod file;
|
|
@ -1,2 +1,3 @@
|
|||
pub mod connection;
|
||||
pub mod entity;
|
||||
// pub mod migrate;
|
||||
|
|
|
@ -1,87 +1,59 @@
|
|||
use crate::crypto;
|
||||
use crate::db;
|
||||
use crate::filesystem::checksum;
|
||||
use crate::util::time;
|
||||
use chrono::{NaiveDateTime, Utc};
|
||||
use sea_orm::entity::prelude::*;
|
||||
use sea_orm::entity::*;
|
||||
use sea_orm::InsertResult;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sea_orm::QueryFilter;
|
||||
use std::ffi::OsStr;
|
||||
use std::fs;
|
||||
use std::io;
|
||||
use std::path;
|
||||
|
||||
// -------------------------------------
|
||||
// Entity: File
|
||||
// Represents an item discovered on the filesystem
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, DeriveEntityModel)]
|
||||
#[sea_orm(table_name = "files")]
|
||||
// -------------------------------------
|
||||
pub struct Model {
|
||||
// identity
|
||||
#[sea_orm(primary_key)]
|
||||
pub id: u32,
|
||||
pub buffer_checksum: String,
|
||||
pub meta_checksum: String,
|
||||
pub uri: String,
|
||||
// metadata
|
||||
pub name: String,
|
||||
pub extension: String,
|
||||
pub size_in_bytes: String,
|
||||
// pub encryption: crypto::Encryption,
|
||||
#[sea_orm(nullable)]
|
||||
pub ipfs_id: Option<String>,
|
||||
// ownership
|
||||
#[sea_orm(nullable)]
|
||||
pub storage_device_id: Option<u32>,
|
||||
#[sea_orm(nullable)]
|
||||
pub capture_device_id: Option<u32>,
|
||||
#[sea_orm(nullable)]
|
||||
pub parent_file_id: Option<u32>,
|
||||
// date
|
||||
pub date_created: NaiveDateTime,
|
||||
pub date_modified: NaiveDateTime,
|
||||
pub date_indexed: NaiveDateTime,
|
||||
}
|
||||
|
||||
pub type File = ActiveModel;
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
use crate::db::entity::file;
|
||||
|
||||
// Read a file from path returning the File struct
|
||||
// Generates meta checksum and extracts metadata
|
||||
pub async fn read_file(path: &str) -> io::Result<File> {
|
||||
pub async fn read_file(path: &str) -> io::Result<file::ActiveModel> {
|
||||
let db = db::connection::get_connection().await.unwrap();
|
||||
|
||||
let path_buff = path::PathBuf::from(path);
|
||||
let metadata = fs::metadata(&path)?;
|
||||
|
||||
if metadata.is_dir() {
|
||||
// return Err();
|
||||
}
|
||||
|
||||
let size = metadata.len();
|
||||
let meta_checksum = checksum::create_meta_hash(path.to_owned(), size)?;
|
||||
|
||||
let file = File {
|
||||
let existing_file = file::Entity::find()
|
||||
.filter(file::Column::MetaChecksum.contains(&meta_checksum))
|
||||
.all(&db)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
println!("Existing file found {:?}", existing_file);
|
||||
|
||||
let file = file::ActiveModel {
|
||||
meta_checksum: Set(meta_checksum),
|
||||
name: Set(extract_name(path_buff.file_name())),
|
||||
extension: Set(extract_name(path_buff.extension())),
|
||||
uri: Set(path.to_owned()),
|
||||
size_in_bytes: Set(format!("{}", size)),
|
||||
date_created: Set(time::system_time_to_date_time(metadata.created()).unwrap()),
|
||||
date_modified: Set(time::system_time_to_date_time(metadata.modified()).unwrap()),
|
||||
date_indexed: Set(time::system_time_to_date_time(metadata.modified()).unwrap()),
|
||||
date_created: Set(Some(
|
||||
time::system_time_to_date_time(metadata.created()).unwrap(),
|
||||
)),
|
||||
date_modified: Set(Some(
|
||||
time::system_time_to_date_time(metadata.modified()).unwrap(),
|
||||
)),
|
||||
date_indexed: Set(Some(
|
||||
time::system_time_to_date_time(metadata.modified()).unwrap(),
|
||||
)),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let res = file.insert(&db).await.unwrap();
|
||||
let file = file
|
||||
.save(&db)
|
||||
.await
|
||||
.map_err(|error| println!("Failed to read file: {}", error))
|
||||
.unwrap();
|
||||
|
||||
Ok(res)
|
||||
Ok(file)
|
||||
}
|
||||
|
||||
// extract name from OsStr returned by PathBuff
|
||||
|
|
|
@ -10,9 +10,16 @@ mod db;
|
|||
mod filesystem;
|
||||
mod util;
|
||||
use crate::app::menu;
|
||||
use env_logger;
|
||||
use futures::executor::block_on;
|
||||
use log;
|
||||
|
||||
fn main() {
|
||||
env_logger::builder()
|
||||
.filter_level(log::LevelFilter::Debug)
|
||||
.is_test(true)
|
||||
.init();
|
||||
|
||||
let connection = db::connection::create_primary_db();
|
||||
let primary_db = block_on(connection).unwrap();
|
||||
|
||||
|
|
Loading…
Reference in a new issue