diff options
author | GeckoEidechse <gecko.eidechse+git@pm.me> | 2024-12-22 23:55:52 +0100 |
---|---|---|
committer | GeckoEidechse <gecko.eidechse+git@pm.me> | 2024-12-22 23:55:52 +0100 |
commit | f1dee718da95836ffa5c0985c9e8f5643e0f3f6f (patch) | |
tree | 24967a28bcae1fc1e5b08da9f58bcc678ed52937 /src-tauri/src/thunderstore | |
parent | cc5ae684221d3165479d7a68556a2bb6fa81cf3a (diff) | |
download | FlightCore-f1dee718da95836ffa5c0985c9e8f5643e0f3f6f.tar.gz FlightCore-f1dee718da95836ffa5c0985c9e8f5643e0f3f6f.zip |
dev: Replace with sample Tauri 2.0 project
as a first step to convert FlightCore to Tauri 2.0
Diffstat (limited to 'src-tauri/src/thunderstore')
-rw-r--r-- | src-tauri/src/thunderstore/mod.rs | 86 |
1 files changed, 0 insertions, 86 deletions
diff --git a/src-tauri/src/thunderstore/mod.rs b/src-tauri/src/thunderstore/mod.rs deleted file mode 100644 index fc2acb02..00000000 --- a/src-tauri/src/thunderstore/mod.rs +++ /dev/null @@ -1,86 +0,0 @@ -//! For interacting with Thunderstore API -use crate::constants::{APP_USER_AGENT, BLACKLISTED_MODS}; -use serde::{Deserialize, Serialize}; -use std::collections::HashSet; -use ts_rs::TS; - -#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize, TS)] -#[ts(export)] -pub struct ThunderstoreMod { - pub name: String, - pub full_name: String, - pub owner: String, - pub package_url: String, - pub date_created: String, - pub date_updated: String, - pub uuid4: String, - pub rating_score: i32, - pub is_pinned: bool, - pub is_deprecated: bool, - pub has_nsfw_content: bool, - pub categories: Vec<String>, - pub versions: Vec<ThunderstoreModVersion>, -} - -#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize, TS)] -#[ts(export)] -pub struct ThunderstoreModVersion { - pub name: String, - pub full_name: String, - pub description: String, - pub icon: String, - pub version_number: String, - pub dependencies: Vec<String>, - pub download_url: String, - pub downloads: i32, - pub date_created: String, - pub website_url: String, - pub is_active: bool, - pub uuid4: String, - pub file_size: i64, -} - -/// Performs actual fetch from Thunderstore and returns response -async fn fetch_thunderstore_packages() -> Result<String, reqwest::Error> { - log::info!("Fetching Thunderstore API"); - - // Fetches - let url = "https://northstar.thunderstore.io/api/v1/package/"; - - let client = reqwest::Client::new(); - client - .get(url) - .header(reqwest::header::USER_AGENT, APP_USER_AGENT) - .send() - .await? - .text() - .await -} - -/// Queries Thunderstore packages API -#[tauri::command] -pub async fn query_thunderstore_packages_api() -> Result<Vec<ThunderstoreMod>, String> { - let res = match fetch_thunderstore_packages().await { - Ok(res) => res, - Err(err) => { - let warn_response = format!("Couldn't fetch from Thunderstore: {err}"); - log::warn!("{warn_response}"); - return Err(warn_response); - } - }; - - // Parse response - let parsed_json: Vec<ThunderstoreMod> = match serde_json::from_str(&res) { - Ok(res) => res, - Err(err) => return Err(err.to_string()), - }; - - // Remove some mods from listing - let to_remove_set: HashSet<&str> = BLACKLISTED_MODS.iter().copied().collect(); - let filtered_packages = parsed_json - .into_iter() - .filter(|package| !to_remove_set.contains(&package.full_name.as_ref())) - .collect::<Vec<ThunderstoreMod>>(); - - Ok(filtered_packages) -} |