init
This commit is contained in:
commit
5206d56cf8
7 changed files with 278 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
/target
|
||||
Cargo.lock
|
9
Cargo.toml
Normal file
9
Cargo.toml
Normal file
|
@ -0,0 +1,9 @@
|
|||
[workspace]
|
||||
members = [
|
||||
"crates/*",
|
||||
]
|
||||
default-members = ["crates/*"]
|
||||
resolver = "2"
|
||||
|
||||
[workspace.package]
|
||||
rust-version = "1.65"
|
9
crates/model/Cargo.toml
Normal file
9
crates/model/Cargo.toml
Normal file
|
@ -0,0 +1,9 @@
|
|||
[package]
|
||||
name = "addonscript-model"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
url = {version = "2.2.2", features = ["serde"]}
|
52
crates/model/src/api.rs
Normal file
52
crates/model/src/api.rs
Normal file
|
@ -0,0 +1,52 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::{AddonScript, File, Hashes, Meta};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct APIAddon {
|
||||
pub id: String,
|
||||
pub namespace: String,
|
||||
pub versions: Vec<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub meta: Option<Meta>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct APIFile {
|
||||
pub link: Vec<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub hashes: Option<Hashes>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub meta: Option<Meta>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct AddonDescriptor {
|
||||
pub id: String,
|
||||
pub namespace: String,
|
||||
pub version: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct EnvObject {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub requested: Option<Vec<AddonDescriptor>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub provided: Option<Vec<AddonDescriptor>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct EnvBuilderRequest {
|
||||
pub addonscript: AddonScript,
|
||||
pub addon: AddonDescriptor,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub client: Option<EnvObject>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub server: Option<EnvObject>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct EnvBuilderResponse {
|
||||
pub addonscript: AddonScript,
|
||||
pub files: Vec<File>,
|
||||
}
|
23
crates/model/src/enums.rs
Normal file
23
crates/model/src/enums.rs
Normal file
|
@ -0,0 +1,23 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum Flag {
|
||||
Required,
|
||||
Optional,
|
||||
Included,
|
||||
Instance,
|
||||
Incompatible,
|
||||
Launch,
|
||||
Env
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum InstallAction {
|
||||
Move,
|
||||
Extract,
|
||||
Rename,
|
||||
Inject,
|
||||
Unknown(String),
|
||||
}
|
133
crates/model/src/lib.rs
Normal file
133
crates/model/src/lib.rs
Normal file
|
@ -0,0 +1,133 @@
|
|||
use std::collections::HashSet;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub use self::{enums::{Flag, InstallAction}, meta::*};
|
||||
|
||||
pub mod api;
|
||||
pub mod meta;
|
||||
pub mod enums;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct Manifest {
|
||||
pub addonscript: AddonScript,
|
||||
pub id: String,
|
||||
pub namespace: String,
|
||||
pub version: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub files : Option<Vec<File>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub relations: Option<Vec<Relation>>,
|
||||
pub flags: Flags,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub repositories: Option<Vec<Repository>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub meta: Option<Meta>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct VersionlessManifest {
|
||||
pub addonscript: AddonScript,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct AddonScript {
|
||||
pub version: u8,
|
||||
}
|
||||
|
||||
impl Default for AddonScript {
|
||||
fn default() -> Self {
|
||||
Self { version: 2 }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct Repository {
|
||||
pub namespace: String,
|
||||
pub instances: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct Relation {
|
||||
pub id: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub namespace: Option<String>,
|
||||
pub version: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub repositories: Option<Vec<String>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub flags: Option<Flags>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct File {
|
||||
pub qualifier: String,
|
||||
pub link: Vec<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub install: Option<Vec<Install>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub flags: Option<Flags>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub hashes: Option<Hashes>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct Hashes {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub sha1: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct Install {
|
||||
pub action: InstallAction,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub args: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct Flags {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub client: Option<HashSet<Flag>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub server: Option<HashSet<Flag>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub both: Option<HashSet<Flag>>,
|
||||
}
|
||||
|
||||
impl VersionlessManifest {
|
||||
pub fn is_version_valid(&self) -> bool {
|
||||
self.addonscript.version == 2
|
||||
}
|
||||
}
|
||||
|
||||
impl Flags {
|
||||
|
||||
pub fn has_client_flag(&self, flag: &Flag) -> bool {
|
||||
if let Some(flags) = &self.client {
|
||||
if flags.contains(flag) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if let Some(flags) = &self.both {
|
||||
if flags.contains(flag) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
pub fn has_server_flag(&self, flag: &Flag) -> bool {
|
||||
if let Some(flags) = &self.server {
|
||||
if flags.contains(flag) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if let Some(flags) = &self.both {
|
||||
if flags.contains(flag) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
50
crates/model/src/meta.rs
Normal file
50
crates/model/src/meta.rs
Normal file
|
@ -0,0 +1,50 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
use url::Url;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct Meta {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub addon: Option<AddonMeta>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub version: Option<VersionMeta>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub additional: Option<Value>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct AddonMeta {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub name: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub icon: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub description: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub summary: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub website: Option<Url>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub source: Option<Url>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub issues: Option<Url>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[serde(rename = "type")]
|
||||
pub addon_type: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub contributors: Option<Vec<Contributor>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct VersionMeta {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub changelog: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub timestamp:Option<u32>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct Contributor {
|
||||
pub name: String,
|
||||
pub email: String,
|
||||
}
|
Loading…
Reference in a new issue