history.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { Elysia } from 'elysia'
  2. import { Eta } from "eta"
  3. import Meteostanica from '../../utils/meteostanica'
  4. const eta = new Eta({ views: "./templates" })
  5. export default (langName, lang) => new Elysia({ prefix: `/history` })
  6. .get('/', ({ set }) => {
  7. set.headers['content-type'] = 'text/html; charset=utf8'
  8. return eta.render(`${langName}/history/index`, { })
  9. })
  10. .get(`/:property`, ({ params: { property }, set }) => {
  11. const data = Meteostanica.getDataPropertyMonthly(property, `2026-03`)
  12. if (!data) {
  13. set.headers['content-type'] = 'text/html; charset=utf8'
  14. return eta.render(`${langName}/history/notFound`, { property })
  15. }
  16. set.headers['content-type'] = 'text/html; charset=utf8'
  17. return eta.render(`${langName}/history/property`, { lang, property, data })
  18. })
  19. .get(`/:property/daily`, ({ params: { property }, set }) => {
  20. const data = Meteostanica.getDataPropertyDaily(property, `2026-03-01`)
  21. if (!data) {
  22. set.headers['content-type'] = 'text/html; charset=utf8'
  23. return eta.render(`${langName}/history/notFound`, { property })
  24. }
  25. set.headers['content-type'] = 'text/html; charset=utf8'
  26. return eta.render(`${langName}/history/property`, { lang, type: `daily`, property, data })
  27. })
  28. .get(`/:property/monthly`, ({ params: { property }, set }) => {
  29. const data = Meteostanica.getDataPropertyMonthly(property, `2026-03`)
  30. if (!data) {
  31. set.headers['content-type'] = 'text/html; charset=utf8'
  32. return eta.render(`${langName}/history/notFound`, { property })
  33. }
  34. set.headers['content-type'] = 'text/html; charset=utf8'
  35. return eta.render(`${langName}/history/property`, { lang, type: `monthly`, property, data })
  36. })
  37. .get(`/:property/yearly`, ({ params: { property }, set }) => {
  38. const data = Meteostanica.getDataPropertyYearly(property, `2026`)
  39. if (!data) {
  40. set.headers['content-type'] = 'text/html; charset=utf8'
  41. return eta.render(`${langName}/history/notFound`, { property })
  42. }
  43. set.headers['content-type'] = 'text/html; charset=utf8'
  44. return eta.render(`${langName}/history/property`, { lang, type: `yearly`, property, data })
  45. })
  46. .get(`/:property/allTime`, ({ params: { property }, set }) => {
  47. const data = Meteostanica.getDataPropertyAllTime(property)
  48. if (!data) {
  49. set.headers['content-type'] = 'text/html; charset=utf8'
  50. return eta.render(`${langName}/history/notFound`, { property })
  51. }
  52. set.headers['content-type'] = 'text/html; charset=utf8'
  53. return eta.render(`${langName}/history/property`, { lang, type: `allTime`, property, data })
  54. })