@@ -27,6 +27,18 @@ type SearchRom = SearchRomSchema;
2727const DOWNLOAD_CLEANUP_DELAY = 100 ;
2828const UPLOAD_CHUNK_SIZE = 10 * 1024 * 1024 ; // 10MB per chunk
2929const MAX_CHUNK_RETRIES = 3 ;
30+ const WEBKIT_USER_AGENT_RE = / A p p l e W e b K i t / i;
31+ const CHROMIUM_BROWSER_RE = / C h r o m e | C h r o m i u m | C r i O S | E d g | O P R / 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
3143async 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