@@ -5,9 +5,12 @@ use serde::{Deserialize, Serialize};
55use serde_json:: json;
66use tauri:: AppHandle ;
77
8- use crate :: web_api:: ManagerExt ;
8+ use crate :: web_api:: { AuthedApiError , ManagerExt } ;
99
10- pub async fn upload_multipart_initiate ( app : & AppHandle , video_id : & str ) -> Result < String , String > {
10+ pub async fn upload_multipart_initiate (
11+ app : & AppHandle ,
12+ video_id : & str ,
13+ ) -> Result < String , AuthedApiError > {
1114 #[ derive( Deserialize ) ]
1215 #[ serde( rename_all = "camelCase" ) ]
1316 pub struct Response {
@@ -32,14 +35,12 @@ pub async fn upload_multipart_initiate(app: &AppHandle, video_id: &str) -> Resul
3235 . text ( )
3336 . await
3437 . unwrap_or_else ( |_| "<no response body>" . to_string ( ) ) ;
35- return Err ( format ! (
36- "api/upload_multipart_initiate/{status}: {error_body}"
37- ) ) ;
38+ return Err ( format ! ( "api/upload_multipart_initiate/{status}: {error_body}" ) . into ( ) ) ;
3839 }
3940
4041 resp. json :: < Response > ( )
4142 . await
42- . map_err ( |err| format ! ( "api/upload_multipart_initiate/response: {err}" ) )
43+ . map_err ( |err| format ! ( "api/upload_multipart_initiate/response: {err}" ) . into ( ) )
4344 . map ( |data| data. upload_id )
4445}
4546
@@ -49,7 +50,7 @@ pub async fn upload_multipart_presign_part(
4950 upload_id : & str ,
5051 part_number : u32 ,
5152 md5_sum : & str ,
52- ) -> Result < String , String > {
53+ ) -> Result < String , AuthedApiError > {
5354 #[ derive( Deserialize ) ]
5455 #[ serde( rename_all = "camelCase" ) ]
5556 pub struct Response {
@@ -76,14 +77,12 @@ pub async fn upload_multipart_presign_part(
7677 . text ( )
7778 . await
7879 . unwrap_or_else ( |_| "<no response body>" . to_string ( ) ) ;
79- return Err ( format ! (
80- "api/upload_multipart_presign_part/{status}: {error_body}"
81- ) ) ;
80+ return Err ( format ! ( "api/upload_multipart_presign_part/{status}: {error_body}" ) . into ( ) ) ;
8281 }
8382
8483 resp. json :: < Response > ( )
8584 . await
86- . map_err ( |err| format ! ( "api/upload_multipart_presign_part/response: {err}" ) )
85+ . map_err ( |err| format ! ( "api/upload_multipart_presign_part/response: {err}" ) . into ( ) )
8786 . map ( |data| data. presigned_url )
8887}
8988
@@ -114,7 +113,7 @@ pub async fn upload_multipart_complete(
114113 upload_id : & str ,
115114 parts : & [ UploadedPart ] ,
116115 meta : Option < S3VideoMeta > ,
117- ) -> Result < Option < String > , String > {
116+ ) -> Result < Option < String > , AuthedApiError > {
118117 #[ derive( Serialize ) ]
119118 #[ serde( rename_all = "camelCase" ) ]
120119 pub struct MultipartCompleteRequest < ' a > {
@@ -150,14 +149,12 @@ pub async fn upload_multipart_complete(
150149 . text ( )
151150 . await
152151 . unwrap_or_else ( |_| "<no response body>" . to_string ( ) ) ;
153- return Err ( format ! (
154- "api/upload_multipart_complete/{status}: {error_body}"
155- ) ) ;
152+ return Err ( format ! ( "api/upload_multipart_complete/{status}: {error_body}" ) . into ( ) ) ;
156153 }
157154
158155 resp. json :: < Response > ( )
159156 . await
160- . map_err ( |err| format ! ( "api/upload_multipart_complete/response: {err}" ) )
157+ . map_err ( |err| format ! ( "api/upload_multipart_complete/response: {err}" ) . into ( ) )
161158 . map ( |data| data. location )
162159}
163160
@@ -179,7 +176,10 @@ pub struct PresignedS3PutRequest {
179176 pub meta : Option < S3VideoMeta > ,
180177}
181178
182- pub async fn upload_signed ( app : & AppHandle , body : PresignedS3PutRequest ) -> Result < String , String > {
179+ pub async fn upload_signed (
180+ app : & AppHandle ,
181+ body : PresignedS3PutRequest ,
182+ ) -> Result < String , AuthedApiError > {
183183 #[ derive( Deserialize ) ]
184184 struct Data {
185185 url : String ,
@@ -204,12 +204,12 @@ pub async fn upload_signed(app: &AppHandle, body: PresignedS3PutRequest) -> Resu
204204 . text ( )
205205 . await
206206 . unwrap_or_else ( |_| "<no response body>" . to_string ( ) ) ;
207- return Err ( format ! ( "api/upload_signed/{status}: {error_body}" ) ) ;
207+ return Err ( format ! ( "api/upload_signed/{status}: {error_body}" ) . into ( ) ) ;
208208 }
209209
210210 resp. json :: < Response > ( )
211211 . await
212- . map_err ( |err| format ! ( "api/upload_signed/response: {err}" ) )
212+ . map_err ( |err| format ! ( "api/upload_signed/response: {err}" ) . into ( ) )
213213 . map ( |data| data. presigned_put_data . url )
214214}
215215
@@ -218,7 +218,7 @@ pub async fn desktop_video_progress(
218218 video_id : & str ,
219219 uploaded : u64 ,
220220 total : u64 ,
221- ) -> Result < ( ) , String > {
221+ ) -> Result < ( ) , AuthedApiError > {
222222 let resp = app
223223 . authed_api_request ( "/api/desktop/video/progress" , |client, url| {
224224 client. post ( url) . json ( & json ! ( {
@@ -237,7 +237,7 @@ pub async fn desktop_video_progress(
237237 . text ( )
238238 . await
239239 . unwrap_or_else ( |_| "<no response body>" . to_string ( ) ) ;
240- return Err ( format ! ( "api/desktop_video_progress/{status}: {error_body}" ) ) ;
240+ return Err ( format ! ( "api/desktop_video_progress/{status}: {error_body}" ) . into ( ) ) ;
241241 }
242242
243243 Ok ( ( ) )
0 commit comments