diff --git a/.gitignore b/.gitignore index ed575ceb1..499bff711 100644 --- a/.gitignore +++ b/.gitignore @@ -105,4 +105,5 @@ fabric.properties **/*.rs.bk # MSVC Windows builds of rustc generate these, which store debugging information -*.pdb \ No newline at end of file +*.pdb + diff --git a/theseus/src/state/metadata.rs b/theseus/src/state/metadata.rs index 76f9713db..6fdef0839 100644 --- a/theseus/src/state/metadata.rs +++ b/theseus/src/state/metadata.rs @@ -12,6 +12,7 @@ use std::collections::LinkedList; const METADATA_URL: &str = "https://meta.modrinth.com/gamedata"; const METADATA_DB_FIELD: &[u8] = b"metadata"; +const RETRY_ATTEMPTS: i32 = 3; // TODO: store as subtree in database #[derive(Encode, Decode, Debug)] @@ -49,6 +50,7 @@ impl Metadata { }) } + // Attempt to fetch metadata and store in sled DB #[tracing::instrument(skip_all)] pub async fn init(db: &sled::Db) -> crate::Result { let mut metadata = None; @@ -66,7 +68,7 @@ impl Metadata { } let mut fetch_futures = LinkedList::new(); - for _ in 0..3 { + for _ in 0..RETRY_ATTEMPTS { fetch_futures.push_back(Self::fetch().boxed()); } diff --git a/theseus/src/state/profiles.rs b/theseus/src/state/profiles.rs index 36e8390d3..dd4ad71ef 100644 --- a/theseus/src/state/profiles.rs +++ b/theseus/src/state/profiles.rs @@ -21,6 +21,7 @@ pub const SUPPORTED_ICON_FORMATS: &[&'static str] = &[ "mp4", ]; +// Represent a Minecraft instance. #[derive(Serialize, Deserialize, Clone, Debug)] pub struct Profile { #[serde(skip)] diff --git a/theseus_gui/src/routes/search/index.svelte b/theseus_gui/src/routes/search/index.svelte index b4b08704d..a8ee69c00 100644 --- a/theseus_gui/src/routes/search/index.svelte +++ b/theseus_gui/src/routes/search/index.svelte @@ -24,12 +24,26 @@ import ProjectCard from '$components/ProjectCard.svelte'; export let projects; + export let searchQuery = ""; + + export const searchProjects = async (query) => { + const encodedQuery = encodeURI(query); + const response = await fetch( + `https://api.modrinth.com/v2/search?query=${encodedQuery}&limit=10&offset=0&index=relevance` + ); + + return response.ok && (await response.json()).hits; + }; + + export async function search(event) { + projects = await searchProjects(searchQuery); + };
- - + +