pub(crate) mod modrinth;
pub(crate) mod curseforge;
use std::collections::HashMap;
use anyhow::Result;
use async_trait::async_trait;
use crate::{minecraft::version::MinecraftInstallation, utils::BetterPath, LauncherContext};
#[derive(PartialEq, Eq, Hash)]
#[allow(missing_docs)]
pub enum ContentType {
ModPack,
Shader,
Mod,
ResourcePack,
DataPack,
World,
}
#[allow(missing_docs)]
pub struct Screenshot {
pub url: String,
pub title: Option<String>,
pub description: Option<String>
}
#[async_trait]
pub trait Content: Send + Sync {
async fn list_downloadable_versions(&self, for_version: Option<&MinecraftInstallation<'_>>, launcher: &LauncherContext) -> Result<Vec<Box<dyn ContentVersion>>>;
fn get_title(&self) -> String;
fn get_description(&self) -> String;
async fn get_body(&self, launcher: &LauncherContext) -> Result<String>;
fn get_icon_url(&self) -> Option<String>;
fn get_urls(&self) -> HashMap<String, String>;
fn get_screenshots(&self) -> Vec<Screenshot>;
fn get_other_information(&self) -> HashMap<String, String>;
fn is_library(&self) -> bool;
fn kind(&self) -> ContentType;
}
#[async_trait]
pub trait ContentVersion: Send + Sync {
fn get_version_file_url(&self) -> String;
fn get_version_file_sha1(&self) -> String;
fn get_version_file_name(&self) -> String;
async fn get_version_changelog(&self, launcher: &LauncherContext) -> Result<String>;
fn get_version_number(&self) -> String;
async fn list_dependencies(&self, launcher: &LauncherContext) -> Result<Vec<ContentDependency>>;
}
pub enum ContentDependency
{
Content(Box<dyn Content>),
ContentVersion(Box<dyn ContentVersion>),
}
#[async_trait]
pub trait ContentService: Send + Sync {
async fn search_content(
&self,
name: String,
skip: usize,
limit: usize,
kind: ContentType,
sort_field: usize,
for_version: Option<&MinecraftInstallation<'_>>,
launcher: &LauncherContext
) -> Result<Vec<Box<dyn Content>>>;
fn get_unsupported_content_types(&self) -> Vec<ContentType>;
fn get_sort_fields(&self) -> Vec<String>;
fn get_default_sort_field(&self) -> String;
async fn get_content_version_from_file(&self, path: &BetterPath, launcher: &LauncherContext) -> Result<Option<Box<dyn ContentVersion>>>;
async fn get_content_by_id(&self, id: &str, launcher: &LauncherContext) -> Result<Option<Box<dyn Content>>>;
async fn get_content_version_by_id(&self, content_id: &str, id: &str, launcher: &LauncherContext) -> Result<Option<Box<dyn ContentVersion>>>;
}