11/**
22 * Chunked file uploader for Sploder-Launcher builds
3- * Uploads build artifacts in 90MB chunks with API key authentication
3+ * Uploads build artifacts in 90MB chunks with API key // Create URLSearchParams for proper form encoding
4+ const formPairs = [];
5+ for (const [key, value] of Object.entries(formFields)) {
6+ formPairs.push(`${encodeURIComponent(key)}=${encodeURIComponent(value)}`);
7+ }
8+
9+ const formDataString = formPairs.join('&');
10+
11+ // Debug: Show first part of form data to verify structure
12+ console.log(`🔧 Form data preview: ${formDataString.substring(0, 200)}...`);
13+ console.log(`📦 Chunk ${chunkIndex + 1}/${totalChunks}: ${(chunkData.length / 1024 / 1024).toFixed(2)}MB`);cation
414 */
515
616const fs = require ( 'fs' ) ;
@@ -18,6 +28,8 @@ if (!API_KEY) {
1828 process . exit ( 1 ) ;
1929}
2030
31+ console . log ( `🔑 API Key loaded: ${ API_KEY . substring ( 0 , 8 ) } ...${ API_KEY . substring ( API_KEY . length - 4 ) } ` ) ;
32+
2133if ( ! process . env . UPLOAD_URL ) {
2234 console . error ( '❌ UPLOAD_URL environment variable is required' ) ;
2335 process . exit ( 1 ) ;
@@ -90,24 +102,47 @@ function makeRequest(url, options, data) {
90102 * Upload a single chunk
91103 */
92104async function uploadChunk ( filePath , fileName , chunkIndex , chunkData , totalChunks , fileHash ) {
105+ // Create form data for application/x-www-form-urlencoded
106+ const formFields = {
107+ 'api_key' : API_KEY ,
108+ 'file_name' : fileName ,
109+ 'chunk_index' : chunkIndex . toString ( ) ,
110+ 'total_chunks' : totalChunks . toString ( ) ,
111+ 'file_hash' : fileHash ,
112+ 'chunk_data' : chunkData . toString ( 'base64' )
113+ } ;
114+
115+ // Validate all required fields
116+ const requiredFields = [ 'api_key' , 'file_name' , 'chunk_index' , 'total_chunks' , 'file_hash' , 'chunk_data' ] ;
117+ for ( const field of requiredFields ) {
118+ if ( ! formFields [ field ] || formFields [ field ] === '' ) {
119+ throw new Error ( `Missing or empty field: ${ field } ` ) ;
120+ }
121+ }
122+
123+ // Create URLSearchParams for proper form encoding
93124 const formData = new URLSearchParams ( ) ;
94- formData . append ( 'api_key' , API_KEY ) ;
95- formData . append ( 'file_name' , fileName ) ;
96- formData . append ( 'chunk_index' , chunkIndex . toString ( ) ) ;
97- formData . append ( 'total_chunks' , totalChunks . toString ( ) ) ;
98- formData . append ( 'file_hash' , fileHash ) ;
99- formData . append ( 'chunk_data' , chunkData . toString ( 'base64' ) ) ;
125+ for ( const [ key , value ] of Object . entries ( formFields ) ) {
126+ formData . append ( key , value ) ;
127+ }
128+
129+ const formDataString = formData . toString ( ) ;
130+ console . log ( `Chunk ${ chunkIndex + 1 } / ${ totalChunks } : ${ ( chunkData . length / 1024 / 1024 ) . toFixed ( 2 ) } MB` ) ;
100131
101132 const response = await makeRequest ( UPLOAD_ENDPOINT , {
102133 method : 'POST' ,
103134 headers : {
104135 'Content-Type' : 'application/x-www-form-urlencoded' ,
105- 'Content-Length' : Buffer . byteLength ( formData . toString ( ) )
136+ 'Content-Length' : Buffer . byteLength ( formDataString )
106137 }
107- } , formData . toString ( ) ) ;
138+ } , formDataString ) ;
108139
109- if ( response . status !== 200 || ! response . data . success ) {
110- throw new Error ( `Upload failed for chunk ${ chunkIndex } : ${ JSON . stringify ( response . data ) } ` ) ;
140+ if ( response . status !== 200 ) {
141+ throw new Error ( `HTTP ${ response . status } : ${ JSON . stringify ( response . data ) } ` ) ;
142+ }
143+
144+ if ( ! response . data . success ) {
145+ throw new Error ( `Server error: ${ JSON . stringify ( response . data ) } ` ) ;
111146 }
112147
113148 return response . data ;
@@ -170,6 +205,10 @@ function findFilesToUpload(directory) {
170205 else if ( item . name . endsWith ( '.zip' ) && item . name . includes ( 'Portable' ) ) {
171206 files . push ( { path : fullPath , type : 'windows-portable' } ) ;
172207 }
208+ // macOS zip file (direct file)
209+ else if ( item . name === 'Sploder-macOS.zip' ) {
210+ files . push ( { path : fullPath , type : 'macos-app' } ) ;
211+ }
173212 } else if ( item . isDirectory ( ) ) {
174213 // macOS app files (in mac/ directory)
175214 if ( item . name === 'mac' ) {
0 commit comments