API-Auth dazu

automatisch auf INFLUX schalten, wenn es Chi-ID gibt
zuzsätzlich option db=m zum erzwingen von Moing
Anzeige Mongo/Influx im Datenstrom
This commit is contained in:
2025-11-05 09:47:25 +00:00
parent 6d9d94f2fa
commit bd44740649
9 changed files with 973 additions and 22 deletions

View File

@@ -2,6 +2,7 @@
const DBASE = process.env.DBASE || 'mongo'
import {DateTime} from "luxon"
import {logit} from "../utilities/logit.js"
import * as influx from "../databases/influx_sql.js"
import * as mongo from "../databases/mongo.js"
import {returnOnError} from "../utilities/reporterror.js"
@@ -23,6 +24,7 @@ const noiseParams = [
{name: 'csv', type: 'bool', default: false},
{name: 'long', type: 'bool', default: false},
{name: 'sort', type: 'int', default: 1},
{name: 'db', type: 'string', default: ''},
{name: 'last_seen', type: 'date', default: '1900-01-01T00:00:00Z'},
{name: 'datetime', type: 'date', default: null}
]
@@ -146,17 +148,30 @@ export async function getSensorData(params) {
return returnOnError(ret, 'CMNDUNKNOWN', getActData.name)
}
const getChipPropety = async (opts) => {
// read 'chip'-data (special for noise sensors)
opts.chipid = null
const chipdata = await mongo.readChipData(opts.sensorid)
logit('Ergebnis von readChipData:', chipdata)
if ((chipdata.err === null) && (chipdata.chipdata !== null)) {
opts.chipid = chipdata.chipdata.chip.id
}
if (opts.db === 'm') {
opts.chipid = null
}
return chipdata.err
}
// export const getActData = async (opts) => {
export async function getActData(opts) {
if (DBASE === 'mongo') {
return await mongo.fetchActData(opts)
} else if (DBASE === 'influx') {
const chiperr = await getChipPropety(opts)
if (opts.chipid) {
return await influx.fetchActData(opts)
} else {
return await mongo.fetchActData(opts)
}
return {err: 'DBASEUNKNOWN', values: []}
}