chore(cache): Added fetch_drop_object command

Signed-off-by: quexeky <git@quexeky.dev>
This commit is contained in:
quexeky
2025-02-08 22:32:04 +11:00
parent 4c59c5d6c1
commit 5c479cb283
3 changed files with 29 additions and 10 deletions

View File

@ -42,7 +42,7 @@ use process::commands::{kill_game, launch_game};
use process::process_manager::ProcessManager;
use remote::auth::{self, generate_authorization_header, recieve_handshake};
use remote::commands::{
auth_initiate, gen_drop_url, manual_recieve_handshake, retry_connect, sign_out, use_remote,
auth_initiate, fetch_drop_object, gen_drop_url, manual_recieve_handshake, retry_connect, sign_out, use_remote
};
use remote::requests::make_request;
use serde::{Deserialize, Serialize};
@ -237,6 +237,7 @@ pub fn run() {
// Remote
use_remote,
gen_drop_url,
fetch_drop_object,
// Library
fetch_library,
fetch_game,

View File

@ -1,8 +1,5 @@
use cacache::Integrity;
use openssl::hash::{hash, MessageDigest};
use rustix::path::Arg;
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use serde_binary::binary_stream::Endian;
use serde::{de::DeserializeOwned, Serialize};
use crate::{database::db::borrow_db_checked, error::remote_access_error::RemoteAccessError};

View File

@ -1,17 +1,16 @@
use std::sync::Mutex;
use log::debug;
use reqwest::blocking::Client;
use tauri::{AppHandle, Emitter, Manager};
use url::Url;
use crate::{
database::db::{borrow_db_checked, borrow_db_mut_checked, save_db},
error::remote_access_error::RemoteAccessError,
AppState, AppStatus,
database::db::{borrow_db_checked, borrow_db_mut_checked, save_db}, error::remote_access_error::RemoteAccessError, remote::{auth::generate_authorization_header, requests::make_request}, AppState, AppStatus
};
use super::{
auth::{auth_initiate_logic, recieve_handshake, setup},
remote::use_remote_logic,
auth::{auth_initiate_logic, recieve_handshake, setup}, cache::{cache_object, get_cached_object}, remote::use_remote_logic
};
#[tauri::command]
@ -35,6 +34,28 @@ pub fn gen_drop_url(path: String) -> Result<String, RemoteAccessError> {
Ok(url.to_string())
}
#[tauri::command]
pub fn fetch_drop_object(path: String) -> Result<Vec<u8>, RemoteAccessError> {
let drop_url = gen_drop_url(path.clone());
let req = make_request(
&Client::new(),
&[&path],
&[],
|r| { r.header("Authorization", generate_authorization_header()) }
)?.send();
match req {
Ok(data) => {
let data = data.bytes()?.to_vec();
cache_object(&path, &data)?;
Ok(data)
},
Err(e) => {
debug!("{}", e);
get_cached_object::<&str, Vec<u8>>(&path)
},
}
}
#[tauri::command]
pub fn sign_out(app: AppHandle) {
// Clear auth from database