@@ -12,7 +12,7 @@ use garde::Validate;
1212use mime:: Mime ;
1313use serde:: { Deserialize , Serialize } ;
1414use serde_with:: serde_as;
15- use std:: collections:: HashMap ;
15+ use std:: { collections:: HashMap , marker :: PhantomData } ;
1616use thiserror:: Error ;
1717use utoipa:: ToSchema ;
1818
@@ -25,23 +25,25 @@ pub struct CreatePresignedRequest {
2525 #[ schema( min_length = 1 , max_length = 255 ) ]
2626 pub name : String ,
2727
28- /// Folder to store the file in
28+ /// ID of the folder to store the file in
2929 #[ garde( skip) ]
3030 #[ schema( value_type = Uuid ) ]
3131 pub folder_id : FolderId ,
3232
33- /// Size of the file being uploaded
33+ /// Size of the file being uploaded in bytes. Must match the size of the
34+ /// file being uploaded
3435 #[ garde( range( min = 1 ) ) ]
3536 #[ schema( minimum = 1 ) ]
3637 pub size : i32 ,
3738
3839 /// Mime type of the file
3940 #[ garde( skip) ]
40- #[ serde_as( as = "serde_with::DisplayFromStr" ) ]
41- #[ schema( value_type = String ) ]
42- pub mime : Mime ,
41+ #[ serde_as( as = "Option< serde_with::DisplayFromStr> " ) ]
42+ #[ schema( value_type = Option < String > ) ]
43+ pub mime : Option < Mime > ,
4344
44- /// Optional parent file ID
45+ /// Optional ID of the parent file if this file is associated as a child
46+ /// of another file. Mainly used to associating attachments to email files
4547 #[ garde( skip) ]
4648 #[ schema( value_type = Option <Uuid >) ]
4749 pub parent_id : Option < FileId > ,
@@ -57,25 +59,37 @@ pub struct CreatePresignedRequest {
5759 pub disable_mime_sniffing : Option < bool > ,
5860}
5961
62+ /// Response describing how to upload the presigned file and the ID
63+ /// for polling the progress
6064#[ derive( Serialize , ToSchema ) ]
6165pub struct PresignedUploadResponse {
66+ /// ID of the file upload task to poll
6267 #[ schema( value_type = Uuid ) ]
6368 pub task_id : PresignedUploadTaskId ,
69+ /// HTTP method to use when uploading the file
6470 pub method : String ,
71+ /// URL to upload the file to
6572 pub uri : String ,
73+ /// Headers to include on the file upload request
6674 pub headers : HashMap < String , String > ,
6775}
6876
6977#[ derive( Serialize , ToSchema ) ]
7078#[ serde( tag = "status" ) ]
7179#[ allow( clippy:: large_enum_variant) ]
7280pub enum PresignedStatusResponse {
81+ /// Presigned upload is currently pending
7382 Pending ,
83+ /// Presigned upload is completed
7484 Complete {
85+ /// The uploaded file
7586 file : FileWithExtra ,
87+ /// The generated file
7688 generated : Vec < GeneratedFile > ,
7789 } ,
90+ /// Presigned upload failed
7891 Failed {
92+ /// The error that occurred
7993 error : String ,
8094 } ,
8195}
@@ -131,6 +145,11 @@ pub struct PresignedDownloadResponse {
131145 pub expires_at : DateTime < Utc > ,
132146}
133147
148+ /// Type hint type for Utoipa to indicate a binary response type
149+ #[ derive( ToSchema ) ]
150+ #[ schema( value_type = String , format = Binary ) ]
151+ pub struct BinaryResponse ( PhantomData < Vec < u8 > > ) ;
152+
134153#[ derive( Debug , Error ) ]
135154pub enum HttpFileError {
136155 #[ error( "unknown file" ) ]
@@ -141,6 +160,7 @@ pub enum HttpFileError {
141160
142161 #[ error( "file size is larger than the maximum allowed size (requested: {0}, maximum: {1})" ) ]
143162 FileTooLarge ( i32 , i32 ) ,
163+
144164 #[ error( "no matching generated file" ) ]
145165 NoMatchingGenerated ,
146166
0 commit comments