30
|
1 local Luan = require "luan:Luan.luan"
|
|
2 local error = Luan.error
|
|
3 local String = require "luan:String.luan"
|
|
4 local to_number = String.to_number or error()
|
73
|
5 local Parsers = require "luan:Parsers.luan"
|
|
6 local json_string = Parsers.json_string or error()
|
30
|
7 local Time = require "luan:Time.luan"
|
|
8 local time_now = Time.now or error()
|
|
9 local Io = require "luan:Io.luan"
|
|
10 local Http = require "luan:http/Http.luan"
|
|
11 local User = require "site:/lib/User.luan"
|
|
12 local current_user = User.current or error()
|
33
|
13 local Shared = require "site:/lib/Shared.luan"
|
73
|
14 local compressed = Shared.compressed or error()
|
|
15 local Online = require "site:/lib/Online.luan"
|
|
16 local set_online = Online.set or error()
|
|
17 local get_online = Online.get or error()
|
30
|
18 local Logging = require "luan:logging/Logging.luan"
|
|
19 local logger = Logging.logger "heartbeat.js"
|
|
20
|
|
21
|
|
22 return function()
|
33
|
23 local user = current_user() or error()
|
73
|
24 set_online(user)
|
|
25 Io.stdout = Http.response.text_writer()
|
33
|
26
|
30
|
27 local last_update = Http.request.parameters.last_update or error()
|
46
|
28 last_update = to_number(last_update) or error(last_update)
|
30
|
29 local user_last_update = user.last_update()
|
73
|
30 if time_now() - user_last_update > 70000 and last_update < user_last_update then
|
|
31 logger.info "update"
|
|
32 %>
|
|
33 location = '/';
|
|
34 <%
|
30
|
35 return
|
|
36 end
|
73
|
37
|
|
38 local online = get_online(user)
|
30
|
39 %>
|
73
|
40 online = <%=json_string(online,compressed)%>;
|
|
41 showOnline();
|
30
|
42 <%
|
|
43 end
|