import fs module and update OTA check logic to compare version numbers correctly
This commit is contained in:
@@ -11,6 +11,7 @@ import {
|
|||||||
saveDevice,
|
saveDevice,
|
||||||
} from "../data";
|
} from "../data";
|
||||||
import { generateDeviceToken, sensorboxAuth, verifyDeviceToken } from "../auth";
|
import { generateDeviceToken, sensorboxAuth, verifyDeviceToken } from "../auth";
|
||||||
|
import fs from "fs";
|
||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
@@ -119,15 +120,13 @@ router.get("/ota/check", sensorboxAuth, (req, res) => {
|
|||||||
saveDevice(device);
|
saveDevice(device);
|
||||||
|
|
||||||
const update = findLatestReleaseDb(device.type, group, hardwareVersion);
|
const update = findLatestReleaseDb(device.type, group, hardwareVersion);
|
||||||
if (!update || update.version === softwareVersion) {
|
if (!update || update.version <= softwareVersion) {
|
||||||
res.sendStatus(204);
|
res.sendStatus(204);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const link = createDownloadLinkDb(device.id, update.id);
|
const link = createDownloadLinkDb(device.id, update.id);
|
||||||
const downloadUrl = `${config.baseUrl}/download/${link.id}`;
|
const downloadUrl = `${config.baseUrl}/download/${link.id}`;
|
||||||
// Get size of the update file to include in the response header
|
|
||||||
const fs = require("fs");
|
|
||||||
let fileSize = 0;
|
let fileSize = 0;
|
||||||
try {
|
try {
|
||||||
const stats = fs.statSync(update.filePath);
|
const stats = fs.statSync(update.filePath);
|
||||||
|
|||||||
Reference in New Issue
Block a user