Skip to content

Commit ea2bd20

Browse files
fix uploading of thumbnails
1 parent 9d14a0d commit ea2bd20

File tree

2 files changed

+38
-31
lines changed

2 files changed

+38
-31
lines changed

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

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ use crate::{
3030
general_settings::{GeneralSettingsStore, PostDeletionBehaviour, PostStudioRecordingBehaviour},
3131
open_external_link,
3232
presets::PresetsStore,
33-
upload::{InstantMultipartUpload, build_video_meta, create_or_get_video, upload_video},
33+
upload::{
34+
InstantMultipartUpload, PresignedS3PutRequest, PresignedS3PutRequestMethod,
35+
build_video_meta, bytes_into_stream, compress_image, create_or_get_video,
36+
do_presigned_upload, upload_video,
37+
},
3438
web_api::ManagerExt,
3539
windows::{CapWindowId, ShowCapWindow},
3640
};
@@ -754,7 +758,6 @@ async fn handle_recording_finish(
754758
let video_upload_info = video_upload_info.clone();
755759

756760
async move {
757-
// if let Some(progressive_upload) = progressive_upload {
758761
let video_upload_succeeded = match progressive_upload
759762
.handle
760763
.await
@@ -776,27 +779,30 @@ async fn handle_recording_finish(
776779
let _ = screenshot_task.await;
777780

778781
if video_upload_succeeded {
779-
// let resp = prepare_screenshot_upload(
780-
// &app,
781-
// &video_upload_info.config.clone(),
782-
// display_screenshot,
783-
// )
784-
// .await;
785-
786-
// match resp {
787-
// Ok(r)
788-
// if r.status().as_u16() >= 200 && r.status().as_u16() < 300 =>
789-
// {
790-
// info!("Screenshot uploaded successfully");
791-
// }
792-
// Ok(r) => {
793-
// error!("Failed to upload screenshot: {}", r.status());
794-
// }
795-
// Err(e) => {
796-
// error!("Failed to upload screenshot: {e}");
797-
// }
798-
// }
799-
todo!();
782+
if let Ok(result) =
783+
compress_image(display_screenshot).await
784+
.map_err(|err|
785+
error!("Error compressing thumbnail for instant mode progressive upload: {err}")
786+
) {
787+
let (stream, total_size) = bytes_into_stream(result);
788+
do_presigned_upload(
789+
&app,
790+
stream,
791+
total_size,
792+
crate::upload::PresignedS3PutRequest {
793+
video_id: video_upload_info.id.clone(),
794+
subpath: "screenshot/screen-capture.jpg".to_string(),
795+
method: PresignedS3PutRequestMethod::Put,
796+
meta: None,
797+
},
798+
|p| {} // TODO: Progress reporting
799+
)
800+
.await
801+
.map_err(|err| {
802+
error!("Error updating thumbnail for instant mode progressive upload: {err}")
803+
})
804+
.ok();
805+
}
800806
} else {
801807
if let Ok(meta) = build_video_meta(&output_path)
802808
.map_err(|err| error!("Error getting video metdata: {}", err))
@@ -824,7 +830,6 @@ async fn handle_recording_finish(
824830
}
825831
}
826832
}
827-
// }
828833
}
829834
});
830835

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ async fn file_reader_stream(path: impl AsRef<Path>) -> Result<(ReaderStream<File
278278
Ok((ReaderStream::new(file), metadata.len()))
279279
}
280280

281-
async fn do_presigned_upload(
281+
pub async fn do_presigned_upload(
282282
app: &AppHandle,
283283
stream: impl Stream<Item = Result<Bytes, io::Error>> + Send + 'static,
284284
total_size: u64,
@@ -422,11 +422,11 @@ pub async fn create_or_get_video(
422422
#[derive(Serialize)]
423423
#[serde(rename_all = "camelCase")]
424424
pub struct PresignedS3PutRequest {
425-
video_id: String,
426-
subpath: String,
427-
method: PresignedS3PutRequestMethod,
425+
pub video_id: String,
426+
pub subpath: String,
427+
pub method: PresignedS3PutRequestMethod,
428428
#[serde(flatten)]
429-
meta: Option<S3VideoMeta>,
429+
pub meta: Option<S3VideoMeta>,
430430
}
431431

432432
#[derive(Serialize)]
@@ -493,7 +493,7 @@ pub fn build_video_meta(path: &PathBuf) -> Result<S3VideoMeta, String> {
493493
})
494494
}
495495

496-
async fn compress_image(path: PathBuf) -> Result<Vec<u8>, String> {
496+
pub async fn compress_image(path: PathBuf) -> Result<Vec<u8>, String> {
497497
task::spawn_blocking(move || {
498498
let img = ImageReader::open(&path)
499499
.map_err(|e| format!("Failed to open image: {e}"))?
@@ -523,7 +523,9 @@ async fn compress_image(path: PathBuf) -> Result<Vec<u8>, String> {
523523
.map_err(|e| format!("Failed to compress image: {e}"))?
524524
}
525525

526-
fn bytes_into_stream(bytes: Vec<u8>) -> (impl Stream<Item = Result<Bytes, std::io::Error>>, u64) {
526+
pub fn bytes_into_stream(
527+
bytes: Vec<u8>,
528+
) -> (impl Stream<Item = Result<Bytes, std::io::Error>>, u64) {
527529
let total_size = bytes.len();
528530
let stream = stream::once(async move { Ok::<_, std::io::Error>(bytes::Bytes::from(bytes)) });
529531
(stream, total_size as u64)

0 commit comments

Comments
 (0)