feat: model improvements

This commit is contained in:
Timo Ley 2022-12-15 21:02:26 +01:00
parent 985c3af906
commit 3df0dc88bf
2 changed files with 17 additions and 7 deletions

View file

@ -1,4 +1,6 @@
use addonscript_versioning::Version;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use url::Url;
use crate::AddonDescriptor; use crate::AddonDescriptor;
@ -8,14 +10,14 @@ use super::{AddonScript, File, Hashes, Meta};
pub struct APIAddon { pub struct APIAddon {
pub id: String, pub id: String,
pub namespace: String, pub namespace: String,
pub versions: Vec<String>, pub versions: Vec<Version>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub meta: Option<Meta>, pub meta: Option<Meta>,
} }
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
pub struct APIFile { pub struct APIFile {
pub link: Vec<String>, pub link: Vec<Url>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub hashes: Option<Hashes>, pub hashes: Option<Hashes>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]

View file

@ -2,6 +2,7 @@ use std::collections::HashSet;
use addonscript_versioning::{Version, VersionRestriction}; use addonscript_versioning::{Version, VersionRestriction};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use url::Url;
pub use self::{ pub use self::{
enums::{Flag, InstallAction}, enums::{Flag, InstallAction},
@ -31,7 +32,7 @@ pub struct Manifest {
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
pub struct VersionlessManifest { pub struct VersionlessManifest {
pub addonscript: AddonScript, pub addonscript: Option<AddonScript>,
} }
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
@ -49,13 +50,13 @@ impl Default for AddonScript {
pub struct AddonDescriptor { pub struct AddonDescriptor {
pub id: String, pub id: String,
pub namespace: String, pub namespace: String,
pub version: Option<String>, pub version: Option<Version>,
} }
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Repository { pub struct Repository {
pub namespace: String, pub namespace: String,
pub instances: Vec<String>, pub instances: Vec<Url>,
} }
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
@ -106,8 +107,15 @@ pub struct Flags {
} }
impl VersionlessManifest { impl VersionlessManifest {
pub fn get_version(&self) -> u8 {
match &self.addonscript {
Some(addonscript) => addonscript.version,
None => 1,
}
}
pub fn is_version_valid(&self) -> bool { pub fn is_version_valid(&self) -> bool {
self.addonscript.version == 2 self.get_version() == 2
} }
} }