discloud_rs/
app.rs

1use serde::Deserialize;
2
3pub mod backup;
4pub mod logs;
5pub mod manage;
6pub mod status;
7
8use crate::{Discloud, Error, TeamMember, TeamPerms};
9
10use self::{
11    backup::AppBackup,
12    logs::AppLogs,
13    manage::{AppRamError, AppStartError, AppStartStatus, AppStopError},
14    status::AppStatus,
15};
16
17#[derive(Deserialize, Debug, Clone)]
18pub struct AppResponseAll {
19    pub apps: Vec<App>,
20    pub message: String,
21    pub status: String,
22}
23
24#[derive(Deserialize, Debug, Clone)]
25pub struct AppResponseUnique {
26    pub apps: App,
27    pub message: String,
28    pub status: String,
29}
30
31#[derive(Deserialize, Debug, Clone)]
32#[serde(rename_all = "camelCase")]
33pub struct App {
34    pub auto_deploy_git: String,
35    pub auto_restart: bool,
36    #[serde(rename = "avatarURL")]
37    pub avatar_url: String,
38    pub exit_code: Option<i32>,
39    pub id: String,
40    pub lang: String,
41    pub main_file: String,
42    pub mods: Vec<String>,
43    pub name: String,
44    pub online: bool,
45    pub ram: i32,
46    pub ram_killed: bool,
47    pub r#type: i32,
48}
49
50impl App {
51    pub async fn get_status(&self, client: &Discloud) -> Result<AppStatus, Error> {
52        client.get_app_status(&self.id).await
53    }
54
55    pub async fn get_logs(&self, client: &Discloud) -> Result<AppLogs, Error> {
56        client.get_app_logs(&self.id).await
57    }
58
59    pub async fn get_backup(&self, client: &Discloud) -> Result<AppBackup, Error> {
60        client.get_app_backup(&self.id).await
61    }
62
63    pub async fn start(&self, client: &Discloud) -> Result<AppStartStatus, AppStartError> {
64        client.start_app(&self.id).await
65    }
66
67    pub async fn stop(&self, client: &Discloud) -> Result<(), AppStopError> {
68        client.stop_app(&self.id).await
69    }
70
71    pub async fn restart(&self, client: &Discloud) -> Result<(), Error> {
72        client.restart_app(&self.id).await
73    }
74
75    pub async fn set_ram(&self, client: &Discloud, quantity: u32) -> Result<(), AppRamError> {
76        client.set_app_ram(&self.id, quantity).await
77    }
78
79    pub async fn commit(&self) {
80        todo!()
81    }
82
83    pub async fn delete(&self, client: &Discloud) -> Result<(), Error> {
84        client.delete_app(&self.id).await
85    }
86
87    pub async fn get_team(&self, client: &Discloud) -> Result<Vec<TeamMember>, Error> {
88        client.get_app_team(&self.id).await
89    }
90
91    pub async fn add_mod(
92        &self,
93        client: &Discloud,
94        mod_id: &str,
95        perms: Vec<TeamPerms>,
96    ) -> Result<TeamMember, Error> {
97        client.add_app_mod(&self.id, mod_id, perms).await
98    }
99
100    pub async fn edit_mod(
101        &self,
102        client: &Discloud,
103        mod_id: &str,
104        perms: Vec<TeamPerms>,
105    ) -> Result<TeamMember, Error> {
106        client.edit_app_mod(&self.id, mod_id, perms).await
107    }
108
109    pub async fn remove_mod(&self, client: &Discloud, mod_id: &str) -> Result<(), Error> {
110        client.remove_app_mod(&self.id, mod_id).await
111    }
112}