| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- import { Elysia } from 'elysia'
- import { Eta } from "eta"
- const eta = new Eta({ views: "./templates" })
- import Meteostanica from '../../utils/meteostanica'
- import editEnvVariable from '../../utils/editEnvVariable'
- import getWifiIPv4 from '../../utils/getWifiIPv4'
- export default (langName, lang) => new Elysia()
- .get('/', ({ set }) => {
- const data = Meteostanica.getData()
- set.headers['content-type'] = 'text/html; charset=utf8'
- return eta.render(`${langName}/index`, { data })
- })
- .get('/settings', ({ set }) => {
- set.headers['content-type'] = 'text/html; charset=utf8'
- return eta.render(`${langName}/settings`, { wifiIPv4: getWifiIPv4(), postDataEnabled: process.env.POST_DATA_ENABLED, cloudURL: process.env.BACKEND_URL })
- })
- .post('/settings', async ({ body, set, redirect }) => {
- const postDataEnabled = body?.postDataEnabled
- const cloudURL = body?.cloudURL
- postDataEnabled?.replaceAll(`"`, ``)
- cloudURL?.replaceAll(`"`, ``)
- if (!cloudURL) {
- set.headers['content-type'] = 'text/html; charset=utf8'
- return eta.render(`${langName}/settings`, { wifiIPv4: getWifiIPv4(), lang, error: `noCloudURL` })
- }
-
- await editEnvVariable(`POST_DATA_ENABLED`, postDataEnabled ?? "false")
- await editEnvVariable(`BACKEND_URL`, cloudURL)
- return redirect(`${langName === `sk` ? `/` : `/en`}`)
- })
- .get('/currentData', () => {
- const data = Meteostanica.getData()
- return data?.[0]
- })
|