Skip to content

Commit 9c743e2

Browse files
cleanup upload_video arguments
1 parent 273f2db commit 9c743e2

File tree

3 files changed

+34
-95
lines changed

3 files changed

+34
-95
lines changed

apps/desktop/src-tauri/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,9 +1111,9 @@ async fn upload_exported_video(
11111111
&app,
11121112
upload_id.clone(),
11131113
output_path,
1114-
Some(s3_config),
1115-
Some(meta.project_path.join("screenshots/display.jpg")),
1116-
Some(metadata),
1114+
meta.project_path.join("screenshots/display.jpg"),
1115+
s3_config,
1116+
metadata,
11171117
Some(channel.clone()),
11181118
)
11191119
.await

apps/desktop/src-tauri/src/recording.rs

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -803,26 +803,29 @@ async fn handle_recording_finish(
803803
}
804804
}
805805
} else {
806-
let meta = build_video_meta(&output_path).ok();
807-
// The upload_video function handles screenshot upload, so we can pass it along
808-
match upload_video(
809-
&app,
810-
video_upload_info.id.clone(),
811-
output_path,
812-
Some(video_upload_info.config.clone()),
813-
Some(display_screenshot.clone()),
814-
meta,
815-
None,
816-
)
817-
.await
806+
if let Ok(meta) = build_video_meta(&output_path)
807+
.map_err(|err| error!("Error getting video metdata: {}", err))
818808
{
819-
Ok(_) => {
820-
info!(
821-
"Final video upload with screenshot completed successfully"
822-
)
823-
}
824-
Err(e) => {
825-
error!("Error in final upload with screenshot: {}", e)
809+
// The upload_video function handles screenshot upload, so we can pass it along
810+
match upload_video(
811+
&app,
812+
video_upload_info.id.clone(),
813+
output_path,
814+
display_screenshot.clone(),
815+
video_upload_info.config.clone(),
816+
meta,
817+
None,
818+
)
819+
.await
820+
{
821+
Ok(_) => {
822+
info!(
823+
"Final video upload with screenshot completed successfully"
824+
)
825+
}
826+
Err(e) => {
827+
error!("Error in final upload with screenshot: {}", e)
828+
}
826829
}
827830
}
828831
}

apps/desktop/src-tauri/src/upload.rs

Lines changed: 9 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -34,53 +34,10 @@ pub struct CreateErrorResponse {
3434
error: String,
3535
}
3636

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-
7637
impl S3UploadMeta {
7738
pub fn id(&self) -> &str {
7839
&self.id
7940
}
80-
81-
// pub fn new(id: String) -> Self {
82-
// Self { id }
83-
// }
8441
}
8542

8643
#[derive(Serialize, Debug, Clone)]
@@ -106,12 +63,6 @@ pub struct UploadedImage {
10663
pub id: String,
10764
}
10865

109-
// pub struct UploadedAudio {
110-
// pub link: String,
111-
// pub id: String,
112-
// pub config: S3UploadMeta,
113-
// }
114-
11566
pub struct UploadProgressUpdater {
11667
video_state: Option<VideoProgressState>,
11768
app: AppHandle,
@@ -212,26 +163,22 @@ pub async fn upload_video(
212163
app: &AppHandle,
213164
video_id: String,
214165
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,
218169
channel: Option<Channel<UploadProgress>>,
219170
) -> Result<UploadedVideo, String> {
220-
println!("Uploading video {video_id}...");
171+
info!("Uploading video {video_id}...");
221172

222173
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-
};
227174

228175
let presigned_put = presigned_s3_put(
229176
app,
230177
PresignedS3PutRequest {
231178
video_id: video_id.clone(),
232179
subpath: "result.mp4".to_string(),
233180
method: PresignedS3PutRequestMethod::Put,
234-
meta: Some(build_video_meta(&file_path)?),
181+
meta: Some(meta),
235182
},
236183
)
237184
.await?;
@@ -270,12 +217,7 @@ pub async fn upload_video(
270217
}
271218
});
272219

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);
279221

280222
let video_upload = client
281223
.put(presigned_put)
@@ -284,21 +226,15 @@ pub async fn upload_video(
284226

285227
let (video_upload, screenshot_result): (
286228
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);
295231

296232
let response = video_upload.map_err(|e| format!("Failed to send upload file request: {e}"))?;
297233

298234
if response.status().is_success() {
299235
println!("Video uploaded successfully");
300236

301-
if let Some(Ok(screenshot_response)) = screenshot_result {
237+
if let Ok(screenshot_response) = screenshot_result {
302238
if screenshot_response.status().is_success() {
303239
println!("Screenshot uploaded successfully");
304240
} else {

0 commit comments

Comments
 (0)