fix: firmware upload failure
This commit is contained in:
16
index.js
16
index.js
@@ -645,7 +645,21 @@ app.post('/api/node/update', async (req, res) => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const updateResult = await nodeClient.updateFirmware(uploadedFile.data, uploadedFile.name);
|
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({
|
res.json({
|
||||||
success: true,
|
success: true,
|
||||||
|
|||||||
@@ -94,13 +94,19 @@ class ApiClient {
|
|||||||
async uploadFirmware(file, nodeIp) {
|
async uploadFirmware(file, nodeIp) {
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('file', file);
|
formData.append('file', file);
|
||||||
return this.request(`/api/node/update`, {
|
const data = await this.request(`/api/node/update`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
query: { ip: nodeIp },
|
query: { ip: nodeIp },
|
||||||
body: formData,
|
body: formData,
|
||||||
isForm: true,
|
isForm: true,
|
||||||
headers: {},
|
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