Skip to content

Commit 5c82044

Browse files
Copilotgantoine
andauthored
fix: avoid safari chunk upload progress stalls
Agent-Logs-Url: https://github.com/rommapp/romm/sessions/41c15553-6e97-45ca-be3d-589c2f07589e Co-authored-by: gantoine <3247106+gantoine@users.noreply.github.com>
1 parent 67060d4 commit 5c82044

1 file changed

Lines changed: 30 additions & 10 deletions

File tree

  • frontend/src/services/api

frontend/src/services/api/rom.ts

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@ type SearchRom = SearchRomSchema;
2727
const DOWNLOAD_CLEANUP_DELAY = 100;
2828
const UPLOAD_CHUNK_SIZE = 10 * 1024 * 1024; // 10MB per chunk
2929
const MAX_CHUNK_RETRIES = 3;
30+
const WEBKIT_USER_AGENT_RE = /AppleWebKit/i;
31+
const CHROMIUM_BROWSER_RE = /Chrome|Chromium|CriOS|Edg|OPR/i;
32+
33+
function shouldTrackChunkUploadProgress(): boolean {
34+
if (typeof navigator === "undefined") return true;
35+
36+
const userAgent = navigator.userAgent;
37+
return !(
38+
WEBKIT_USER_AGENT_RE.test(userAgent) &&
39+
!CHROMIUM_BROWSER_RE.test(userAgent)
40+
);
41+
}
3042

3143
async function uploadRomChunked({
3244
platformId,
@@ -37,6 +49,7 @@ async function uploadRomChunked({
3749
}): Promise<void> {
3850
const uploadStore = storeUpload();
3951
const totalChunks = Math.ceil(file.size / UPLOAD_CHUNK_SIZE);
52+
const trackChunkUploadProgress = shouldTrackChunkUploadProgress();
4053

4154
const { data: startData } = await api.post("/roms/upload/start", null, {
4255
headers: {
@@ -64,17 +77,24 @@ async function uploadRomChunked({
6477
"X-Chunk-Index": i.toString(),
6578
},
6679
timeout: 120000,
67-
onUploadProgress: (progressEvent: AxiosProgressEvent) => {
68-
const chunkFraction = progressEvent.progress ?? 0;
69-
const overall = ((i + chunkFraction) / totalChunks) * 100;
70-
uploadStore.updateChunkProgress(
71-
file.name,
72-
overall,
73-
file.size,
74-
progressEvent.rate,
75-
);
76-
},
80+
...(trackChunkUploadProgress && {
81+
onUploadProgress: (progressEvent: AxiosProgressEvent) => {
82+
const chunkFraction = progressEvent.progress ?? 0;
83+
const overall = ((i + chunkFraction) / totalChunks) * 100;
84+
uploadStore.updateChunkProgress(
85+
file.name,
86+
overall,
87+
file.size,
88+
progressEvent.rate,
89+
);
90+
},
91+
}),
7792
});
93+
uploadStore.updateChunkProgress(
94+
file.name,
95+
((i + 1) / totalChunks) * 100,
96+
file.size,
97+
);
7898
lastError = null;
7999
break;
80100
} catch (err) {

0 commit comments

Comments
 (0)