Skip to main content

jacquard_api/place_stream/media/
create_upload.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: place.stream.media.createUpload
4//
5// This file was automatically generated from Lexicon schemas.
6// Any manual changes will be overwritten on the next regeneration.
7
8#[allow(unused_imports)]
9use alloc::collections::BTreeMap;
10
11#[allow(unused_imports)]
12use core::marker::PhantomData;
13use jacquard_common::{CowStr, BosStr, DefaultStr, FromStaticStr};
14use jacquard_common::deps::smol_str::SmolStr;
15use jacquard_common::types::string::{Datetime, UriValue};
16use jacquard_common::types::value::Data;
17use jacquard_derive::{IntoStatic, open_union};
18use serde::{Serialize, Deserialize};
19
20#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
21#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
22pub struct CreateUpload<S: BosStr = DefaultStr> {
23    ///Optional filename hint to attach as upload metadata.
24    #[serde(skip_serializing_if = "Option::is_none")]
25    pub filename: Option<S>,
26    ///MIME type of the content being uploaded (e.g. video/mp4).
27    pub mime_type: S,
28    ///Total size of the upload in bytes.
29    pub size: i64,
30    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
31    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
32}
33
34
35#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
36#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
37pub struct CreateUploadOutput<S: BosStr = DefaultStr> {
38    ///When the upload token expires.
39    pub expires_at: Datetime,
40    ///Server-side identifier for this upload.
41    pub upload_id: S,
42    ///Short-lived bearer token bound to this upload. Send as 'Authorization: Bearer <token>' on TUS requests.
43    pub upload_token: S,
44    ///Absolute URL to PATCH/HEAD per the TUS protocol.
45    pub upload_url: UriValue<S>,
46    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
47    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
48}
49
50
51#[derive(
52    Serialize,
53    Deserialize,
54    Debug,
55    Clone,
56    PartialEq,
57    Eq,
58    thiserror::Error,
59    miette::Diagnostic
60)]
61
62#[serde(tag = "error", content = "message")]
63pub enum CreateUploadError {
64    /// The requested upload exceeds the server's maximum allowed size.
65    #[serde(rename = "UploadTooLarge")]
66    UploadTooLarge(Option<SmolStr>),
67    /// The server does not accept this MIME type for upload.
68    #[serde(rename = "UnsupportedMimeType")]
69    UnsupportedMimeType(Option<SmolStr>),
70    /// Catch-all for unknown error codes.
71    #[serde(untagged)]
72    Other { error: SmolStr, message: Option<SmolStr> },
73}
74
75impl core::fmt::Display for CreateUploadError {
76    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
77        match self {
78            Self::UploadTooLarge(msg) => {
79                write!(f, "UploadTooLarge")?;
80                if let Some(msg) = msg {
81                    write!(f, ": {}", msg)?;
82                }
83                Ok(())
84            }
85            Self::UnsupportedMimeType(msg) => {
86                write!(f, "UnsupportedMimeType")?;
87                if let Some(msg) = msg {
88                    write!(f, ": {}", msg)?;
89                }
90                Ok(())
91            }
92            Self::Other { error, message } => {
93                write!(f, "{}", error)?;
94                if let Some(msg) = message {
95                    write!(f, ": {}", msg)?;
96                }
97                Ok(())
98            }
99        }
100    }
101}
102
103/** Response marker for the `place.stream.media.createUpload` procedure.
104
105Implements `jacquard_common::xrpc::XrpcResp`; successful bodies decode as `Self::Output<S>`, which is `CreateUploadOutput<S>` for this endpoint.*/
106pub struct CreateUploadResponse;
107impl jacquard_common::xrpc::XrpcResp for CreateUploadResponse {
108    const NSID: &'static str = "place.stream.media.createUpload";
109    const ENCODING: &'static str = "application/json";
110    type Output<S: BosStr> = CreateUploadOutput<S>;
111    type Err = CreateUploadError;
112}
113
114impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for CreateUpload<S> {
115    const NSID: &'static str = "place.stream.media.createUpload";
116    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
117        "application/json",
118    );
119    type Response = CreateUploadResponse;
120}
121
122/** Endpoint marker for the `place.stream.media.createUpload` procedure.
123
124Path: `/xrpc/place.stream.media.createUpload`. The request payload type is `CreateUpload<S>`; send that request with `jacquard::Client` or use this marker through lower-level `XrpcEndpoint` APIs.*/
125pub struct CreateUploadRequest;
126impl jacquard_common::xrpc::XrpcEndpoint for CreateUploadRequest {
127    const PATH: &'static str = "/xrpc/place.stream.media.createUpload";
128    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
129        "application/json",
130    );
131    type Request<S: BosStr> = CreateUpload<S>;
132    type Response = CreateUploadResponse;
133}
134
135pub mod create_upload_state {
136
137    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
138    #[allow(unused)]
139    use ::core::marker::PhantomData;
140    mod sealed {
141        pub trait Sealed {}
142    }
143    /// State trait tracking which required fields have been set
144    pub trait State: sealed::Sealed {
145        type MimeType;
146        type Size;
147    }
148    /// Empty state - all required fields are unset
149    pub struct Empty(());
150    impl sealed::Sealed for Empty {}
151    impl State for Empty {
152        type MimeType = Unset;
153        type Size = Unset;
154    }
155    ///State transition - sets the `mime_type` field to Set
156    pub struct SetMimeType<St: State = Empty>(PhantomData<fn() -> St>);
157    impl<St: State> sealed::Sealed for SetMimeType<St> {}
158    impl<St: State> State for SetMimeType<St> {
159        type MimeType = Set<members::mime_type>;
160        type Size = St::Size;
161    }
162    ///State transition - sets the `size` field to Set
163    pub struct SetSize<St: State = Empty>(PhantomData<fn() -> St>);
164    impl<St: State> sealed::Sealed for SetSize<St> {}
165    impl<St: State> State for SetSize<St> {
166        type MimeType = St::MimeType;
167        type Size = Set<members::size>;
168    }
169    /// Marker types for field names
170    #[allow(non_camel_case_types)]
171    pub mod members {
172        ///Marker type for the `mime_type` field
173        pub struct mime_type(());
174        ///Marker type for the `size` field
175        pub struct size(());
176    }
177}
178
179/// Builder for constructing an instance of this type.
180pub struct CreateUploadBuilder<St: create_upload_state::State, S: BosStr = DefaultStr> {
181    _state: PhantomData<fn() -> St>,
182    _fields: (Option<S>, Option<S>, Option<i64>),
183    _type: PhantomData<fn() -> S>,
184}
185
186impl CreateUpload<DefaultStr> {
187    /// Create a new builder for this type, using the default string type (DefaultStr = SmolStr) if needed
188    pub fn new() -> CreateUploadBuilder<create_upload_state::Empty, DefaultStr> {
189        CreateUploadBuilder::new()
190    }
191}
192
193impl<S: BosStr> CreateUpload<S> {
194    /// Create a new builder for this type
195    pub fn builder() -> CreateUploadBuilder<create_upload_state::Empty, S> {
196        CreateUploadBuilder::builder()
197    }
198}
199
200impl CreateUploadBuilder<create_upload_state::Empty, DefaultStr> {
201    /// Create a new builder with all fields unset, using the default string type, if needed
202    pub fn new() -> Self {
203        CreateUploadBuilder {
204            _state: PhantomData,
205            _fields: (None, None, None),
206            _type: PhantomData,
207        }
208    }
209}
210
211impl<S: BosStr> CreateUploadBuilder<create_upload_state::Empty, S> {
212    /// Create a new builder with all fields unset
213    pub fn builder() -> Self {
214        CreateUploadBuilder {
215            _state: PhantomData,
216            _fields: (None, None, None),
217            _type: PhantomData,
218        }
219    }
220}
221
222impl<St: create_upload_state::State, S: BosStr> CreateUploadBuilder<St, S> {
223    /// Set the `filename` field (optional)
224    pub fn filename(mut self, value: impl Into<Option<S>>) -> Self {
225        self._fields.0 = value.into();
226        self
227    }
228    /// Set the `filename` field to an Option value (optional)
229    pub fn maybe_filename(mut self, value: Option<S>) -> Self {
230        self._fields.0 = value;
231        self
232    }
233}
234
235impl<St, S: BosStr> CreateUploadBuilder<St, S>
236where
237    St: create_upload_state::State,
238    St::MimeType: create_upload_state::IsUnset,
239{
240    /// Set the `mimeType` field (required)
241    pub fn mime_type(
242        mut self,
243        value: impl Into<S>,
244    ) -> CreateUploadBuilder<create_upload_state::SetMimeType<St>, S> {
245        self._fields.1 = Option::Some(value.into());
246        CreateUploadBuilder {
247            _state: PhantomData,
248            _fields: self._fields,
249            _type: PhantomData,
250        }
251    }
252}
253
254impl<St, S: BosStr> CreateUploadBuilder<St, S>
255where
256    St: create_upload_state::State,
257    St::Size: create_upload_state::IsUnset,
258{
259    /// Set the `size` field (required)
260    pub fn size(
261        mut self,
262        value: impl Into<i64>,
263    ) -> CreateUploadBuilder<create_upload_state::SetSize<St>, S> {
264        self._fields.2 = Option::Some(value.into());
265        CreateUploadBuilder {
266            _state: PhantomData,
267            _fields: self._fields,
268            _type: PhantomData,
269        }
270    }
271}
272
273impl<St, S: BosStr> CreateUploadBuilder<St, S>
274where
275    St: create_upload_state::State,
276    St::MimeType: create_upload_state::IsSet,
277    St::Size: create_upload_state::IsSet,
278{
279    /// Build the final struct.
280    pub fn build(self) -> CreateUpload<S> {
281        CreateUpload {
282            filename: self._fields.0,
283            mime_type: self._fields.1.unwrap(),
284            size: self._fields.2.unwrap(),
285            extra_data: Default::default(),
286        }
287    }
288    /// Build the final struct with custom extra_data.
289    pub fn build_with_data(
290        self,
291        extra_data: BTreeMap<SmolStr, Data<S>>,
292    ) -> CreateUpload<S> {
293        CreateUpload {
294            filename: self._fields.0,
295            mime_type: self._fields.1.unwrap(),
296            size: self._fields.2.unwrap(),
297            extra_data: Some(extra_data),
298        }
299    }
300}