@@ -34,53 +34,10 @@ pub struct CreateErrorResponse {
34
34
error : String ,
35
35
}
36
36
37
- // fn deserialize_empty_object_as_string<'de, D>(deserializer: D) -> Result<String, D::Error>
38
- // where
39
- // D: Deserializer<'de>,
40
- // {
41
- // struct StringOrObject;
42
-
43
- // impl<'de> de::Visitor<'de> for StringOrObject {
44
- // type Value = String;
45
-
46
- // fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
47
- // formatter.write_str("string or empty object")
48
- // }
49
-
50
- // fn visit_str<E>(self, value: &str) -> Result<String, E>
51
- // where
52
- // E: de::Error,
53
- // {
54
- // Ok(value.to_string())
55
- // }
56
-
57
- // fn visit_string<E>(self, value: String) -> Result<String, E>
58
- // where
59
- // E: de::Error,
60
- // {
61
- // Ok(value)
62
- // }
63
-
64
- // fn visit_map<M>(self, _map: M) -> Result<String, M::Error>
65
- // where
66
- // M: de::MapAccess<'de>,
67
- // {
68
- // // Return empty string for empty objects
69
- // Ok(String::new())
70
- // }
71
- // }
72
-
73
- // deserializer.deserialize_any(StringOrObject)
74
- // }
75
-
76
37
impl S3UploadMeta {
77
38
pub fn id ( & self ) -> & str {
78
39
& self . id
79
40
}
80
-
81
- // pub fn new(id: String) -> Self {
82
- // Self { id }
83
- // }
84
41
}
85
42
86
43
#[ derive( Serialize , Debug , Clone ) ]
@@ -106,12 +63,6 @@ pub struct UploadedImage {
106
63
pub id : String ,
107
64
}
108
65
109
- // pub struct UploadedAudio {
110
- // pub link: String,
111
- // pub id: String,
112
- // pub config: S3UploadMeta,
113
- // }
114
-
115
66
pub struct UploadProgressUpdater {
116
67
video_state : Option < VideoProgressState > ,
117
68
app : AppHandle ,
@@ -212,26 +163,22 @@ pub async fn upload_video(
212
163
app : & AppHandle ,
213
164
video_id : String ,
214
165
file_path : PathBuf ,
215
- existing_config : Option < S3UploadMeta > ,
216
- screenshot_path : Option < PathBuf > ,
217
- meta : Option < S3VideoMeta > ,
166
+ screenshot_path : PathBuf ,
167
+ s3_config : S3UploadMeta ,
168
+ meta : S3VideoMeta ,
218
169
channel : Option < Channel < UploadProgress > > ,
219
170
) -> Result < UploadedVideo , String > {
220
- println ! ( "Uploading video {video_id}..." ) ;
171
+ info ! ( "Uploading video {video_id}..." ) ;
221
172
222
173
let client = reqwest:: Client :: new ( ) ;
223
- let s3_config = match existing_config {
224
- Some ( config) => config,
225
- None => create_or_get_video ( app, false , Some ( video_id. clone ( ) ) , None , meta) . await ?,
226
- } ;
227
174
228
175
let presigned_put = presigned_s3_put (
229
176
app,
230
177
PresignedS3PutRequest {
231
178
video_id : video_id. clone ( ) ,
232
179
subpath : "result.mp4" . to_string ( ) ,
233
180
method : PresignedS3PutRequestMethod :: Put ,
234
- meta : Some ( build_video_meta ( & file_path ) ? ) ,
181
+ meta : Some ( meta ) ,
235
182
} ,
236
183
)
237
184
. await ?;
@@ -270,12 +217,7 @@ pub async fn upload_video(
270
217
}
271
218
} ) ;
272
219
273
- let screenshot_upload = match screenshot_path {
274
- Some ( screenshot_path) if screenshot_path. exists ( ) => {
275
- Some ( prepare_screenshot_upload ( app, & s3_config, screenshot_path) )
276
- }
277
- _ => None ,
278
- } ;
220
+ let screenshot_upload = prepare_screenshot_upload ( app, & s3_config, screenshot_path) ;
279
221
280
222
let video_upload = client
281
223
. put ( presigned_put)
@@ -284,21 +226,15 @@ pub async fn upload_video(
284
226
285
227
let ( video_upload, screenshot_result) : (
286
228
Result < reqwest:: Response , reqwest:: Error > ,
287
- Option < Result < reqwest:: Response , String > > ,
288
- ) = tokio:: join!( video_upload. send( ) , async {
289
- if let Some ( screenshot_req) = screenshot_upload {
290
- Some ( screenshot_req. await )
291
- } else {
292
- None
293
- }
294
- } ) ;
229
+ Result < reqwest:: Response , String > ,
230
+ ) = tokio:: join!( video_upload. send( ) , screenshot_upload) ;
295
231
296
232
let response = video_upload. map_err ( |e| format ! ( "Failed to send upload file request: {e}" ) ) ?;
297
233
298
234
if response. status ( ) . is_success ( ) {
299
235
println ! ( "Video uploaded successfully" ) ;
300
236
301
- if let Some ( Ok ( screenshot_response) ) = screenshot_result {
237
+ if let Ok ( screenshot_response) = screenshot_result {
302
238
if screenshot_response. status ( ) . is_success ( ) {
303
239
println ! ( "Screenshot uploaded successfully" ) ;
304
240
} else {
0 commit comments