Migrate from window.electron to tauri IPC functions across components
- Replaced `window.electron.invoke` calls with equivalent `tauri` function calls for all IPC interactions. - Removed `electron.d.ts` TypeScript definitions as they are no longer needed. - Updated related logic for offline/online state synchronization. - Added `types.rs` and `shared/mod.rs` modules to support Tauri IPC integration with Rust enums and shared logic. - Refactored IPC request queues to use updated handler names for consistency with Tauri.
This commit is contained in:
1
src-tauri/src/domains/cover/mod.rs
Normal file
1
src-tauri/src/domains/cover/mod.rs
Normal file
@@ -0,0 +1 @@
|
||||
pub mod service;
|
||||
53
src-tauri/src/domains/cover/service.rs
Normal file
53
src-tauri/src/domains/cover/service.rs
Normal file
@@ -0,0 +1,53 @@
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
|
||||
use base64::{engine::general_purpose::STANDARD as BASE64, Engine};
|
||||
use rusqlite::Connection;
|
||||
|
||||
use crate::crypto::encryption::decrypt_data_with_user_key;
|
||||
use crate::crypto::key_manager::get_user_encryption_key;
|
||||
use crate::domains::book::repo;
|
||||
use crate::error::AppResult;
|
||||
use crate::helpers::timestamp_in_seconds;
|
||||
use crate::shared::types::Lang;
|
||||
|
||||
/// Retrieves and decrypts the cover picture for a specific book.
|
||||
/// Returns the decrypted cover image data, or an empty string if not found.
|
||||
pub fn get_cover_picture(conn: &Connection, user_id: &str, book_id: &str, lang: Lang) -> AppResult<String> {
|
||||
let cover_query: repo::BookCoverQuery = repo::fetch_book_cover(conn, user_id, book_id, lang)?;
|
||||
if !cover_query.cover_image.is_empty() {
|
||||
let user_encryption_key: String = get_user_encryption_key(user_id)?;
|
||||
decrypt_data_with_user_key(&cover_query.cover_image, &user_encryption_key)
|
||||
} else {
|
||||
Ok(String::new())
|
||||
}
|
||||
}
|
||||
|
||||
/// Deletes the cover picture association for a specific book.
|
||||
/// Clears the cover image reference in the database.
|
||||
/// Returns true if the cover was successfully deleted, false otherwise.
|
||||
pub fn delete_cover_picture(conn: &Connection, user_id: &str, book_id: &str, lang: Lang) -> AppResult<bool> {
|
||||
let _existing_cover_name: String = get_cover_picture(conn, user_id, book_id, lang)?;
|
||||
let last_update: i64 = timestamp_in_seconds();
|
||||
repo::update_book_cover(conn, book_id, "", user_id, last_update, lang)
|
||||
}
|
||||
|
||||
/// Retrieves and decrypts a picture file, returning it as a base64-encoded string.
|
||||
/// Returns the base64-encoded image data, or an empty string if the image cannot be read.
|
||||
pub fn get_picture(_user_id: &str, user_key: &str, image: &str, _lang: Lang) -> String {
|
||||
if image.is_empty() {
|
||||
return String::new();
|
||||
}
|
||||
match try_get_picture(user_key, image) {
|
||||
Ok(base64_data) => base64_data,
|
||||
Err(_) => String::new(),
|
||||
}
|
||||
}
|
||||
|
||||
fn try_get_picture(user_key: &str, image: &str) -> AppResult<String> {
|
||||
let decrypted_file_name: String = decrypt_data_with_user_key(image, user_key)?;
|
||||
let user_directory: &Path = Path::new(&decrypted_file_name);
|
||||
let file_data: Vec<u8> = fs::read(user_directory)
|
||||
.map_err(|error| crate::error::AppError::Internal(error.to_string()))?;
|
||||
Ok(BASE64.encode(&file_data))
|
||||
}
|
||||
Reference in New Issue
Block a user