1use serde::{Deserialize, Serialize};
2use std::collections::HashMap;
3use std::path::PathBuf;
4use structopt::StructOpt;
5use reqwest::blocking::multipart::Form;
6use std::fmt;
7
8pub trait AddMultipartFiles {
9 fn add_multipart_files(&self, form: Form) -> Form {form}
10}
11
12#[derive(StructOpt, Debug, Serialize, Deserialize)]
13pub struct Namespace {
14 #[structopt(skip)]
15 #[serde(skip_serializing)]
16 #[serde(default)]
17 children: Box<Vec<Namespace>>,
18 #[structopt(skip)]
19 #[serde(skip_serializing)]
20 parent: Box<Option<Namespace>>,
21 #[structopt(skip)]
22 #[serde(skip_serializing)]
23 #[serde(default)] pub emotes: Vec<Emote>,
25 #[structopt(skip)]
26 #[serde(skip_serializing)]
27 id: u32,
28 name: String,
29 #[serde(rename(serialize = "path"))]
30 slug: String,
31}
32
33#[derive(Debug, Serialize, Deserialize)]
34pub struct Response {
35 id: Option<i32>, msg: Option<String>, path: Option<String>, key: Option<String>, }
41
42impl fmt::Display for Response {
43 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
44 if let Some(id) = &self.id { return write!(f, "Created namespace with id {}", id)
46 }
47 else if let Some(path) = &self.path { return write!(f, "{} with path {}", self.msg.as_ref().unwrap(), path)
49 }
50 else if let Some(key) = &self.key { return write!(f, "API key: {}", key)
52 }
53 write!(f, "{}", self.msg.as_ref().unwrap())
54 }
55}
56
57#[derive(StructOpt, Debug, Serialize, Deserialize)]
58pub struct Emote {
59 #[structopt(skip)]
60 pub id: u32,
61 #[structopt(skip)]
62 pub info: HashMap<String, String>,
63 #[serde(skip_deserializing)]
64 pub path: String, pub name: String,
66 #[serde(skip_deserializing)]
67 #[serde(skip_serializing)]
68 #[structopt(parse(from_os_str))]
69 pub emotes_file: PathBuf, #[serde(skip_deserializing)]
71 #[structopt(skip="png")]
72 pub r#type: String,
73}
74
75impl AddMultipartFiles for Emote {
76 fn add_multipart_files(&self, form: Form) -> Form {
77 form.file("emotes_file", &self.emotes_file).unwrap()
78 }
79}
80
81#[derive(StructOpt, Deserialize, Serialize, Debug)]
82pub struct User {
83 #[structopt(long, short)]
84 admin: bool,
85 #[structopt(skip)]
86 #[serde(skip_serializing)]
87 id: u32,
88 name: String,
89 #[structopt(skip)]
90 #[serde(skip_serializing)]
91 namespaces: Vec<Namespace>,
92 #[structopt(skip)]
93 #[serde(skip_deserializing)]
94 api_key: String
95}
96
97#[derive(Debug, Serialize, Deserialize)]
98pub struct Blank;