Skip to content

Commit

Permalink
Merge pull request #203 from Polyfrost/feat/curseforge
Browse files Browse the repository at this point in the history
Feature: Implement Curseforge Package API
  • Loading branch information
LynithDev authored Oct 17, 2024
2 parents 4a63c96 + 26d957b commit 3745ed0
Show file tree
Hide file tree
Showing 34 changed files with 1,681 additions and 467 deletions.
3 changes: 3 additions & 0 deletions .template.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#! Use single quotes due to special characters and dotenvy being weird

CURSEFORGE_API_KEY = ''
9 changes: 8 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ zeroize = { version = "1.8", features = [ "zeroize_derive" ] }
serde = { version = "1.0", features = [ "derive" ] }
serde_json = { version = "1.0" }
serde_ini = { version = "0.2" }
serde_repr = { version = "0.1" }
regex = { version = "1.10" }
url = { version = "2.5.2" }
strum = { version = "0.26", features = [ "derive" ] }
Expand Down Expand Up @@ -179,6 +180,7 @@ cocoa = { version = "0.26" }
objc = { version = "0.2" }
cc = { version = "1.1" }
libc = { version = "0.2" }
dotenvy = { git = "https://github.com/allan2/dotenvy/", rev = "db0d6aa8fc8d1b0ddbfe94b5c833372e463eb1c5" }
# https://github.com/tauri-apps/tauri/blob/dev/crates/tauri/Cargo.toml#L102
webkit2gtk = { version = "=2.0.1", features = [ "v2_40" ] }

Expand Down
1 change: 1 addition & 0 deletions apps/desktop/src/api/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ macro_rules! collect_commands {
get_provider_package_version,
search_provider_packages,
get_provider_authors,
get_package_body,
download_provider_package,
// Cluster Packages
get_cluster_package,
Expand Down
20 changes: 16 additions & 4 deletions apps/desktop/src/api/commands/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use onelauncher::cluster::content::package;
use onelauncher::data::{Loader, ManagedPackage, ManagedUser, ManagedVersion, PackageType};
use onelauncher::package::content::Providers;
use onelauncher::package::import::{default_launcher_path, ImportType};
use onelauncher::store::{Author, ClusterPath, Package, PackagePath, ProviderSearchResults};
use onelauncher::store::{
Author, ClusterPath, Package, PackageBody, PackagePath, ProviderSearchResults,
};
use onelauncher::utils::pagination::Pagination;
use uuid::Uuid;

#[specta::specta]
Expand Down Expand Up @@ -49,9 +52,11 @@ pub async fn get_all_provider_package_versions(
project_id: String,
game_versions: Option<Vec<String>>,
loaders: Option<Vec<Loader>>,
) -> Result<Vec<ManagedVersion>, String> {
page: Option<u32>,
page_size: Option<u16>,
) -> Result<(Vec<ManagedVersion>, Pagination), String> {
Ok(provider
.get_all_versions(&project_id, game_versions, loaders)
.get_all_versions(&project_id, game_versions, loaders, page, page_size)
.await?)
}

Expand All @@ -70,7 +75,7 @@ pub async fn get_provider_package_version(
provider: Providers,
version: String,
) -> Result<ManagedVersion, String> {
Ok(provider.get_version(&version).await?)
Ok(provider.get_version("", &version).await?) // TODO
}

#[derive(specta::Type, serde::Deserialize, serde::Serialize)]
Expand Down Expand Up @@ -114,6 +119,12 @@ pub async fn get_provider_authors(
Ok(provider.get_authors(&author).await?)
}

#[specta::specta]
#[tauri::command]
pub async fn get_package_body(provider: Providers, body: PackageBody) -> Result<String, String> {
Ok(provider.get_package_body(&body).await?)
}

#[specta::specta]
#[tauri::command]
pub async fn download_provider_package(
Expand All @@ -138,6 +149,7 @@ pub async fn download_provider_package(
package_version,
)
.await?;

package::add_package(
&cluster.cluster_path(),
pkg_path,
Expand Down
15 changes: 8 additions & 7 deletions apps/frontend/src/ui/components/content/SearchResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ interface SearchResultsContainerProps {
provider: Providers;
results: SearchResult[];
header: string | JSX.Element;
category: string;
collapsable?: boolean;
}

Expand Down Expand Up @@ -56,7 +55,7 @@ function SearchResultsContainer(props: SearchResultsContainerProps) {
</div>

<Show when={collapsed() === true}>
<div class="absolute bottom-4 left-1/2 z-2 -translate-x-1/2">
<div class="w-full flex items-center justify-center">
<Button
buttonStyle="secondary"
children="Show more"
Expand Down Expand Up @@ -146,7 +145,7 @@ function PackageItem(props: SearchResult & { provider: Providers; row?: boolean
</div>
<div class="flex flex-1 flex-col gap-2 p-3">
<div class="flex flex-col gap-2">
<h4 class="text-fg-primary font-medium">{props.title}</h4>
<h4 class="text-fg-primary font-medium line-height-normal">{props.title}</h4>
<p class="text-xs text-fg-secondary">
By
{' '}
Expand All @@ -166,10 +165,12 @@ function PackageItem(props: SearchResult & { provider: Providers; row?: boolean
{abbreviateNumber(props.downloads)}
</div>

<div class="flex flex-row items-center gap-2">
<HeartIcon class="h-4 w-4" />
{abbreviateNumber(props.follows)}
</div>
<Show when={props.follows > 0}>
<div class="flex flex-row items-center gap-2">
<HeartIcon class="h-4 w-4" />
{abbreviateNumber(props.follows)}
</div>
</Show>
</div>
</div>
</div>
Expand Down
Loading

0 comments on commit 3745ed0

Please sign in to comment.