trim serial/name mapping; add a log message

This commit is contained in:
David Ventura
2024-05-01 13:17:37 +02:00
parent 5a0b36f42b
commit 2ce568c019
+3 -2
View File
@@ -21,7 +21,7 @@ const sessions: Record<string, Session> = {};
// Text file containing the mapping of camera names.
const nameFile = "cameras.txt";
// Reads the simple mapping of camera names from the text file.
// Reads the mapping of serial numbers to camera names from the text file.
const cameraNames = Object.assign(
{},
...(existsSync(nameFile) ? readFileSync(nameFile, "utf8") : "")
@@ -32,7 +32,7 @@ const cameraNames = Object.assign(
.filter((l) => l.trim() != "")
.map((l) => {
let kv = l.split("=");
return { [kv[0]]: kv[1] };
return { [kv[0].trim()]: kv[1].trim() };
}),
);
@@ -41,6 +41,7 @@ const cameraName = (id: string): string => cameraNames[id] || id;
// The HTTP server.
export const serveHttp = (opts: opt, port: number, with_audio: boolean) => {
logger.info(`Mapping camera names: ${JSON.stringify(cameraNames)}`);
const server = http.createServer((req, res) => {
if (req.url.startsWith("/ui/")) {
let devId = req.url.split("/")[2];