This commit is contained in:
Bianca Fürstenau 2025-03-05 20:15:11 +01:00
parent eda34db508
commit be9b5ed855
12 changed files with 43 additions and 45 deletions

View file

@ -1,8 +1,8 @@
use chrono::offset::Utc;
use curl::{easy, easy::Easy2};
use rand::prelude::*;
use rusqlite::{Connection, DatabaseName};
use ring_compat::signature::ed25519::SigningKey;
use rusqlite::{Connection, DatabaseName};
use tauri::{Manager, State};
use tokio::sync::Mutex;
@ -62,7 +62,8 @@ fn data_client(file: &str) -> Result<Easy2<Collector>, ()> {
file
);
client.url(&url).map_err(|_| ())?;
client.username(include_str!("cloud_user.txt")).map_err(|_| ())?;
client.username(include_str!("cloud_user.txt"))
.map_err(|_| ())?;
client.http_auth(easy::Auth::new().auto(true))
.map_err(|_| ())?;
client.ssl_cainfo_blob(include_bytes!("isrg-root-x1.pem"))
@ -76,8 +77,7 @@ fn put_client(file: &str, payload: &[u8]) -> Result<Easy2<Collector>, ()> {
client.get_mut().1.extend_from_slice(payload);
client.in_filesize(payload.len() as u64)
.map_err(|e| println!("{:?}", e))?;
client.upload(true)
.map_err(|e| println!("{:?}", e))?;
client.upload(true).map_err(|e| println!("{:?}", e))?;
Ok(client)
}
@ -96,22 +96,21 @@ async fn push_key(id: &u64, key: &SigningKey) -> Result<(), ()> {
let file = format!("{:016X}.key", id);
let v_key = key.verifying_key();
let client = put_client(&file, v_key.as_ref())?;
let _perf = client.perform()
.map_err(|e| println!("{:?}", e))?;
let _perf = client.perform().map_err(|e| println!("{:?}", e))?;
Ok(())
}
fn push_db(id: &u64, db: &Connection, app: tauri::AppHandle) -> Result<(), ()> {
let filename = format!("{:016X}.sqlite", id);
let path = app.path().resolve(&filename, tauri::path::BaseDirectory::Temp)
let path = app
.path()
.resolve(&filename, tauri::path::BaseDirectory::Temp)
.map_err(|e| println!("{:?}", e))?;
db.backup(DatabaseName::Main, &path, None)
.map_err(|e| println!("{:?}", e))?;
let buf = std::fs::read(&path)
.map_err(|e| println!("{:?}", e))?;
let buf = std::fs::read(&path).map_err(|e| println!("{:?}", e))?;
let client = put_client(&filename, buf.as_ref())?;
let _perf = client.perform()
.map_err(|e| println!("{:?}", e))?;
let _perf = client.perform().map_err(|e| println!("{:?}", e))?;
Ok(())
}

View file

@ -1,7 +1,7 @@
use chrono::offset::Utc;
use std::collections::HashMap;
use tokio::sync::Mutex;
use tauri::State;
use tokio::sync::Mutex;
use crate::types::*;
@ -22,14 +22,14 @@ fn parse_inventory(data: HashMap<String, String>) -> Result<Inventory, ()> {
match data.get(&format!("cafe-inventory-{}", s)) {
None => (),
Some(c) => {
let c = if c == "" {"0"} else {c};
let c = if c == "" { "0" } else { c };
let Ok(count) = c.parse() else {
println!("Invalid count '{}' for '{}' in inventory data.", c, s);
continue;
};
let v = VoucherInventory { store, count };
vouchers.push(v);
},
}
}
}
unimplemented!()
@ -47,15 +47,10 @@ pub async fn inventory(
for v in inv.vouchers {
state.db.execute(
"INSERT INTO voucher_inventory VALUES ()",
(
inv.acc,
v.store,
v.count,
now,
),
(inv.acc, v.store, v.count, now),
)
.map_err(|e| println!("{:?}", e))?;
};
}
Ok(())
}