1
0
forked from Tank/braga
braga/front/cellar.lua
2026-03-08 21:18:45 +00:00

32 lines
871 B
Lua

local template = require "resty.template"
local handle = require('framework.handle')
local sensors = require('database.sensors')
local function resp(start,ends)
local view = template.new("climate.html", "layout.html")
view.start = start
view.ends = ends
view.title = "Микроклимат подвала"
view.data = sensors.cellar.data(start,ends)
view.cellar = sensors.cellar.now()
view.room = sensors.room.now()
view.weather = sensors.weather.now()
view:render()
end
local request = {
POST = function()
ngx.req.read_body()
local args, err = ngx.req.get_post_args()
resp(string.match(args['datetimes'], "([%d-%s:]+)%s>%s([%d-%s:]+)"))
end,
GET = function()
local ends = os.date('%Y-%m-%d %H:%M:%S',os.time()+14400)
local start = os.date('%Y-%m-%d %H:%M:%S',os.time()-86400)
resp(start,ends)
end
}
ngx.say(handle(request))