Add info boxes contents
This commit is contained in:
@@ -11,6 +11,5 @@ lazy_static.workspace = true
|
||||
ratatui.workspace = true
|
||||
serde_json.workspace = true
|
||||
dashmap.workspace = true
|
||||
db = { path = "../db" }
|
||||
language-tags = { version = "0.3.2", features = ["serde"] }
|
||||
sys-locale = "0.3.2"
|
||||
|
||||
17
models/src/db.rs
Executable file
17
models/src/db.rs
Executable file
@@ -0,0 +1,17 @@
|
||||
use serde::de::DeserializeOwned;
|
||||
use serde::Serialize;
|
||||
|
||||
pub trait RocksColumn {
|
||||
type Id: Serialize + DeserializeOwned + Clone;
|
||||
fn get_id(&self) -> Self::Id;
|
||||
fn set_id(&mut self, id: Self::Id);
|
||||
fn get_column_name() -> String;
|
||||
}
|
||||
|
||||
pub trait RocksReference<T> where T: RocksColumn {
|
||||
fn get_reference_id(&self) -> T::Id;
|
||||
}
|
||||
|
||||
pub trait RocksReferences<T> where T: RocksColumn {
|
||||
fn get_reference_ids(&self) -> Vec<T::Id>;
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
use color_eyre::Report;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use db::types::{RocksColumn, RocksReferences};
|
||||
use crate::config::ApplicationConfig;
|
||||
use crate::db::{RocksColumn, RocksReferences};
|
||||
use crate::dlsite::genre::DLSiteGenre;
|
||||
use crate::dlsite::translation::DLSiteTranslation;
|
||||
|
||||
@@ -10,6 +10,7 @@ pub struct DLSiteCategory {
|
||||
#[serde(skip)]
|
||||
pub id: String,
|
||||
pub genre_ids: Vec<u16>,
|
||||
//TODO: have to become multilingual
|
||||
pub name: DLSiteTranslation
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use db::types::RocksColumn;
|
||||
use super::translation::DLSiteTranslation;
|
||||
use crate::db::RocksColumn;
|
||||
use crate::dlsite::DLSiteTranslations;
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct DLSiteGenre {
|
||||
#[serde(skip)]
|
||||
pub id: u16,
|
||||
pub name: Vec<DLSiteTranslation>
|
||||
pub name: DLSiteTranslations
|
||||
}
|
||||
|
||||
impl RocksColumn for DLSiteGenre {
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
use std::path::PathBuf;
|
||||
use ratatui::text::Text;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use db::types::{RocksColumn, RocksReferences};
|
||||
use crate::db::{RocksColumn, RocksReferences};
|
||||
use super::genre::DLSiteGenre;
|
||||
use super::translation::DLSiteTranslation;
|
||||
use super::translation::{DLSiteTranslation, DLSiteTranslations};
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct DLSiteManiax {
|
||||
#[serde(skip)]
|
||||
pub rj_num: String,
|
||||
pub genre_ids: Vec<u16>,
|
||||
pub name: Vec<DLSiteTranslation>,
|
||||
pub name: DLSiteTranslations,
|
||||
pub sells_count: u32,
|
||||
pub folder_path: PathBuf,
|
||||
pub version: Option<String>
|
||||
@@ -22,7 +22,7 @@ impl From<super::crawler::DLSiteManiax> for DLSiteManiax {
|
||||
Self {
|
||||
rj_num: value.rj_num,
|
||||
genre_ids: value.genre_ids,
|
||||
name: vec![title],
|
||||
name: DLSiteTranslations(vec![title]),
|
||||
sells_count: value.sells_count,
|
||||
folder_path: value.folder_path,
|
||||
version: None
|
||||
@@ -56,4 +56,10 @@ impl Into<Text<'_>> for &DLSiteManiax {
|
||||
fn into(self) -> Text<'static> {
|
||||
Text::from(self.rj_num.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<Text<'_>> for DLSiteManiax {
|
||||
fn into(self) -> Text<'static> {
|
||||
Text::from(self.rj_num.to_string())
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ mod genre;
|
||||
mod maniax;
|
||||
pub mod crawler;
|
||||
|
||||
pub use translation::{EN_LOCALE, JP_LOCALE, DLSiteTranslation};
|
||||
pub use translation::*;
|
||||
pub use category::DLSiteCategory;
|
||||
pub use genre::DLSiteGenre;
|
||||
pub use maniax::DLSiteManiax;
|
||||
|
||||
@@ -4,7 +4,7 @@ use language_tags::LanguageTag;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use lazy_static::lazy_static;
|
||||
use crate::config::ApplicationConfig;
|
||||
use super::matches_primary_language;
|
||||
use super::{matches_primary_language, PrimaryLanguage};
|
||||
|
||||
lazy_static! {
|
||||
pub static ref EN_LOCALE: LanguageTag = LanguageTag::parse("en").unwrap();
|
||||
@@ -17,6 +17,30 @@ pub enum DLSiteTranslation {
|
||||
EN(String), JP(String)
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
|
||||
pub struct DLSiteTranslations(pub Vec<DLSiteTranslation>);
|
||||
|
||||
impl DLSiteTranslations {
|
||||
pub fn get_translation(&self, language: LanguageTag) -> color_eyre::Result<String> {
|
||||
let Self(translations) = self;
|
||||
let primary_language = PrimaryLanguage::try_from(&language)?;
|
||||
let translation = match primary_language {
|
||||
PrimaryLanguage::EN => translations.iter().find(|v| matches!(v, DLSiteTranslation::EN(_))),
|
||||
PrimaryLanguage::JP => translations.iter().find(|v| matches!(v, DLSiteTranslation::JP(_))),
|
||||
};
|
||||
match translation {
|
||||
Some(translation) => Ok(translation.to_string()),
|
||||
None => Err(eyre!("No translation found for {:?}", language))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl DLSiteTranslation {
|
||||
pub fn to_string(&self) -> String {
|
||||
self.into()
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<&str> for DLSiteTranslation {
|
||||
type Error = Report;
|
||||
fn try_from(value: &str) -> color_eyre::Result<Self> {
|
||||
@@ -44,13 +68,12 @@ impl TryFrom<String> for DLSiteTranslation {
|
||||
}
|
||||
}
|
||||
|
||||
impl TryInto<String> for DLSiteTranslation {
|
||||
type Error = Report;
|
||||
impl Into<String> for &DLSiteTranslation {
|
||||
|
||||
fn try_into(self) -> Result<String, Self::Error> {
|
||||
fn into(self) -> String {
|
||||
match self {
|
||||
DLSiteTranslation::EN(val) => Ok(val),
|
||||
DLSiteTranslation::JP(val) => Ok(val),
|
||||
DLSiteTranslation::EN(val) => val.to_string(),
|
||||
DLSiteTranslation::JP(val) => val.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ use lazy_static::lazy_static;
|
||||
|
||||
pub mod dlsite;
|
||||
pub mod config;
|
||||
pub mod db;
|
||||
|
||||
const APP_DIR_NAME: &str = "sus_manager";
|
||||
lazy_static! {
|
||||
|
||||
Reference in New Issue
Block a user