Skip to content

Commit

Permalink
bye bye android, hello android32 and android64
Browse files Browse the repository at this point in the history
  • Loading branch information
Fleeym committed Feb 1, 2024
1 parent 3d16627 commit 7ea7581
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 25 deletions.
2 changes: 1 addition & 1 deletion migrations/20240102213218_first_migration.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ CREATE TYPE dependency_importance AS ENUM ('required', 'recommended', 'suggested
CREATE TYPE incompatibility_importance AS ENUM ('breaking', 'conflicting');
CREATE TYPE version_compare AS ENUM ('=', '>', '<', '>=', '=<');
CREATE TYPE gd_version as ENUM ('*', '2.113', '2.200', '2.204', '2.205');
CREATE TYPE gd_ver_platform as ENUM ('android', 'ios', 'mac', 'win');
CREATE TYPE gd_ver_platform as ENUM ('android32', 'android64', 'ios', 'mac', 'win');

CREATE TABLE mods (
id TEXT PRIMARY KEY NOT NULL,
Expand Down
7 changes: 5 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ async fn main() -> anyhow::Result<()> {
.max_connections(10)
.connect(&env_url).await?;
info!("Running migrations");
sqlx::migrate!("./migrations")
let migration_res = sqlx::migrate!("./migrations")
.run(&pool)
.await?;
.await;
if migration_res.is_err() {
log::error!("Error encountered while running migrations: {}", migration_res.err().unwrap());
}
let addr = "0.0.0.0";
let port = dotenvy::var("PORT").map_or(8080, |x: String| x.parse::<u16>().unwrap());
let debug = dotenvy::var("APP_DEBUG").unwrap_or("0".to_string()) == "1";
Expand Down
4 changes: 2 additions & 2 deletions src/types/mod_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub struct ModJson {
pub early_load: bool,
#[serde(default)]
pub api: bool,
pub gd: Option<ModJsonGDVersionType>,
pub gd: ModJsonGDVersionType,
pub about: Option<String>,
pub changelog: Option<String>,
pub dependencies: Option<Vec<ModJsonDependency>>,
Expand Down Expand Up @@ -84,7 +84,7 @@ impl ModJson {
let mut archive = match zip::ZipArchive::new(reader) {
Err(e) => {
log::error!("{}", e);
return Err(ApiError::FilesystemError);
return Err(ApiError::BadRequest("Couldn't unzip .geode file".to_string()));
},
Ok(a) => a
};
Expand Down
7 changes: 6 additions & 1 deletion src/types/models/mod_entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ impl Mod {
for i in query.platforms.unwrap().split(",") {
let trimmed = i.trim();
let platform = VerPlatform::from_str(trimmed).or(Err(ApiError::BadRequest(format!("Invalid platform {}", trimmed))))?;
platforms.push(platform)
if platform == VerPlatform::Android {
platforms.push(VerPlatform::Android32);
platforms.push(VerPlatform::Android64);
} else {
platforms.push(platform)
}
}
}
let mut builder: QueryBuilder<Postgres> = QueryBuilder::new(
Expand Down
45 changes: 32 additions & 13 deletions src/types/models/mod_gd_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ pub enum GDVersionEnum {
#[sqlx(type_name = "gd_ver_platform", rename_all = "lowercase")]
#[serde(rename_all = "lowercase")]
pub enum VerPlatform {
#[sqlx(skip)]
Android,
#[serde(skip_deserializing)]
Android32,
#[serde(skip_deserializing)]
Android64,
Ios,
Mac,
Win,
Expand All @@ -40,8 +45,8 @@ impl FromStr for VerPlatform {
fn from_str(s: &str) -> Result<Self, ()> {
match s {
"android" => Ok(VerPlatform::Android),
"android32" => Ok(VerPlatform::Android),
"android64" => Ok(VerPlatform::Android),
"android32" => Ok(VerPlatform::Android32),
"android64" => Ok(VerPlatform::Android64),
"ios" => Ok(VerPlatform::Ios),
"mac" => Ok(VerPlatform::Mac),
"win" => Ok(VerPlatform::Win),
Expand Down Expand Up @@ -74,19 +79,30 @@ pub struct DetailedGDVersion {
}

impl DetailedGDVersion {
pub fn to_create_payload(&self) -> Vec<ModGDVersionCreate> {
pub fn to_create_payload(&self, json: &ModJson) -> Vec<ModGDVersionCreate> {
let mut ret: Vec<_> = vec![];
if self.android.is_some() {
ret.push(ModGDVersionCreate { gd: self.android.unwrap(), platform: VerPlatform::Android });
if json.android32 {
ret.push(ModGDVersionCreate { gd: self.android.unwrap(), platform: VerPlatform::Android64 });
}
if json.android64 {
ret.push(ModGDVersionCreate { gd: self.android.unwrap(), platform: VerPlatform::Android32 })
}
}
if self.win.is_some() {
ret.push(ModGDVersionCreate { gd: self.win.unwrap(), platform: VerPlatform::Win });
if json.windows {
ret.push(ModGDVersionCreate { gd: self.win.unwrap(), platform: VerPlatform::Win });
}
}
if self.mac.is_some() {
ret.push(ModGDVersionCreate { gd: self.mac.unwrap(), platform: VerPlatform::Mac });
if json.mac {
ret.push(ModGDVersionCreate { gd: self.mac.unwrap(), platform: VerPlatform::Mac });
}
}
if self.ios.is_some() {
ret.push(ModGDVersionCreate { gd: self.ios.unwrap(), platform: VerPlatform::Ios });
if json.ios {
ret.push(ModGDVersionCreate { gd: self.ios.unwrap(), platform: VerPlatform::Ios });
}
}

ret
Expand Down Expand Up @@ -141,8 +157,11 @@ impl ModGDVersion {

pub async fn create_for_all_platforms(json: &ModJson, version: GDVersionEnum, version_id: i32, pool: &mut PgConnection) -> Result<(), ApiError> {
let mut platforms_arg: Vec<ModGDVersionCreate> = vec![];
if json.android32 || json.android64 {
platforms_arg.push(ModGDVersionCreate { gd: version, platform: VerPlatform::Android })
if json.android32 {
platforms_arg.push(ModGDVersionCreate { gd: version, platform: VerPlatform::Android32 })
}
if json.android64 {
platforms_arg.push(ModGDVersionCreate { gd: version, platform: VerPlatform::Android64 })
}
if json.windows {
platforms_arg.push(ModGDVersionCreate { gd: version, platform: VerPlatform::Win})
Expand Down Expand Up @@ -172,10 +191,10 @@ impl ModGDVersion {
let mut ret = DetailedGDVersion { win: None, mac: None, android: None, ios: None };
for i in result {
match i.platform {
VerPlatform::Android => { ret.android = Some(i.gd) },
VerPlatform::Android32 | VerPlatform::Android64 | VerPlatform::Android => { ret.android = Some(i.gd) },
VerPlatform::Win => { ret.win = Some(i.gd) },
VerPlatform::Mac => { ret.mac = Some(i.gd) },
VerPlatform::Ios => { ret.ios = Some(i.gd) }
VerPlatform::Ios => { ret.ios = Some(i.gd) },
}
}

Expand Down Expand Up @@ -210,7 +229,7 @@ impl ModGDVersion {
Entry::Vacant(e) => {
let mut ver = DetailedGDVersion::default();
match i.platform {
VerPlatform::Android => ver.android = Some(i.gd),
VerPlatform::Android | VerPlatform::Android32 | VerPlatform::Android64 => ver.android = Some(i.gd),
VerPlatform::Mac => ver.mac = Some(i.gd),
VerPlatform::Ios => ver.ios = Some(i.gd),
VerPlatform::Win => ver.win = Some(i.gd)
Expand All @@ -219,7 +238,7 @@ impl ModGDVersion {
},
Entry::Occupied(mut e) => {
match i.platform {
VerPlatform::Android => e.get_mut().android = Some(i.gd),
VerPlatform::Android | VerPlatform::Android32 | VerPlatform::Android64 => e.get_mut().android = Some(i.gd),
VerPlatform::Mac => e.get_mut().mac = Some(i.gd),
VerPlatform::Ios => e.get_mut().ios = Some(i.gd),
VerPlatform::Win => e.get_mut().win = Some(i.gd)
Expand Down
11 changes: 5 additions & 6 deletions src/types/models/mod_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,11 @@ impl ModVersion {
Ok(row) => row
};
let id = result.get::<i32, &str>("id");
match json.gd.as_ref() {
Some(gd) => match gd {
ModJsonGDVersionType::VersionStr(ver) => ModGDVersion::create_for_all_platforms(json, *ver, id, pool).await?,
ModJsonGDVersionType::VersionObj(vec) => ModGDVersion::create_from_json(vec.to_create_payload(), id, pool).await?
},
None => ()
match &json.gd {
ModJsonGDVersionType::VersionStr(ver) => ModGDVersion::create_for_all_platforms(json, *ver, id, pool).await?,
ModJsonGDVersionType::VersionObj(vec) => {
ModGDVersion::create_from_json(vec.to_create_payload(json), id, pool).await?;
}
}
if json.dependencies.as_ref().is_some_and(|x| !x.is_empty()) {
let dependencies = json.query_dependencies(pool).await?;
Expand Down

0 comments on commit 7ea7581

Please sign in to comment.