1use serde::{Deserialize, Serialize};
2
3use crate::locks::Lock;
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
6#[serde(rename_all = "lowercase")]
7pub enum Operation {
8 Upload,
9 Download,
10}
11
12#[derive(Debug, Clone, Deserialize, Serialize)]
13pub struct ObjectId {
14 pub oid: String,
15 pub size: u64,
16}
17
18#[derive(Debug, Deserialize)]
19pub struct BatchRequest {
20 pub operation: Operation,
21 #[serde(default)]
22 pub transfers: Vec<String>,
23 pub objects: Vec<ObjectId>,
24}
25
26#[derive(Debug, Deserialize)]
27pub struct RetainRequest {
28 pub oids: Vec<String>,
29 #[serde(default)]
30 pub dry_run: bool,
31}
32
33#[derive(Debug, Serialize)]
34pub struct BatchResponse {
35 pub transfer: &'static str,
36 pub objects: Vec<ObjectSpec>,
37}
38
39#[derive(Debug, Serialize)]
40pub struct ObjectSpec {
41 #[serde(flatten)]
42 pub id: ObjectId,
43 #[serde(skip_serializing_if = "Option::is_none")]
44 pub actions: Option<Actions>,
45 #[serde(skip_serializing_if = "Option::is_none")]
46 pub error: Option<ObjectError>,
47}
48
49#[derive(Debug, Default, Serialize)]
50pub struct Actions {
51 #[serde(skip_serializing_if = "Option::is_none")]
52 pub upload: Option<Action>,
53 #[serde(skip_serializing_if = "Option::is_none")]
54 pub download: Option<Action>,
55 #[serde(skip_serializing_if = "Option::is_none")]
56 pub verify: Option<Action>,
57}
58
59#[derive(Debug, Serialize)]
60pub struct Action {
61 pub href: String,
62 pub expires_in: u32,
63}
64
65#[derive(Debug, Serialize)]
66pub struct ObjectError {
67 pub code: u16,
68 pub message: String,
69}
70
71impl ObjectSpec {
72 pub fn missing(id: ObjectId) -> Self {
73 Self {
74 id,
75 actions: None,
76 error: Some(ObjectError {
77 code: 404,
78 message: "object not found".into(),
79 }),
80 }
81 }
82}
83
84#[derive(Debug, Deserialize)]
85pub struct CreateLockRequest {
86 pub path: String,
87}
88
89#[derive(Debug, Deserialize)]
90pub struct ListLocksQuery {
91 pub path: Option<String>,
92 pub id: Option<String>,
93}
94
95#[derive(Debug, Default, Deserialize)]
96pub struct VerifyLocksRequest {}
97
98#[derive(Debug, Deserialize)]
99pub struct UnlockRequest {
100 #[serde(default)]
101 pub force: bool,
102}
103
104#[derive(Debug, Serialize)]
105pub struct LockResponse {
106 pub lock: Lock,
107}
108
109#[derive(Debug, Serialize)]
110pub struct ListLocksResponse {
111 pub locks: Vec<Lock>,
112 pub next_cursor: &'static str,
113}
114
115#[derive(Debug, Serialize)]
116pub struct VerifyLocksResponse {
117 pub ours: Vec<Lock>,
118 pub theirs: Vec<Lock>,
119 pub next_cursor: &'static str,
120}