file read

This commit is contained in:
Jamie 2021-09-28 11:45:59 -07:00
parent 1edf6212fb
commit f8c9ae9033
13 changed files with 116 additions and 27 deletions

1
src-tauri/Cargo.lock generated
View file

@ -313,6 +313,7 @@ dependencies = [
"libc",
"num-integer",
"num-traits",
"serde",
"time",
"winapi",
]

View file

@ -15,14 +15,14 @@ build = "src/build.rs"
tauri-build = { version = "1.0.0-beta.3" }
[dependencies]
tauri = { version = "1.0.0-beta.5", features = ["api-all", "menu"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
rebind = "0.2.1"
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.0.0-beta.5", features = ["api-all", "menu"] }
data-encoding = "2.3.2"
ring = "0.17.0-alpha.10"
rusqlite = "0.25.3"
chrono = "0.4.0"
chrono = { version = "0.4.0", features = ["serde"]}
[features]
default = [ "custom-protocol" ]

View file

@ -1,3 +1,6 @@
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
pub enum Encryption {
NONE,
AES128,

View file

@ -1,2 +1 @@
pub mod init;
// pub mod util;

View file

@ -1 +0,0 @@

View file

@ -1,22 +1,29 @@
use crate::crypto;
use chrono::prelude::*;
use serde::{Deserialize, Serialize};
use std::fs;
use std::path;
use crate::filesystem::checksum;
use crate::util::time;
#[derive(Debug, Serialize, Deserialize)]
pub struct File {
// identity
pub id: u32,
pub id: Option<u64>,
pub checksum: String,
pub uri: String,
// metadata
pub name: String,
pub extension: String,
pub size_in_bytes: u32,
pub mime: String,
pub size_in_bytes: u64,
pub encryption: crypto::Encryption,
pub ipfs_id: Option<String>,
// ownership
pub user_id: u32,
pub storage_device_id: u32,
pub capture_device_id: Option<u32>,
pub parent_object_id: Option<u32>,
pub user_id: Option<u64>,
pub storage_device_id: Option<u64>,
pub capture_device_id: Option<u64>,
pub parent_file_id: Option<u64>,
// date
pub date_created: DateTime<Utc>,
pub date_modified: DateTime<Utc>,
@ -25,17 +32,54 @@ pub struct File {
pub struct Directory {
// identity
pub id: u32,
pub id: Option<u64>,
pub name: String,
// calculations
pub calculated_size_in_bytes: u32,
pub calculated_size_in_bytes: u64,
pub calculated_file_count: u32,
// ownership
pub user_id: u32,
pub storage_device_id: u32,
pub user_id: Option<u64>,
pub storage_device_id: Option<u64>,
pub parent_directory_id: Option<u32>,
// date
pub date_created: DateTime<Utc>,
pub date_modified: DateTime<Utc>,
pub date_indexed: DateTime<Utc>,
}
#[tauri::command]
pub fn read_file_command(path: &str) -> Result<File, String> {
let file = read_file(path).unwrap();
Ok(file)
}
pub fn read_file(path: &str) -> Result<File, String> {
let path_buff = path::PathBuf::from(path);
// extract metadata
let metadata = fs::metadata(&path).unwrap();
if metadata.is_dir() {
panic!("Not a file, this is a directory");
}
let file = File {
id: None,
name: path_buff.file_name().unwrap().to_str().unwrap().to_owned(),
extension: path_buff.extension().unwrap().to_str().unwrap().to_owned(),
uri: path.to_owned(),
checksum: checksum::create_hash(path).unwrap(),
size_in_bytes: metadata.len(),
date_created: time::system_time_to_date_time(metadata.created().unwrap()).unwrap(),
date_modified: time::system_time_to_date_time(metadata.created().unwrap()).unwrap(),
date_indexed: chrono::offset::Utc::now(),
encryption: crypto::Encryption::NONE,
ipfs_id: None,
user_id: None,
storage_device_id: None,
capture_device_id: None,
parent_file_id: None,
};
println!("file: {:?}", file);
Ok(file)
}

View file

@ -1,2 +1,2 @@
mod file;
mod hash;
pub mod checksum;
pub mod file;

View file

@ -7,6 +7,7 @@ mod app;
mod crypto;
mod db;
mod filesystem;
mod util;
use crate::app::menu;
#[derive(serde::Serialize)]
@ -28,7 +29,10 @@ fn main() {
println!("jeff {:?}", connection);
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![fn_exposed_to_js])
.invoke_handler(tauri::generate_handler![
fn_exposed_to_js,
filesystem::file::read_file_command
])
.menu(menu::get_menu())
.run(tauri::generate_context!())
.expect("error while running tauri application");

View file

@ -0,0 +1 @@
pub mod time;

View file

@ -0,0 +1,12 @@
use chrono::{offset::TimeZone, DateTime, NaiveDateTime, Utc};
use std::io;
use std::time::{SystemTime, UNIX_EPOCH};
pub fn system_time_to_date_time(system_time: SystemTime) -> io::Result<DateTime<Utc>> {
let std_duration = system_time.duration_since(UNIX_EPOCH).unwrap();
let chrono_duration = chrono::Duration::from_std(std_duration).unwrap();
let unix = NaiveDateTime::from_timestamp(0, 0);
let naive = unix + chrono_duration;
let date_time: DateTime<Utc> = Utc.from_local_datetime(&naive).unwrap();
Ok(date_time)
}

View file

@ -43,19 +43,25 @@
"active": false
},
"allowlist": {
"all": true
"all": true,
"dialog": {
"all": true,
"open": true,
"save": true
}
},
"windows": [
{
"title": "Nexus",
"width": 800,
"height": 500,
"width": 1200,
"height": 700,
"resizable": true,
"fullscreen": false,
"alwaysOnTop": false,
"focus": true,
"fileDropEnabled": false,
"fileDropEnabled": true,
"decorations": false,
"transparent": false,
"center": true
}
],

View file

@ -1,7 +1,8 @@
import React from 'react';
import React, { useRef } from 'react';
import { Button, colors, ColorScheme, extendTheme, Icon, Input, Switch } from '@vechaiui/react';
import { VechaiProvider } from '@vechaiui/react';
import { CookingPot } from 'phosphor-react';
import { invoke } from '@tauri-apps/api';
export const pale: ColorScheme = {
id: 'pale',
@ -28,14 +29,33 @@ const theme = extendTheme({
});
export default function App() {
const fileUploader = useRef<HTMLInputElement | null>(null);
function changeHandler(e: any) {
console.log(e);
}
return (
<VechaiProvider theme={theme} colorScheme="pale">
<div data-tauri-drag-region className="max-w h-10 bg-primary-800"></div>
<div className="p-2">
<div className="max-w h-20"></div>
<div className="flex flex-wrap w-full py-2 space-x-2">
<Button variant="solid" color="primary">
<div className="flex flex-wrap w-full space-x-2">
<input type="file" id="file" onChange={changeHandler} />
<Button
variant="solid"
color="primary"
onClick={() => {
invoke('read_file_command', {
path: '/Users/jamie/Desktop/lol.png'
}).then(console.log);
}}
>
Load File
</Button>
<Button variant="solid" color="primary">
Reset
</Button>
<Button variant="solid" color="primary">
Close
</Button>
</div>
</div>
</VechaiProvider>