1- const DEBUG = true ;
2-
3- // Configuration constants
4- const CHUNK_SIZE_MOBILE = 32 * 1024 ; // 32KB for mobile devices
5- const CHUNK_SIZE_DESKTOP = 64 * 1024 ; // 64KB for desktop devices
6- const BUFFER_THRESHOLD_MOBILE = CHUNK_SIZE_MOBILE * 16 ;
7- const BUFFER_THRESHOLD_DESKTOP = CHUNK_SIZE_DESKTOP * 16 ;
8- const BUFFER_CHECK_INTERVAL = 200 ; // 200ms interval for buffer checks
9- const SHARE_LINK_FOCUS_DELAY = 300 ; // 300ms delay before focusing share link
10- const TRANSFER_FINALIZE_DELAY = 1000 ; // 1000ms delay before finalizing transfer
11- const MOBILE_BREAKPOINT = 768 ; // 768px mobile breakpoint
12- const TRANSFER_ID_MAX_NUMBER = 1000 ; // Maximum number for transfer ID generation
13-
1+ const CHUNK_SIZE_MOBILE = 32 * 1024 ; // 32KiB for mobile devices
2+ const CHUNK_SIZE_DESKTOP = 64 * 1024 ; // 64KiB for desktop devices
3+ const BUFFER_THRESHOLD_MOBILE = CHUNK_SIZE_MOBILE * 16 ; // 512KiB buffer threshold for mobile
4+ const BUFFER_THRESHOLD_DESKTOP = CHUNK_SIZE_DESKTOP * 16 ; // 1MiB buffer threshold for desktop
5+ const BUFFER_CHECK_INTERVAL = 200 ; // 200ms interval for buffer checks
6+ const SHARE_LINK_FOCUS_DELAY = 300 ; // 300ms delay before focusing share link
7+ const TRANSFER_FINALIZE_DELAY = 1000 ; // 1000ms delay before finalizing transfer
8+ const MOBILE_BREAKPOINT = 768 ; // 768px mobile breakpoint
9+ const TRANSFER_ID_MAX_NUMBER = 1000 ; // Maximum number for transfer ID generation (0-999)
10+
11+ const DEBUG_LOGS = true ;
1412const log = {
15- debug : ( ...args ) => DEBUG && console . debug ( ...args ) ,
13+ debug : ( ...args ) => DEBUG_LOGS && console . debug ( ...args ) ,
1614 info : ( ...args ) => console . info ( ...args ) ,
1715 warn : ( ...args ) => console . warn ( ...args ) ,
1816 error : ( ...args ) => console . error ( ...args )
@@ -31,7 +29,7 @@ function initFileTransfer() {
3129 progressText : document . getElementById ( 'progress-text' ) ,
3230 statusText : document . getElementById ( 'status-text' ) ,
3331 shareLink : document . getElementById ( 'share-link' ) ,
34- shareUrl : document . getElementById ( 'share-url' ) ,
32+ shareUrl : document . getElementById ( 'share-url' )
3533 } ;
3634
3735 if ( isMobileDevice ( ) && elements . dropAreaText ) {
@@ -132,10 +130,8 @@ function displayShareLink(elements, transferId) {
132130function uploadFile ( file , elements ) {
133131 const transferId = generateTransferId ( ) ;
134132
135- const isLocalhost = window . location . hostname === 'localhost' || window . location . hostname === '127.0.0.1' ;
136- const wsUrl = isLocalhost
137- ? `ws://${ window . location . hostname } :${ window . location . port || 8080 } /send/${ transferId } `
138- : `wss://transit.sh/send/${ transferId } ` ;
133+ const wsProtocol = window . location . protocol === 'https:' ? 'wss:' : 'ws:' ;
134+ const wsUrl = `${ wsProtocol } //${ window . location . host } /send/${ transferId } ` ;
139135
140136 log . info ( 'Starting upload:' , { transferId, fileName : file . name , fileSize : file . size , wsUrl } ) ;
141137
@@ -150,9 +146,9 @@ function uploadFile(file, elements) {
150146
151147 showProgress ( elements ) ;
152148
153- ws . onopen = ( ) => handleWsOpen ( ws , file , transferId , elements , uploadState ) ;
149+ ws . onopen = ( ) => handleWsOpen ( ws , file , transferId , elements ) ;
154150 ws . onmessage = ( event ) => handleWsMessage ( event , ws , file , elements , abortController , uploadState ) ;
155- ws . onerror = ( error ) => handleWsError ( error , elements . statusText , uploadState ) ;
151+ ws . onerror = ( error ) => handleWsError ( error , elements . statusText ) ;
156152 ws . onclose = ( event ) => {
157153 log . info ( 'WebSocket connection closed:' , { code : event . code , reason : event . reason , wasClean : event . wasClean } ) ;
158154 if ( uploadState . isUploading && ! event . wasClean ) {
@@ -200,7 +196,7 @@ function uploadFile(file, elements) {
200196 }
201197}
202198
203- function handleWsOpen ( ws , file , transferId , elements , uploadState ) {
199+ function handleWsOpen ( ws , file , transferId , elements ) {
204200 log . info ( 'WebSocket connection opened' ) ;
205201 const metadata = {
206202 file_name : file . name ,
@@ -230,7 +226,7 @@ function handleWsMessage(event, ws, file, elements, abortController, uploadState
230226 }
231227}
232228
233- function handleWsError ( error , statusText , uploadState ) {
229+ function handleWsError ( error , statusText ) {
234230 log . error ( 'WebSocket error:' , error ) ;
235231 statusText . textContent = 'Error: ' + ( error . message || 'Connection failed' ) ;
236232 statusText . style . color = 'var(--error)' ;
0 commit comments