This commit is contained in:
2025-08-26 12:20:17 +02:00
parent be3cd771fc
commit ff43eddd27
4 changed files with 100 additions and 78 deletions

View File

@@ -199,15 +199,32 @@ class SporeApiClient {
/**
* Update firmware on the device
* @param {Buffer|Uint8Array} firmwareData - Firmware binary data
* @param {string} filename - Name of the firmware file
* @returns {Promise<Object>} Update response
*/
async updateFirmware(firmwareData, filename) {
// Send the raw firmware data directly to the SPORE device
// The SPORE device expects the file data, not re-encoded multipart
// Create multipart form data manually for Node.js compatibility
const boundary = '----WebKitFormBoundary' + Math.random().toString(16).substr(2, 8);
let body = '';
// Add the firmware file part
body += `--${boundary}\r\n`;
body += `Content-Disposition: form-data; name="firmware"; filename="${filename}"\r\n`;
body += 'Content-Type: application/octet-stream\r\n\r\n';
// Convert the body to Buffer and append the firmware data
const headerBuffer = Buffer.from(body, 'utf8');
const endBuffer = Buffer.from(`\r\n--${boundary}--\r\n`, 'utf8');
// Combine all parts
const finalBody = Buffer.concat([headerBuffer, firmwareData, endBuffer]);
// Send the multipart form data to the SPORE device
return this.request('POST', '/api/node/update', {
body: firmwareData,
body: finalBody,
headers: {
'Content-Type': 'application/octet-stream'
'Content-Type': `multipart/form-data; boundary=${boundary}`
}
});
}