Refactor and clean up

- Removed unused services (`cover`, `character`, `series_location` modules) and legacy methods to reduce code clutter.
- Consolidated `IncidentProps` and `PlotPointProps` into `incident.service` and `plotpoint.service` modules, replacing duplicated definitions.
- Updated references across modules (`act`, `incident.service`, `character`) for consistency.
- Improved serialization with `serde` for `IncidentProps`.
- Enhanced `get_incitents_incidents` to include optional chapters.
This commit is contained in:
natreex
2026-03-21 11:29:58 -04:00
parent 1f99fe0bdc
commit 1478fe10dd
7 changed files with 24 additions and 665 deletions

View File

@@ -1,53 +0,0 @@
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))
}