Move Sheet and Composer to separate code file
This commit is contained in:
parent
3f7b45efda
commit
0addc7c4b9
@ -1,46 +1,7 @@
|
||||
use log::debug;
|
||||
use sqlx::{migrate::MigrateDatabase, Connection, Sqlite, SqliteConnection, SqlitePool};
|
||||
use sqlx::{migrate::MigrateDatabase, Sqlite, SqlitePool};
|
||||
|
||||
#[derive(sqlx::FromRow, Debug)]
|
||||
pub struct Sheet {
|
||||
name: String,
|
||||
// #[sqlx(from = "String")]
|
||||
path: String,
|
||||
// #[sqlx(from = "i64")]
|
||||
file_size: i32,
|
||||
file_hash: String,
|
||||
}
|
||||
|
||||
#[derive(sqlx::FromRow)]
|
||||
pub struct Composer {
|
||||
name: String,
|
||||
id: u32,
|
||||
}
|
||||
|
||||
impl Sheet {
|
||||
pub fn new_debug() -> Self {
|
||||
Sheet {
|
||||
name: "Hello world".to_string(),
|
||||
path: "This/is/my/path".into(),
|
||||
file_size: 42,
|
||||
file_hash: "h4sh".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn verify_path(&self) -> std::io::Result<bool> {
|
||||
// First compare file size since it is faster than hashing
|
||||
// let file_size = fs::metadata(&self.path)?.len();
|
||||
// if file_size == self.file_size {
|
||||
// let file_content = fs::read(&self.path)?;
|
||||
// let file_hash = blake3::hash(&file_content);
|
||||
// if file_hash.to_string() == self.file_hash {
|
||||
// return Ok(true);
|
||||
// }
|
||||
// }
|
||||
|
||||
Ok(false)
|
||||
}
|
||||
}
|
||||
use crate::sheet::Sheet;
|
||||
|
||||
pub struct Database {
|
||||
connection: SqlitePool,
|
||||
|
@ -1,8 +1,9 @@
|
||||
mod database;
|
||||
mod mcdu;
|
||||
mod sheet;
|
||||
mod sheet_listing;
|
||||
|
||||
use std::{env, path::PathBuf, process};
|
||||
use std::{path::PathBuf, process};
|
||||
|
||||
use clap::Parser;
|
||||
use database::Database;
|
||||
@ -13,8 +14,6 @@ use mcdu::McduModel;
|
||||
use relm4::prelude::*;
|
||||
use sheet_listing::{SheetListingInput, SheetListingModel};
|
||||
|
||||
use crate::database::Sheet;
|
||||
|
||||
struct AppModel {
|
||||
mcdu: Controller<McduModel>,
|
||||
sheet_listing: Controller<SheetListingModel>,
|
||||
|
40
src/sheet.rs
Normal file
40
src/sheet.rs
Normal file
@ -0,0 +1,40 @@
|
||||
#[derive(sqlx::FromRow, Debug)]
|
||||
pub struct Sheet {
|
||||
pub name: String,
|
||||
// #[sqlx(from = "String")]
|
||||
pub path: String,
|
||||
// #[sqlx(from = "i64")]
|
||||
pub file_size: i32,
|
||||
pub file_hash: String,
|
||||
}
|
||||
|
||||
#[derive(sqlx::FromRow)]
|
||||
pub struct Composer {
|
||||
pub name: String,
|
||||
pub id: u32,
|
||||
}
|
||||
|
||||
impl Sheet {
|
||||
pub fn new_debug() -> Self {
|
||||
Sheet {
|
||||
name: "Hello world".to_string(),
|
||||
path: "This/is/my/path".into(),
|
||||
file_size: 42,
|
||||
file_hash: "h4sh".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn verify_path(&self) -> std::io::Result<bool> {
|
||||
// First compare file size since it is faster than hashing
|
||||
// let file_size = fs::metadata(&self.path)?.len();
|
||||
// if file_size == self.file_size {
|
||||
// let file_content = fs::read(&self.path)?;
|
||||
// let file_hash = blake3::hash(&file_content);
|
||||
// if file_hash.to_string() == self.file_hash {
|
||||
// return Ok(true);
|
||||
// }
|
||||
// }
|
||||
|
||||
Ok(false)
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user