mirror of
https://github.com/Drop-OSS/drop-app.git
synced 2026-07-27 10:14:48 +10:00
feat: more refactoring (broken)
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
[package]
|
||||
name = "drop-library"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
drop-errors = { path = "../drop-errors" }
|
||||
http = "*"
|
||||
reqwest = { version = "*", default-features = false }
|
||||
serde = { version = "*", default-features = false, features = ["derive"] }
|
||||
tauri = "*"
|
||||
@@ -0,0 +1,11 @@
|
||||
pub enum DropLibraryError {
|
||||
NetworkError(reqwest::Error),
|
||||
ServerError(drop_errors::drop_server_error::ServerError),
|
||||
Unconfigured,
|
||||
}
|
||||
|
||||
impl From<reqwest::Error> for DropLibraryError {
|
||||
fn from(value: reqwest::Error) -> Self {
|
||||
DropLibraryError::NetworkError(value)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
use crate::libraries::LibraryProviderIdentifier;
|
||||
|
||||
pub struct LibraryGamePreview {
|
||||
pub library: LibraryProviderIdentifier,
|
||||
pub internal_id: String,
|
||||
pub name: String,
|
||||
pub short_description: String,
|
||||
pub icon: String,
|
||||
}
|
||||
|
||||
pub struct LibraryGame {
|
||||
pub library: LibraryProviderIdentifier,
|
||||
pub internal_id: String,
|
||||
pub name: String,
|
||||
pub short_description: String,
|
||||
pub md_description: String,
|
||||
pub icon: String,
|
||||
}
|
||||
|
||||
impl From<LibraryGame> for LibraryGamePreview {
|
||||
fn from(value: LibraryGame) -> Self {
|
||||
LibraryGamePreview {
|
||||
library: value.library,
|
||||
internal_id: value.internal_id,
|
||||
name: value.name,
|
||||
short_description: value.short_description,
|
||||
icon: value.icon,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
pub mod libraries;
|
||||
pub mod game;
|
||||
pub mod errors;
|
||||
@@ -0,0 +1,76 @@
|
||||
use std::{
|
||||
fmt::Display,
|
||||
hash::{DefaultHasher, Hash, Hasher},
|
||||
};
|
||||
|
||||
use http::Request;
|
||||
use serde::{Deserialize, Serialize, de::DeserializeOwned};
|
||||
use tauri::UriSchemeResponder;
|
||||
|
||||
use crate::{
|
||||
errors::DropLibraryError,
|
||||
game::{LibraryGame, LibraryGamePreview},
|
||||
};
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
pub struct LibraryProviderIdentifier {
|
||||
internal_id: usize,
|
||||
name: String,
|
||||
}
|
||||
|
||||
impl PartialEq for LibraryProviderIdentifier {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.internal_id == other.internal_id
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for LibraryProviderIdentifier {}
|
||||
|
||||
impl Hash for LibraryProviderIdentifier {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
self.internal_id.hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for LibraryProviderIdentifier {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.write_str(&self.name)
|
||||
}
|
||||
}
|
||||
|
||||
impl LibraryProviderIdentifier {
|
||||
pub fn str_hash(&self) -> String {
|
||||
let mut hasher = DefaultHasher::new();
|
||||
self.hash(&mut hasher);
|
||||
hasher.finish().to_string()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct LibraryFetchConfig {
|
||||
pub hard_refresh: bool,
|
||||
}
|
||||
|
||||
pub trait DropLibraryProvider: Serialize + DeserializeOwned + Sized {
|
||||
fn build(identifier: LibraryProviderIdentifier) -> Self;
|
||||
fn id(&self) -> &LibraryProviderIdentifier;
|
||||
fn load_object(
|
||||
&self,
|
||||
request: Request<Vec<u8>>,
|
||||
responder: UriSchemeResponder,
|
||||
) -> impl Future<Output = Result<(), DropLibraryError>> + Send;
|
||||
|
||||
fn fetch_library(
|
||||
&self,
|
||||
config: &LibraryFetchConfig,
|
||||
) -> impl Future<Output = Result<Vec<LibraryGamePreview>, DropLibraryError>> + Send;
|
||||
fn fetch_game(
|
||||
&self,
|
||||
config: &LibraryFetchConfig,
|
||||
) -> impl Future<Output = Result<LibraryGame, DropLibraryError>> + Send;
|
||||
|
||||
|
||||
|
||||
fn owns_game(&self, id: &LibraryProviderIdentifier) -> bool {
|
||||
self.id().internal_id == id.internal_id
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user