1use serde::{Deserialize, Serialize};
4use std::collections::HashMap;
5
6#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
8#[serde(rename_all = "lowercase")]
9pub enum ContainerStatus {
10 Running,
11 Stopped,
12 Creating,
13 Error,
14 #[serde(other)]
15 Unknown,
16}
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20pub struct Container {
21 pub id: String,
23 pub name: String,
25 pub image: String,
27 pub status: String,
29 pub created_at: String,
31 pub started_at: Option<String>,
33 #[serde(default)]
35 pub labels: HashMap<String, String>,
36 #[serde(default)]
38 pub environment: HashMap<String, String>,
39}
40
41#[derive(Debug, Clone, Serialize, Default)]
43pub struct CreateContainerRequest {
44 pub image: String,
46 #[serde(skip_serializing_if = "Option::is_none")]
48 pub name: Option<String>,
49 #[serde(skip_serializing_if = "HashMap::is_empty", default)]
51 pub environment: HashMap<String, String>,
52 #[serde(skip_serializing_if = "HashMap::is_empty", default)]
54 pub labels: HashMap<String, String>,
55}
56
57impl CreateContainerRequest {
58 pub fn new(image: impl Into<String>) -> Self {
60 Self {
61 image: image.into(),
62 ..Default::default()
63 }
64 }
65
66 pub fn name(mut self, name: impl Into<String>) -> Self {
68 self.name = Some(name.into());
69 self
70 }
71
72 pub fn env(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
74 self.environment.insert(key.into(), value.into());
75 self
76 }
77
78 pub fn label(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
80 self.labels.insert(key.into(), value.into());
81 self
82 }
83}
84
85#[derive(Debug, Clone, Serialize, Deserialize)]
87pub struct FileInfo {
88 pub name: String,
90 pub path: String,
92 pub size: u64,
94 pub mode: String,
96 pub mod_time: String,
98 pub is_dir: bool,
100}
101
102#[derive(Debug, Clone, Serialize)]
104pub struct ResizeMessage {
105 #[serde(rename = "type")]
106 pub msg_type: String,
107 pub cols: u16,
108 pub rows: u16,
109}
110
111impl ResizeMessage {
112 pub fn new(cols: u16, rows: u16) -> Self {
113 Self {
114 msg_type: "resize".into(),
115 cols,
116 rows,
117 }
118 }
119}