Skip to content

Commit

Permalink
initial commit for v2
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAlan404 committed May 4, 2024
1 parent da23550 commit 5acc9ac
Show file tree
Hide file tree
Showing 18 changed files with 318 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/api/app/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use anyhow::{Context, Result};

pub const APP_USER_AGENT: &str = concat!(

Check warning on line 3 in src/api/app/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

constant `APP_USER_AGENT` is never used

warning: constant `APP_USER_AGENT` is never used --> src/api/app/mod.rs:3:11 | 3 | pub const APP_USER_AGENT: &str = concat!( | ^^^^^^^^^^^^^^
env!("CARGO_PKG_NAME"),
"/",
env!("CARGO_PKG_VERSION"),
" - ",
env!("CARGO_PKG_REPOSITORY"),
);

pub struct App {

Check warning on line 11 in src/api/app/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

struct `App` is never constructed

warning: struct `App` is never constructed --> src/api/app/mod.rs:11:12 | 11 | pub struct App { | ^^^
http_client: reqwest::Client,
}

impl App {
pub fn new() -> Result<Self> {

Check warning on line 16 in src/api/app/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

associated function `new` is never used

warning: associated function `new` is never used --> src/api/app/mod.rs:16:12 | 15 | impl App { | -------- associated function in this implementation 16 | pub fn new() -> Result<Self> { | ^^^
let http_client = reqwest::Client::builder()
.user_agent(APP_USER_AGENT)
.build()
.context("Initializing http_client")?;

Ok(Self {
http_client,
})
}
}
3 changes: 3 additions & 0 deletions src/api/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod models;
pub mod app;
pub mod tools;
21 changes: 21 additions & 0 deletions src/api/models/addon.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use anyhow::Result;

use crate::app::AddonType;

use super::{Environment, Step};

pub enum AddonTarget {

Check warning on line 7 in src/api/models/addon.rs

View workflow job for this annotation

GitHub Actions / clippy

enum `AddonTarget` is never used

warning: enum `AddonTarget` is never used --> src/api/models/addon.rs:7:10 | 7 | pub enum AddonTarget { | ^^^^^^^^^^^
Plugin,
Mod,
}

pub struct Addon {

Check warning on line 12 in src/api/models/addon.rs

View workflow job for this annotation

GitHub Actions / clippy

struct `Addon` is never constructed

warning: struct `Addon` is never constructed --> src/api/models/addon.rs:12:12 | 12 | pub struct Addon { | ^^^^^
pub environment: Option<Environment>,
pub addon_type: AddonType,
}

impl Addon {
async fn resolve_steps(&self) -> Result<Vec<Step>> {

Check warning on line 18 in src/api/models/addon.rs

View workflow job for this annotation

GitHub Actions / clippy

method `resolve_steps` is never used

warning: method `resolve_steps` is never used --> src/api/models/addon.rs:18:14 | 17 | impl Addon { | ---------- method in this implementation 18 | async fn resolve_steps(&self) -> Result<Vec<Step>> { | ^^^^^^^^^^^^^
Ok(vec![])
}
}
26 changes: 26 additions & 0 deletions src/api/models/addon_source.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use anyhow::Result;
use serde::{Deserialize, Serialize};

use super::{ModpackSource, Addon};


#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub enum AddonSource {
File {
path: String,
},

Folder {
path: String,
},

Modpack {
modpack: ModpackSource,
},
}

impl AddonSource {
async fn resolve(&self) -> Result<Vec<Addon>> {

Check warning on line 23 in src/api/models/addon_source.rs

View workflow job for this annotation

GitHub Actions / clippy

method `resolve` is never used

warning: method `resolve` is never used --> src/api/models/addon_source.rs:23:14 | 22 | impl AddonSource { | ---------------- method in this implementation 23 | async fn resolve(&self) -> Result<Vec<Addon>> { | ^^^^^^^ | = note: `#[warn(dead_code)]` on by default
Ok(vec![])
}

Check warning on line 25 in src/api/models/addon_source.rs

View workflow job for this annotation

GitHub Actions / clippy

unused `async` for function with no await statements

warning: unused `async` for function with no await statements --> src/api/models/addon_source.rs:23:5 | 23 | / async fn resolve(&self) -> Result<Vec<Addon>> { 24 | | Ok(vec![]) 25 | | } | |_____^ | = help: consider removing the `async` from this function = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unused_async = note: `-W clippy::unused-async` implied by `-W clippy::pedantic` = help: to override `-W clippy::pedantic` add `#[allow(clippy::unused_async)]`
}
3 changes: 3 additions & 0 deletions src/api/models/addon_type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub enum AddonType {

}
10 changes: 10 additions & 0 deletions src/api/models/env.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Hash, Default)]
#[serde(rename_all = "lowercase")]
pub enum Environment {
#[default]
Both,
Server,
Client,
}
14 changes: 14 additions & 0 deletions src/api/models/hash.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Hash, Default)]
#[serde(rename_all = "lowercase")]
#[non_exhaustive]
pub enum HashFormat {
Sha256,
Sha512,
Sha1,
Md5,
#[serde(rename = "murmur2")]
#[default]
Curseforge,
}
19 changes: 19 additions & 0 deletions src/api/models/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
mod server;
mod addon_source;
mod modpack_source;
mod step;
mod addon;
mod env;
mod packwiz;
mod mrpack;
mod hash;

pub use server::*;

Check warning on line 11 in src/api/models/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

unused import: `server::*`

warning: unused import: `server::*` --> src/api/models/mod.rs:11:9 | 11 | pub use server::*; | ^^^^^^^^^
pub use addon_source::*;
pub use modpack_source::*;
pub use step::*;
pub use addon::*;
pub use env::*;
pub use packwiz::*;

Check warning on line 17 in src/api/models/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

unused import: `packwiz::*`

warning: unused import: `packwiz::*` --> src/api/models/mod.rs:17:9 | 17 | pub use packwiz::*; | ^^^^^^^^^^
pub use mrpack::*;

Check warning on line 18 in src/api/models/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

unused import: `mrpack::*`

warning: unused import: `mrpack::*` --> src/api/models/mod.rs:18:9 | 18 | pub use mrpack::*; | ^^^^^^^^^
pub use hash::*;
21 changes: 21 additions & 0 deletions src/api/models/modpack_source.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub enum ModpackSource {
Local {
modpack_type: ModpackType,
path: String,
},

Remote {
modpack_type: ModpackType,
url: String,
},
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub enum ModpackType {
Packwiz,
MRPack,
Unsup,
}
Empty file added src/api/models/mrpack/mod.rs
Empty file.
5 changes: 5 additions & 0 deletions src/api/models/packwiz/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mod packwiz_mod;
mod packwiz_pack;

pub use packwiz_pack::*;

Check warning on line 4 in src/api/models/packwiz/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

unused import: `packwiz_pack::*`

warning: unused import: `packwiz_pack::*` --> src/api/models/packwiz/mod.rs:4:9 | 4 | pub use packwiz_pack::*; | ^^^^^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default
pub use packwiz_mod::*;

Check warning on line 5 in src/api/models/packwiz/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

unused import: `packwiz_mod::*`

warning: unused import: `packwiz_mod::*` --> src/api/models/packwiz/mod.rs:5:9 | 5 | pub use packwiz_mod::*; | ^^^^^^^^^^^^^^
56 changes: 56 additions & 0 deletions src/api/models/packwiz/packwiz_mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
use serde::{Deserialize, Serialize};

use crate::api::models::{Environment, HashFormat};

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash, Default)]
#[serde(default)]
pub struct PackwizMod {
pub name: String,
pub filename: String,
pub download: PackwizModDownload,
pub option: PackwizModOption,
pub side: Environment,
pub update: Option<PackwizModUpdate>,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash, Default)]
pub struct PackwizModOption {
pub optional: bool,
pub default: bool,
pub description: Option<String>,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash, Default)]
#[serde(rename_all = "kebab-case")]
pub struct PackwizModDownload {
pub url: Option<String>,
pub hash: String,
pub hash_format: HashFormat,
#[serde(default)]
pub mode: PackwizDownloadMode,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash, Default)]
#[serde(rename_all = "lowercase")]
pub enum PackwizDownloadMode {
#[default]
#[serde(alias = "")]
Url,
#[serde(rename = "metadata:curseforge")]
Curseforge,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)]
#[serde(rename_all = "lowercase")]
pub enum PackwizModUpdate {
#[serde(rename_all = "kebab-case")]
Modrinth {
mod_id: String,
version: String,
},
#[serde(rename_all = "kebab-case")]
Curseforge {
file_id: u64,
project_id: u64,
},
}
40 changes: 40 additions & 0 deletions src/api/models/packwiz/packwiz_pack.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use std::collections::HashMap;

use serde::{Deserialize, Serialize};

use crate::api::models::HashFormat;

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
#[serde(rename_all = "kebab-case")]
pub struct PackwizPack {
pub name: String,
pub author: Option<String>,
pub version: Option<String>,
pub description: Option<String>,
pub pack_format: String,
pub index: PackwizPackFile,
pub versions: HashMap<String, String>,
}

pub static PACK_TOML: &str = "pack.toml";

Check warning on line 19 in src/api/models/packwiz/packwiz_pack.rs

View workflow job for this annotation

GitHub Actions / clippy

static `PACK_TOML` is never used

warning: static `PACK_TOML` is never used --> src/api/models/packwiz/packwiz_pack.rs:19:12 | 19 | pub static PACK_TOML: &str = "pack.toml"; | ^^^^^^^^^

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)]
#[serde(rename_all = "kebab-case")]
pub struct PackwizPackIndex {
pub hash_format: HashFormat,
pub files: Vec<PackwizPackFile>,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)]
#[serde(rename_all = "kebab-case")]
pub struct PackwizPackFile {
pub file: String,
pub hash: String,
pub hash_format: Option<String>,

pub alias: Option<String>,
#[serde(default)]
pub metafile: bool,
#[serde(default)]
pub preserve: bool,
}
23 changes: 23 additions & 0 deletions src/api/models/server.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use serde::{Serialize, Deserialize};

use super::AddonSource;

#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
#[serde(default)]
pub struct Server {
name: String,
port: Option<i32>,

sources: Vec<AddonSource>,
}

impl Default for Server {
fn default() -> Self {
Self {
name: String::from("server"),
port: None,

sources: vec![],
}
}
}
49 changes: 49 additions & 0 deletions src/api/models/step.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use std::collections::HashMap;

use anyhow::Result;
use serde::{Deserialize, Serialize};

use super::HashFormat;

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type")]
pub enum Step {
CacheCheck(CacheStrategy),
Download {
url: String,
filename: String,
size: Option<i32>,
hashes: HashMap<HashFormat, String>,
},
Execute,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default)]
#[serde(tag = "type")]
pub enum CacheStrategy {
File {
namespace: String,
path: String,
},
Indexed {
index_path: String,
key: String,
value: String,
},
#[default]
None,
}

pub enum StepResult {

Check warning on line 37 in src/api/models/step.rs

View workflow job for this annotation

GitHub Actions / clippy

enum `StepResult` is never used

warning: enum `StepResult` is never used --> src/api/models/step.rs:37:10 | 37 | pub enum StepResult { | ^^^^^^^^^^
// continue into running next step
Continue,
// skip next steps for this addon
// example: addon is already downloaded / cache hit
Skip,
}

impl Step {
async fn run(&self) -> Result<StepResult> {

Check warning on line 46 in src/api/models/step.rs

View workflow job for this annotation

GitHub Actions / clippy

method `run` is never used

warning: method `run` is never used --> src/api/models/step.rs:46:14 | 45 | impl Step { | --------- method in this implementation 46 | async fn run(&self) -> Result<StepResult> { | ^^^
Ok(StepResult::Continue)
}

Check warning on line 48 in src/api/models/step.rs

View workflow job for this annotation

GitHub Actions / clippy

unused `async` for function with no await statements

warning: unused `async` for function with no await statements --> src/api/models/step.rs:46:5 | 46 | / async fn run(&self) -> Result<StepResult> { 47 | | Ok(StepResult::Continue) 48 | | } | |_____^ | = help: consider removing the `async` from this function = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unused_async
}
Empty file added src/api/tools/java/mod.rs
Empty file.
1 change: 1 addition & 0 deletions src/api/tools/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod java;
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use anyhow::Result;
use app::BaseApp;
use clap::Parser;

mod api;
mod app;
mod commands;
mod core;
Expand Down

0 comments on commit 5acc9ac

Please sign in to comment.