From ad855e7b0eeeca087a5832b5c7264cd680f4e959 Mon Sep 17 00:00:00 2001 From: ckegel <57967583+CKegel@users.noreply.github.com> Date: Wed, 15 Mar 2023 13:56:41 -0400 Subject: [PATCH] Moved Latitude and Longitude to enviornment variables that can be accessed through an API --- .env.example | 2 ++ public/js/whiteboard.js | 16 +++++++++------- server.js | 5 +++++ 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/.env.example b/.env.example index d53b548..0716e87 100644 --- a/.env.example +++ b/.env.example @@ -9,3 +9,5 @@ PORT=8080 TZ=America/New_York CHOREBOT_VERIFICATION_TOKEN=chorebot token here ENV=dev +LONGITUDE:logitudehere +LATITUDE:latitudehere diff --git a/public/js/whiteboard.js b/public/js/whiteboard.js index 1ab2a2d..984b6ce 100644 --- a/public/js/whiteboard.js +++ b/public/js/whiteboard.js @@ -1,7 +1,5 @@ /* global moment, io, SunCalc */ - -const longitude = -73.67577; -const latitude = 42.72927; +let locale; // 30 minutes in milliseconds (60000 ms in 1 min) //Time Constants(in Milliseconds) const oneMinute = 60000; @@ -90,7 +88,7 @@ function updateDate() { document.querySelector("#date").innerHTML = todaysDate.format("D MMM YY"); document.querySelector("#time").innerHTML = todaysDate.format("HH:mm"); - const times = SunCalc.getTimes(new Date(), latitude, longitude); + const times = SunCalc.getTimes(new Date(), locale.latitude, locale.longitude); const now = Date.now(); // if the current time falls between 30 minutes after sunrise and // 30 minutes after sunset, then we use the light stylesheet, otherwise @@ -195,8 +193,6 @@ function handleDispatch(determinant, complaint, location) { dispatchTimeoutID = setTimeout(clearDispatch, threeMinutes); } -updateDate(); - const socket = io.connect(); socket.on("notes", (noteResponse) => { updateNotes(noteResponse); @@ -230,4 +226,10 @@ socket.on("dispatch", (dispatchResponse) => { // Refreshes the page allowing us to update the UI without ever touching the tv socket.on("refresh", () => window.location.reload()); -setInterval(() => updateDate(), 2000); +const response = fetch('/locale') + .then((response) => response.json()) + .then((data) => { + locale = data; + updateDate(); + setInterval(() => updateDate(), 2000); +}); \ No newline at end of file diff --git a/server.js b/server.js index cff2202..42939c9 100644 --- a/server.js +++ b/server.js @@ -24,6 +24,7 @@ const pool = mariadb.createPool({ const PORT = process.env.PORT || 8080; const WEBSITE_ACCESS_TOKEN = process.env.WEBSITE_ACCESS_TOKEN; const HERALD_TOKEN = process.env.HERALD_TOKEN; +const LOCALE = {longitude: process.env.LONGITUDE, latitude: process.env.LATITUDE}; // app.use(bodyParser.urlencoded({ extended: true })); app.use(bodyParser.json()); @@ -34,6 +35,10 @@ app.get('/suncalc.js', (_, res) => { res.sendFile(path.join(__dirname, 'node_modules', 'suncalc', 'suncalc.js')); }); +app.get('/locale', (_, res) => { + res.json(LOCALE); +}); + app.get('/', (req, res) => { if (WEBSITE_ACCESS_TOKEN !== req.query.token) { res.sendStatus(403);