UNPKG

@robotical/sensors-dashboard

Version:

A dashboard tool for depicting Marty data by Robotical

36 lines (35 loc) 1.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; require("core-js/modules/es.promise.js"); require("core-js/modules/es.regexp.exec.js"); require("core-js/modules/es.string.replace.js"); require("core-js/modules/es.json.stringify.js"); const DATABASE_URL = 'https://marty-webapp-default-rtdb.firebaseio.com/'; const LOG_PATH = 'logs'; const SHOULD_WRITE_LOGS = true; class OnlineLogger { static async writeLog(logTitle, log) { if (!SHOULD_WRITE_LOGS) return; try { const logPath = "".concat(LOG_PATH, "/").concat(new Date().toISOString().replace(/:/g, '-').replace(/\./g, '-'), "_").concat(logTitle, ".json"); const response = await fetch("".concat(DATABASE_URL).concat(logPath), { method: 'PUT', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ log }) }); if (!response.ok) { throw new Error('Failed to write log to database'); } } catch (error) { console.error('Failed to write log to database:', error); } } } exports.default = OnlineLogger;