|
@@ -7,10 +7,20 @@ const eta = new Eta({ views: "./templates" })
|
|
|
export default (langName, lang) => new Elysia({ prefix: `/history` })
|
|
export default (langName, lang) => new Elysia({ prefix: `/history` })
|
|
|
.get('/', ({ set }) => {
|
|
.get('/', ({ set }) => {
|
|
|
set.headers['content-type'] = 'text/html; charset=utf8'
|
|
set.headers['content-type'] = 'text/html; charset=utf8'
|
|
|
- return eta.render(`${langName}/history/index`, { })
|
|
|
|
|
|
|
+ return eta.render(`${langName}/history/index`, { lang })
|
|
|
})
|
|
})
|
|
|
- .get(`/:property`, ({ params: { property }, set }) => {
|
|
|
|
|
- const data = Meteostanica.getDataPropertyMonthly(property, `2026-03`)
|
|
|
|
|
|
|
+ .get(`/:property`, ({ params: { property }, query: { day, month, year }, set }) => {
|
|
|
|
|
+ const dateMap = Meteostanica.getDateMap()
|
|
|
|
|
+
|
|
|
|
|
+ const years = Object.keys(dateMap)
|
|
|
|
|
+ const months = Object.keys(dateMap[years[years.length - 1]])
|
|
|
|
|
+ const days = dateMap[years[years.length - 1]][months[months.length - 1]]
|
|
|
|
|
+
|
|
|
|
|
+ const lastYear = years[years.length - 1]
|
|
|
|
|
+ const lastMonth = months[months.length - 1]
|
|
|
|
|
+ const lastDay = days[days.length - 1]
|
|
|
|
|
+
|
|
|
|
|
+ const data = Meteostanica.getDataPropertyDaily(property, `${year ?? lastYear}-${month ?? lastMonth}-${day ?? lastDay}`)
|
|
|
|
|
|
|
|
if (!data) {
|
|
if (!data) {
|
|
|
set.headers['content-type'] = 'text/html; charset=utf8'
|
|
set.headers['content-type'] = 'text/html; charset=utf8'
|
|
@@ -18,10 +28,20 @@ export default (langName, lang) => new Elysia({ prefix: `/history` })
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
set.headers['content-type'] = 'text/html; charset=utf8'
|
|
set.headers['content-type'] = 'text/html; charset=utf8'
|
|
|
- return eta.render(`${langName}/history/property`, { lang, property, data })
|
|
|
|
|
|
|
+ return eta.render(`${langName}/history/property`, { lang, dateMap: { years, months, days }, type: `daily`, property, data })
|
|
|
})
|
|
})
|
|
|
- .get(`/:property/daily`, ({ params: { property }, set }) => {
|
|
|
|
|
- const data = Meteostanica.getDataPropertyDaily(property, `2026-03-01`)
|
|
|
|
|
|
|
+ .get(`/:property/daily`, ({ params: { property }, query: { day, month, year }, set }) => {
|
|
|
|
|
+ const dateMap = Meteostanica.getDateMap()
|
|
|
|
|
+
|
|
|
|
|
+ const years = Object.keys(dateMap)
|
|
|
|
|
+ const months = Object.keys(dateMap[years[years.length - 1]])
|
|
|
|
|
+ const days = dateMap[years[years.length - 1]][months[months.length - 1]]
|
|
|
|
|
+
|
|
|
|
|
+ const lastYear = years[years.length - 1]
|
|
|
|
|
+ const lastMonth = months[months.length - 1]
|
|
|
|
|
+ const lastDay = days[days.length - 1]
|
|
|
|
|
+
|
|
|
|
|
+ const data = Meteostanica.getDataPropertyDaily(property, `${year ?? lastYear}-${month ?? lastMonth}-${day ?? lastDay}`)
|
|
|
|
|
|
|
|
if (!data) {
|
|
if (!data) {
|
|
|
set.headers['content-type'] = 'text/html; charset=utf8'
|
|
set.headers['content-type'] = 'text/html; charset=utf8'
|
|
@@ -29,10 +49,18 @@ export default (langName, lang) => new Elysia({ prefix: `/history` })
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
set.headers['content-type'] = 'text/html; charset=utf8'
|
|
set.headers['content-type'] = 'text/html; charset=utf8'
|
|
|
- return eta.render(`${langName}/history/property`, { lang, type: `daily`, property, data })
|
|
|
|
|
|
|
+ return eta.render(`${langName}/history/property`, { lang, dateMap: { years, months, days }, type: `daily`, property, data })
|
|
|
})
|
|
})
|
|
|
- .get(`/:property/monthly`, ({ params: { property }, set }) => {
|
|
|
|
|
- const data = Meteostanica.getDataPropertyMonthly(property, `2026-03`)
|
|
|
|
|
|
|
+ .get(`/:property/monthly`, ({ params: { property }, query: { month, year }, set }) => {
|
|
|
|
|
+ const dateMap = Meteostanica.getDateMap()
|
|
|
|
|
+
|
|
|
|
|
+ const years = Object.keys(dateMap)
|
|
|
|
|
+ const months = Object.keys(dateMap[years[years.length - 1]])
|
|
|
|
|
+
|
|
|
|
|
+ const lastYear = years[years.length - 1]
|
|
|
|
|
+ const lastMonth = months[months.length - 1]
|
|
|
|
|
+
|
|
|
|
|
+ const data = Meteostanica.getDataPropertyMonthly(property, `${year ?? lastYear}-${month ?? lastMonth}`)
|
|
|
|
|
|
|
|
if (!data) {
|
|
if (!data) {
|
|
|
set.headers['content-type'] = 'text/html; charset=utf8'
|
|
set.headers['content-type'] = 'text/html; charset=utf8'
|
|
@@ -40,10 +68,16 @@ export default (langName, lang) => new Elysia({ prefix: `/history` })
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
set.headers['content-type'] = 'text/html; charset=utf8'
|
|
set.headers['content-type'] = 'text/html; charset=utf8'
|
|
|
- return eta.render(`${langName}/history/property`, { lang, type: `monthly`, property, data })
|
|
|
|
|
|
|
+ return eta.render(`${langName}/history/property`, { lang, dateMap: { years, months }, type: `monthly`, property, data })
|
|
|
})
|
|
})
|
|
|
- .get(`/:property/yearly`, ({ params: { property }, set }) => {
|
|
|
|
|
- const data = Meteostanica.getDataPropertyYearly(property, `2026`)
|
|
|
|
|
|
|
+ .get(`/:property/yearly`, ({ params: { property }, query: { year }, set }) => {
|
|
|
|
|
+ const dateMap = Meteostanica.getDateMap()
|
|
|
|
|
+
|
|
|
|
|
+ const years = Object.keys(dateMap)
|
|
|
|
|
+
|
|
|
|
|
+ const lastYear = years[years.length - 1]
|
|
|
|
|
+
|
|
|
|
|
+ const data = Meteostanica.getDataPropertyYearly(property, year ?? lastYear)
|
|
|
|
|
|
|
|
if (!data) {
|
|
if (!data) {
|
|
|
set.headers['content-type'] = 'text/html; charset=utf8'
|
|
set.headers['content-type'] = 'text/html; charset=utf8'
|
|
@@ -51,10 +85,11 @@ export default (langName, lang) => new Elysia({ prefix: `/history` })
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
set.headers['content-type'] = 'text/html; charset=utf8'
|
|
set.headers['content-type'] = 'text/html; charset=utf8'
|
|
|
- return eta.render(`${langName}/history/property`, { lang, type: `yearly`, property, data })
|
|
|
|
|
|
|
+ return eta.render(`${langName}/history/property`, { lang, dateMap: { years }, type: `yearly`, property, data })
|
|
|
})
|
|
})
|
|
|
.get(`/:property/allTime`, ({ params: { property }, set }) => {
|
|
.get(`/:property/allTime`, ({ params: { property }, set }) => {
|
|
|
const data = Meteostanica.getDataPropertyAllTime(property)
|
|
const data = Meteostanica.getDataPropertyAllTime(property)
|
|
|
|
|
+ const dateMap = Meteostanica.getDateMap()
|
|
|
|
|
|
|
|
if (!data) {
|
|
if (!data) {
|
|
|
set.headers['content-type'] = 'text/html; charset=utf8'
|
|
set.headers['content-type'] = 'text/html; charset=utf8'
|
|
@@ -62,5 +97,5 @@ export default (langName, lang) => new Elysia({ prefix: `/history` })
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
set.headers['content-type'] = 'text/html; charset=utf8'
|
|
set.headers['content-type'] = 'text/html; charset=utf8'
|
|
|
- return eta.render(`${langName}/history/property`, { lang, type: `allTime`, property, data })
|
|
|
|
|
|
|
+ return eta.render(`${langName}/history/property`, { lang, dateMap, type: `allTime`, property, data })
|
|
|
})
|
|
})
|