WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit a2a4471

Browse files
committed
fix multi part upload and previous recordings reupload status
1 parent 2290d23 commit a2a4471

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

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

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ pub async fn upload_video(
9494
let upload_id = api::upload_multipart_initiate(&app, &video_id).await?;
9595

9696
let video_fut = async {
97-
let parts = progress(
97+
let stream = progress(
9898
app.clone(),
9999
video_id.clone(),
100100
multipart_uploader(
@@ -103,9 +103,23 @@ pub async fn upload_video(
103103
upload_id.clone(),
104104
from_pending_file_to_chunks(file_path.clone(), None),
105105
),
106-
)
107-
.try_collect::<Vec<_>>()
108-
.await?;
106+
);
107+
108+
let stream = if let Some(channel) = channel {
109+
tauri_channel_progress(channel, stream).boxed()
110+
} else {
111+
stream.boxed()
112+
};
113+
114+
let mut parts = stream.try_collect::<Vec<_>>().await?;
115+
116+
// Deduplicate parts - keep the last occurrence of each part number
117+
let mut deduplicated_parts = HashMap::new();
118+
for part in parts {
119+
deduplicated_parts.insert(part.part_number, part);
120+
}
121+
parts = deduplicated_parts.into_values().collect::<Vec<_>>();
122+
parts.sort_by_key(|part| part.part_number);
109123

110124
let metadata = build_video_meta(&file_path)
111125
.map_err(|e| error!("Failed to get video metadata: {e}"))
@@ -541,7 +555,7 @@ pub fn from_pending_file_to_chunks(
541555
}
542556
} else if new_data_size == 0 && realtime_is_done.unwrap_or(true) {
543557
// Recording is done and no new data - re-emit first chunk with corrected MP4 header
544-
if let Some(first_size) = first_chunk_size {
558+
if let Some(first_size) = first_chunk_size && realtime_upload_done.is_some() {
545559
file.seek(std::io::SeekFrom::Start(0)).await?;
546560

547561
let chunk_size = first_size as usize;
@@ -606,7 +620,7 @@ fn multipart_uploader(
606620
let mut prev_part_number = None;
607621
while let Some(item) = stream.next().await {
608622
let Chunk { total_size, part_number, chunk } = item.map_err(|err| format!("uploader/part/{:?}/fs: {err:?}", prev_part_number.map(|p| p + 1)))?;
609-
debug!("Uploading chunk {part_number} for video {video_id:?}");
623+
debug!("Uploading chunk {part_number} ({} bytes) for video {video_id:?}", chunk.len());
610624
prev_part_number = Some(part_number);
611625
let md5_sum = base64::encode(md5::compute(&chunk).0);
612626
let size = chunk.len();
@@ -820,7 +834,7 @@ fn progress<T: UploadedChunk, E>(
820834
}
821835

822836
/// Track the upload progress into a Tauri channel
823-
fn tauri_progress<T: UploadedChunk, E>(
837+
fn tauri_channel_progress<T: UploadedChunk, E>(
824838
channel: Channel<UploadProgress>,
825839
stream: impl Stream<Item = Result<T, E>>,
826840
) -> impl Stream<Item = Result<T, E>> {

apps/desktop/src/routes/(window-chrome)/settings/recordings.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
type ParentProps,
2222
Show,
2323
} from "solid-js";
24-
import { createStore, produce } from "solid-js/store";
24+
import { createStore, produce, reconcile } from "solid-js/store";
2525
import CapTooltip from "~/components/Tooltip";
2626
import { trackEvent } from "~/utils/analytics";
2727
import { createTauriEventListener } from "~/utils/createEventListener";
@@ -76,6 +76,7 @@ const recordingsQuery = queryOptions({
7676
);
7777
return recordings;
7878
},
79+
reconcile: (old, n) => reconcile(n)(old),
7980
// This will ensure any changes to the upload status in the project meta are reflected.
8081
refetchInterval: 2000,
8182
});

0 commit comments

Comments
 (0)