feat(mobile): update notifications and more error handling added
All checks were successful
Build and Push LST Docker Image / docker (push) Successful in 1m24s
All checks were successful
Build and Push LST Docker Image / docker (push) Successful in 1m24s
This commit is contained in:
@@ -2,6 +2,9 @@ import fs from "node:fs";
|
||||
import { Router } from "express";
|
||||
import path from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
import { db } from "../db/db.controller.js";
|
||||
import { scanLog } from "../db/schema/scanlog.schema.js";
|
||||
import { apiReturn } from "../utils/returnHelper.utils.js";
|
||||
|
||||
const router = Router();
|
||||
|
||||
@@ -12,27 +15,23 @@ const downloadDir = path.resolve(__dirname, "../../downloads/mobile");
|
||||
const projectRoot = path.resolve("./lstMobile"); // adjust as needed
|
||||
const appJsonPath = path.join(projectRoot, "app.json");
|
||||
|
||||
const raw = fs.readFileSync(appJsonPath, "utf-8");
|
||||
const config = JSON.parse(raw);
|
||||
|
||||
const exp = config.expo;
|
||||
|
||||
const currentApk = {
|
||||
packageName: exp.android?.package,
|
||||
versionName: exp.version,
|
||||
versionCode: exp.android?.versionCode,
|
||||
minSupportedVersionCode: 1, // keep this custom if needed
|
||||
fileName: "lst-mobile.apk",
|
||||
};
|
||||
|
||||
router.get("/version", async (req, res) => {
|
||||
const baseUrl = `${req.protocol}://${req.get("host")}`;
|
||||
|
||||
const raw = fs.readFileSync(appJsonPath, "utf-8");
|
||||
const config = JSON.parse(raw);
|
||||
|
||||
const exp = config.expo;
|
||||
|
||||
res.json({
|
||||
packageName: currentApk.packageName,
|
||||
versionName: currentApk.versionName,
|
||||
versionCode: currentApk.versionCode,
|
||||
minSupportedVersionCode: currentApk.minSupportedVersionCode,
|
||||
packageName: exp.android?.package,
|
||||
versionName: exp.version,
|
||||
versionCode: exp.android?.versionCode,
|
||||
minSupportedVersionCode: exp?.android?.minSupportedVersionCode ?? 0,
|
||||
downloadUrl: `${baseUrl}/lst/api/mobile/apk/latest`,
|
||||
});
|
||||
});
|
||||
@@ -66,4 +65,29 @@ router.get("/apk/ehs", (_, res) => {
|
||||
return res.sendFile(apkPath);
|
||||
});
|
||||
|
||||
router.post("/logs", async (req, res) => {
|
||||
const body = req.body;
|
||||
const newLog = await db
|
||||
.insert(scanLog)
|
||||
.values({
|
||||
scannerId: body.data.scannerId,
|
||||
message: body.data.message,
|
||||
prompt: body.data.prompt,
|
||||
commandDescription: body.data.commandDescription,
|
||||
status: body.data.status,
|
||||
lines: body.data.lines,
|
||||
})
|
||||
.returning();
|
||||
|
||||
return apiReturn(res, {
|
||||
success: true,
|
||||
level: "info",
|
||||
module: "mobile",
|
||||
subModule: "scan logs",
|
||||
message: `New log from ${body.data.scannerId}`,
|
||||
data: newLog,
|
||||
status: 200,
|
||||
});
|
||||
});
|
||||
|
||||
export default router;
|
||||
|
||||
Reference in New Issue
Block a user