import fs module and update OTA check logic to compare version numbers correctly
This commit is contained in:
@@ -11,6 +11,7 @@ import {
|
||||
saveDevice,
|
||||
} from "../data";
|
||||
import { generateDeviceToken, sensorboxAuth, verifyDeviceToken } from "../auth";
|
||||
import fs from "fs";
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
@@ -119,15 +120,13 @@ router.get("/ota/check", sensorboxAuth, (req, res) => {
|
||||
saveDevice(device);
|
||||
|
||||
const update = findLatestReleaseDb(device.type, group, hardwareVersion);
|
||||
if (!update || update.version === softwareVersion) {
|
||||
if (!update || update.version <= softwareVersion) {
|
||||
res.sendStatus(204);
|
||||
return;
|
||||
}
|
||||
|
||||
const link = createDownloadLinkDb(device.id, update.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;
|
||||
try {
|
||||
const stats = fs.statSync(update.filePath);
|
||||
|
||||
Reference in New Issue
Block a user