mirror of
https://github.com/Drop-OSS/drop-app.git
synced 2025-11-14 16:51:18 +10:00
migrate to nuxt and groundwork
This commit is contained in:
14
src-tauri/src/auth.rs
Normal file
14
src-tauri/src/auth.rs
Normal file
@ -0,0 +1,14 @@
|
||||
use tauri::Error;
|
||||
|
||||
use crate::{data::DatabaseInterface, AppAuthenticationStatus, User};
|
||||
|
||||
pub fn setup(db: DatabaseInterface) -> Result<(AppAuthenticationStatus, Option<User>), Error> {
|
||||
let data = db.get_data(true).unwrap();
|
||||
// If we have certs, exit for now
|
||||
if data.certs.is_some() {
|
||||
// TODO: check if it's still valid, and fetch user information
|
||||
return Ok((AppAuthenticationStatus::SignedInNeedsReauth, None));
|
||||
}
|
||||
|
||||
return Ok((AppAuthenticationStatus::SignedOut, None));
|
||||
}
|
||||
32
src-tauri/src/data.rs
Normal file
32
src-tauri/src/data.rs
Normal file
@ -0,0 +1,32 @@
|
||||
use std::fs::create_dir_all;
|
||||
|
||||
use directories::BaseDirs;
|
||||
use rustbreak::{deser::Bincode, FileDatabase, PathDatabase};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone)]
|
||||
pub struct DatabaseCerts {
|
||||
pub private: String,
|
||||
pub public: String,
|
||||
pub cert: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Clone, Deserialize)]
|
||||
pub struct Database {
|
||||
pub certs: Option<DatabaseCerts>,
|
||||
}
|
||||
|
||||
pub type DatabaseInterface =
|
||||
rustbreak::Database<Database, rustbreak::backend::PathBackend, Bincode>;
|
||||
|
||||
pub fn setup() -> DatabaseInterface {
|
||||
let db_path = BaseDirs::new().unwrap().data_dir().join("drop");
|
||||
let default = Database {
|
||||
certs: None
|
||||
};
|
||||
let db = PathDatabase::<Database, Bincode>::create_at_path(db_path, default).unwrap();
|
||||
|
||||
db.save().unwrap();
|
||||
|
||||
return db;
|
||||
}
|
||||
@ -1,24 +1,45 @@
|
||||
mod auth;
|
||||
mod data;
|
||||
mod unpacker;
|
||||
|
||||
use data::DatabaseInterface;
|
||||
use serde::Serialize;
|
||||
use tauri::Runtime;
|
||||
use unpacker::unpack;
|
||||
|
||||
#[derive(Clone, Copy, Serialize)]
|
||||
pub enum AppAuthenticationStatus {
|
||||
SignedOut,
|
||||
SignedIn,
|
||||
SignedInNeedsReauth,
|
||||
}
|
||||
#[derive(Clone, Copy, Serialize)]
|
||||
pub struct User {}
|
||||
|
||||
#[derive(Clone, Copy, Serialize)]
|
||||
pub struct AppState {
|
||||
auth: AppAuthenticationStatus,
|
||||
user: Option<User>,
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn unpack_debug<R: Runtime>(
|
||||
app: tauri::AppHandle<R>,
|
||||
window: tauri::Window<R>,
|
||||
) -> Result<String, String> {
|
||||
|
||||
unpack().unwrap();
|
||||
|
||||
return Ok("Successful".to_string());
|
||||
fn fetch_state(state: tauri::State<AppState>) -> Result<AppState, String> {
|
||||
Ok(*state.inner())
|
||||
}
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
let db: DatabaseInterface = data::setup();
|
||||
let auth_result = auth::setup(db).unwrap();
|
||||
|
||||
let state = AppState {
|
||||
auth: auth_result.0,
|
||||
user: auth_result.1,
|
||||
};
|
||||
|
||||
tauri::Builder::default()
|
||||
.manage(state)
|
||||
.invoke_handler(tauri::generate_handler![fetch_state])
|
||||
.plugin(tauri_plugin_shell::init())
|
||||
.invoke_handler(tauri::generate_handler![unpack_debug])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
|
||||
@ -27,7 +27,7 @@ struct Manifest {
|
||||
record: HashMap<String, ManifestRecord>,
|
||||
}
|
||||
|
||||
pub fn unpack() -> Result<(), Error> {
|
||||
pub async fn unpack() -> Result<(), Error> {
|
||||
let chunk_size: u64 = 1024 * 1024 * 16;
|
||||
|
||||
let input = Path::new("/home/decduck/Dev/droplet-output");
|
||||
@ -53,13 +53,12 @@ pub fn unpack() -> Result<(), Error> {
|
||||
let chunk_path = input.join(chunk.uuid + ".bin");
|
||||
let chunk_handle = File::open(chunk_path).unwrap();
|
||||
|
||||
let chunk_reader = BufReader::new(chunk_handle);
|
||||
let mut decompressor = zstd::Decoder::new(chunk_reader).unwrap();
|
||||
let mut chunk_reader = BufReader::new(chunk_handle);
|
||||
|
||||
let offset = u64::try_from(chunk.index).unwrap() * chunk_size;
|
||||
file_handle.seek(io::SeekFrom::Start(offset)).unwrap();
|
||||
|
||||
io::copy(&mut decompressor, &mut file_handle).unwrap();
|
||||
io::copy(&mut chunk_reader, &mut file_handle).unwrap();
|
||||
file_handle.flush().unwrap();
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user