feature/desktop-view #5
16
index.js
16
index.js
@@ -645,7 +645,21 @@ app.post('/api/node/update', async (req, res) => {
|
||||
|
||||
try {
|
||||
const updateResult = await nodeClient.updateFirmware(uploadedFile.data, uploadedFile.name);
|
||||
console.log(`Firmware upload to SPORE device ${nodeIp} completed successfully:`, updateResult);
|
||||
console.log(`Firmware upload to SPORE device ${nodeIp} completed:`, updateResult);
|
||||
|
||||
// Check if the SPORE device reported a failure
|
||||
if (updateResult && updateResult.status === 'FAIL') {
|
||||
console.error(`SPORE device ${nodeIp} reported firmware update failure:`, updateResult.message);
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
error: 'Firmware update failed',
|
||||
message: updateResult.message || 'Firmware update failed on device',
|
||||
nodeIp: nodeIp,
|
||||
fileSize: uploadedFile.data.length,
|
||||
filename: uploadedFile.name,
|
||||
result: updateResult
|
||||
});
|
||||
}
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
|
||||
@@ -94,13 +94,19 @@ class ApiClient {
|
||||
async uploadFirmware(file, nodeIp) {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
return this.request(`/api/node/update`, {
|
||||
const data = await this.request(`/api/node/update`, {
|
||||
method: 'POST',
|
||||
query: { ip: nodeIp },
|
||||
body: formData,
|
||||
isForm: true,
|
||||
headers: {},
|
||||
});
|
||||
// Some endpoints may return HTTP 200 with success=false on logical failure
|
||||
if (data && data.success === false) {
|
||||
const message = data.message || 'Firmware upload failed';
|
||||
throw new Error(message);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user