Getting lvgmc csv files in frontend

This commit is contained in:
Guntis Smaukstelis
2025-03-10 16:56:24 +02:00
parent 9d6b86e218
commit 841b4b6ec9
6 changed files with 62 additions and 6 deletions
+3 -1
View File
@@ -9,12 +9,13 @@ import { Station } from './station/Station';
import { apiHost } from './consts';
import { WeatherIconStub } from './components/weatherIcons/WeatherIconStub';
import { Harmonie } from './harmonie/Harmonie'
import { LvgmcForecast } from './lvgmc-forecast/LvgmcForecast'
console.log("env:", import.meta.env.MODE)
console.log("api host:", apiHost)
const App: Component = () => {
const pages = ['station', 'cities', 'latvia', 'database', 'harmonie']
const pages = ['station', 'cities', 'latvia', 'database', 'harmonie', 'lvgmc-forecast']
return (
<div>
<div class="grid-1-1">
@@ -32,6 +33,7 @@ const App: Component = () => {
<Router>
<Route path="/" component={Harmonie} />
<Route path="/harmonie" component={Harmonie} />
<Route path="/lvgmc-forecast" component={LvgmcForecast} />
<Route path="/station" component={Station} />
<Route path="/cities" component={Cities} />
<Route path="/latvia" component={Country} />
+26
View File
@@ -25,6 +25,32 @@ export const fetchJson = (url: string, options = {}) => {
})
}
export const fetchText = (url: string, options = {}) => {
return fetch(url, options).then(async response => {
let responseCode = ''
if (!response.ok) {
responseCode = `error ${response.status}`
}
let text = ''
let responseMessage = ''
try {
text = await response.text()
} catch (err) {
responseMessage = 'Invalid TEXT response'
}
if (responseCode) {
if (responseMessage) throw new Error(`${responseCode}: ${responseMessage}`)
else throw new Error(responseCode)
} else if (responseMessage) {
throw new Error(responseMessage)
}
return text
})
}
export const fetchBuffer = (url: string, options = {}) => {
return fetch(url, options).then(async response => {
+18
View File
@@ -0,0 +1,18 @@
import { Component } from 'solid-js'
import { apiHost } from '../consts'
import { fetchText } from '../helpers/fetch'
// Eiropa_LTV_pilsetas_nakama_dn.csv
// Eiropa_LTV_pilsetas_tekosa_dn.csv
// Latvija_LTV_pilsetas_nakama_dnn.csv
// Latvija_LTV_pilsetas_tekosa_dn.csv
// Latvija_faktiskais_laiks.csv
export const LvgmcForecast: Component<{}> = () => {
fetchText(`${apiHost}/api/show/lvgmc-forecast/Latvija_LTV_pilsetas_tekosa_dn.csv`)
.then(console.log)
return <>
LvgmcForecast
</>
}