Skip to content

Commit

Permalink
mcman migrate
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAlan404 committed Jul 17, 2024
1 parent 34bcedb commit a41a167
Show file tree
Hide file tree
Showing 27 changed files with 717 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/api/app/actions/build/bootstrap.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{collections::HashSet, path::Path, sync::Arc};
use std::{path::Path, sync::Arc};

use anyhow::{Context, Result};
use futures::{StreamExt, TryStreamExt};
Expand Down
4 changes: 2 additions & 2 deletions src/api/app/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ impl App {

pub async fn save_changes(&self) -> Result<()> {

Check warning on line 21 in src/api/app/io.rs

View workflow job for this annotation

GitHub Actions / clippy

method `save_changes` is never used

warning: method `save_changes` is never used --> src/api/app/io.rs:21:18 | 10 | impl App { | -------- method in this implementation ... 21 | pub async fn save_changes(&self) -> Result<()> { | ^^^^^^^^^^^^
if let Some((path, server)) = &*self.server.read().await {
write_toml(&path, SERVER_TOML, &server)?;
write_toml(path.parent().unwrap(), SERVER_TOML, &server)?;
}

if let Some((path, network)) = &*self.network.read().await {
write_toml(&path, NETWORK_TOML, &network)?;
write_toml(path.parent().unwrap(), NETWORK_TOML, &network)?;
}

Ok(())
Expand Down
4 changes: 3 additions & 1 deletion src/api/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ impl App {
ci,
};

app.try_read_files()?;
if let Err(e) = app.try_read_files() {
println!("Error while reading files: {e:?}");
}

Ok(app)
}
Expand Down
1 change: 1 addition & 0 deletions src/api/models/addon/addon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use super::{AddonTarget, AddonType};

#[derive(Debug, Deserialize, Serialize, Clone, Hash, PartialEq, Eq)]
pub struct Addon {
#[serde(alias = "side")]
pub environment: Option<Environment>,
#[serde(flatten)]
pub addon_type: AddonType,

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

View workflow job for this annotation

GitHub Actions / clippy

field name starts with the struct's name

warning: field name starts with the struct's name --> src/api/models/addon/addon.rs:13:5 | 13 | pub addon_type: AddonType, | ^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#struct_field_names = note: `-W clippy::struct-field-names` implied by `-W clippy::pedantic` = help: to override `-W clippy::pedantic` add `#[allow(clippy::struct_field_names)]`
Expand Down
13 changes: 7 additions & 6 deletions src/api/models/addon/addon_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ use std::path::{Path, PathBuf};
use serde::{Deserialize, Serialize};

#[derive(Debug, Deserialize, Serialize, Clone, Hash, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum AddonTarget {
Plugin,
Mod,
Plugins,
Mods,
Custom(String),
}

Expand All @@ -18,16 +19,16 @@ impl Default for AddonTarget {
impl AddonTarget {
pub fn from_str(str: &str) -> Self {
match str {
"mods" => AddonTarget::Mod,
"plugins" => AddonTarget::Plugin,
"mods" => AddonTarget::Mods,
"plugins" => AddonTarget::Plugins,
other => AddonTarget::Custom(other.to_owned()),
}
}

pub fn as_str(&self) -> &str {
match self {
AddonTarget::Mod => "mods",
AddonTarget::Plugin => "plugins",
AddonTarget::Mods => "mods",
AddonTarget::Plugins => "plugins",
AddonTarget::Custom(path) => path.as_str(),
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/api/models/addon/holders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ use serde::{Deserialize, Serialize};

use super::{Addon, AddonTarget, AddonType};

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct AddonListFile {
#[serde(default = "Vec::new")]
#[serde(skip_serializing_if = "Vec::is_empty")]
pub addons: Vec<Addon>,

// backwards compatability
#[serde(default = "Vec::new")]
#[serde(skip_serializing_if = "Vec::is_empty")]
pub mods: Vec<AddonType>,
#[serde(default = "Vec::new")]
#[serde(skip_serializing_if = "Vec::is_empty")]
pub plugins: Vec<AddonType>,
}

Expand All @@ -24,7 +27,7 @@ impl AddonListFile {
Addon {
environment: None,
addon_type,
target: AddonTarget::Mod,
target: AddonTarget::Mods,
}
})
.collect(),
Expand All @@ -34,7 +37,7 @@ impl AddonListFile {
Addon {
environment: None,
addon_type,
target: AddonTarget::Plugin,
target: AddonTarget::Plugins,
}
}).collect()
].concat()
Expand Down
52 changes: 52 additions & 0 deletions src/api/models/hooks/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
use std::collections::HashMap;

use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct Hook {
pub when: HookEvent,
#[serde(default)]
pub onfail: HookFailBehavior,
#[serde(default = "bool_true")]
pub show_output: bool,
#[serde(default)]
pub description: String,
#[serde(default)]
pub disabled: bool,
#[serde(default)]
pub env: HashMap<String, String>,

pub windows: Option<String>,
pub linux: Option<String>,
}

fn bool_true() -> bool {
true
}

#[derive(Debug, Serialize, Deserialize, Clone, Hash, PartialEq, Default)]
#[serde(rename_all = "lowercase")]
pub enum HookEvent {
#[default]
None,
PreBuild,
PostBuild,
PreInstall,
PostInstall,
PreWorldUnpack,
PostWorldUnpack,
PreWorldPack,
PostWorldPack,
DevSessionStart,
DevSessionEnd,
TestSuccess,
TestFail,
}

#[derive(Debug, Serialize, Deserialize, Clone, Hash, PartialEq, Default)]
pub enum HookFailBehavior {
#[default]
Error,
Ignore,
Warn,
}
12 changes: 12 additions & 0 deletions src/api/models/legacy/clientsidemod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use serde::{Deserialize, Serialize};

use super::LegacyDownloadable;

#[derive(Debug, Serialize, Deserialize, Clone, Hash, PartialEq, Eq)]
pub struct LegacyClientSideMod {
#[serde(flatten)]
pub dl: LegacyDownloadable,

pub optional: bool,
pub desc: String,
}
80 changes: 80 additions & 0 deletions src/api/models/legacy/downloadable.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
use serde::{Deserialize, Serialize};

#[derive(Debug, Deserialize, Serialize, Clone, Hash, PartialEq, Eq)]
#[serde(tag = "type", rename_all = "lowercase")]
pub enum LegacyDownloadable {
// sources
Url {
url: String,
#[serde(default)]
#[serde(skip_serializing_if = "crate::api::utils::serde::is_default")]
filename: Option<String>,
#[serde(default)]
#[serde(skip_serializing_if = "crate::api::utils::serde::is_default")]
desc: Option<String>,
},

#[serde(alias = "mr")]
Modrinth {
id: String,
#[serde(default = "latest")]
version: String,
},

#[serde(alias = "cr")]
CurseRinth {
id: String,
#[serde(default = "latest")]
version: String,
},

Spigot {
id: String,
#[serde(default = "latest")]
version: String,
},

Hangar {
id: String,
version: String,
},

#[serde(rename = "ghrel")]
GithubRelease {
repo: String,
tag: String,
asset: String,
},

// pain in the a-
Jenkins {
url: String,
job: String,
#[serde(default = "latest")]
build: String,
#[serde(default = "first")]
artifact: String,
},

Maven {
url: String,
group: String,
artifact: String,
#[serde(default = "latest")]
version: String,
#[serde(default = "artifact")]
filename: String,
},
}

pub fn latest() -> String {
"latest".to_owned()
}

pub fn first() -> String {
"first".to_owned()
}

pub fn artifact() -> String {
"artifact".to_owned()
}
Empty file added src/api/models/legacy/hook.rs
Empty file.
23 changes: 23 additions & 0 deletions src/api/models/legacy/markdown_options.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use serde::{Deserialize, Serialize};

#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
#[serde(default)]
pub struct LegacyMarkdownOptions {
pub files: Vec<String>,
pub auto_update: bool,
}

impl Default for LegacyMarkdownOptions {
fn default() -> Self {
Self {
files: vec!["README.md".to_owned()],
auto_update: false,
}
}
}

impl LegacyMarkdownOptions {
pub fn is_empty(&self) -> bool {
self.files.is_empty()
}
}
22 changes: 22 additions & 0 deletions src/api/models/legacy/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
mod downloadable;
mod world;
mod clientsidemod;
mod markdown_options;
mod server;
mod server_options;
mod server_type;
mod server_launcher;
mod network;
mod hook;

pub use downloadable::*;
pub use world::*;
pub use clientsidemod::*;
pub use markdown_options::*;
pub use server::*;
pub use server_options::*;
pub use server_type::*;
pub use server_launcher::*;

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

View workflow job for this annotation

GitHub Actions / clippy

unused import: `server_launcher::*`

warning: unused import: `server_launcher::*` --> src/api/models/legacy/mod.rs:19:9 | 19 | pub use server_launcher::*; | ^^^^^^^^^^^^^^^^^^
pub use network::*;

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

View workflow job for this annotation

GitHub Actions / clippy

unused import: `network::*`

warning: unused import: `network::*` --> src/api/models/legacy/mod.rs:20:9 | 20 | pub use network::*; | ^^^^^^^^^^
pub use hook::*;

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

View workflow job for this annotation

GitHub Actions / clippy

unused import: `hook::*`

warning: unused import: `hook::*` --> src/api/models/legacy/mod.rs:21:9 | 21 | pub use hook::*; | ^^^^^^^

68 changes: 68 additions & 0 deletions src/api/models/legacy/network.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
use std::collections::HashMap;

use serde::{Deserialize, Serialize};

use crate::api::models::hooks::Hook;

use super::{LegacyDownloadable, LegacyMarkdownOptions};

#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(default)]
pub struct LegacyNetwork {
pub name: String,
pub proxy: String,
#[serde(default)]
#[serde(skip_serializing_if = "Vec::is_empty")]
pub proxy_groups: Vec<String>,
pub port: u16,
pub servers: HashMap<String, LegacyServerEntry>,
pub variables: HashMap<String, String>,

#[serde(default)]
#[serde(skip_serializing_if = "LegacyMarkdownOptions::is_empty")]
pub markdown: LegacyMarkdownOptions,

#[serde(default)]
#[serde(skip_serializing_if = "HashMap::is_empty")]
pub hooks: HashMap<String, Hook>,

#[serde(default)]
#[serde(skip_serializing_if = "HashMap::is_empty")]
pub groups: HashMap<String, LegacyGroup>,
}

#[derive(Debug, Deserialize, Serialize, Default, Clone)]
#[serde(default)]
pub struct LegacyServerEntry {
pub port: u16,
pub ip_address: Option<String>,
#[serde(skip_serializing_if = "Vec::is_empty")]
pub groups: Vec<String>,
}

#[derive(Debug, Default, Deserialize, Serialize, Clone)]
#[serde(default)]
pub struct LegacyGroup {
#[serde(default)]
pub variables: HashMap<String, String>,
#[serde(skip_serializing_if = "Vec::is_empty")]
pub plugins: Vec<LegacyDownloadable>,
#[serde(skip_serializing_if = "Vec::is_empty")]
pub mods: Vec<LegacyDownloadable>,
}

impl Default for LegacyNetwork {
fn default() -> Self {
Self {
name: String::new(),
proxy: "proxy".to_owned(),
proxy_groups: vec![],
port: 25565,
servers: HashMap::new(),
variables: HashMap::new(),
markdown: LegacyMarkdownOptions::default(),
hooks: HashMap::new(),
groups: HashMap::new(),
}
}
}
Loading

0 comments on commit a41a167

Please sign in to comment.