forked from PVNFU-28/picochan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpico_json
executable file
·47 lines (40 loc) · 1.45 KB
/
pico_json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/local/bin/haserl
<% -- Picochan JSON Frontend
-- HAPAS ARE SUPERIOR TO WHITES
local cgi = require("picoaux.cgi");
local json = require("picoaux.cjson");
local pico = require("picoengine");
cgi.initialize();
cgi.headers["Content-Type"] = "application/json; charset=utf-8";
cgi.headers["Cache-Control"] = "no-cache";
if cgi.pathinfo[1] == nil or cgi.pathinfo[1] == "" then
cgi.outputbuf = {json.encode{
sitename = pico.global.get("sitename"),
frontpage = pico.global.get("frontpage"),
defaultpostname = pico.global.get("defaultpostname"),
boards = pico.board.list()
}};
elseif cgi.pathinfo[1] == "Overboard" then
cgi.outputbuf = {json.encode(pico.board.overboard())};
elseif cgi.pathinfo[1] == "Recent" then
cgi.outputbuf = {json.encode(pico.post.recent(tonumber(cgi.pathinfo[2]) or 1))};
else
if not pico.board.exists(cgi.pathinfo[1]) then
cgi.headers["Status"] = "404 Not Found";
cgi.finalize();
end
if cgi.pathinfo[2] == nil or cgi.pathinfo[2] == "" or cgi.pathinfo[2] == "catalog" then
cgi.outputbuf = {json.encode(pico.board.catalog(cgi.pathinfo[1]))};
elseif cgi.pathinfo[2] == "index" then
cgi.outputbuf = {json.encode(pico.board.index(cgi.pathinfo[1]))};
else
local thread_tbl = pico.post.thread(cgi.pathinfo[1], cgi.pathinfo[2]);
if not thread_tbl then
cgi.headers["Status"] = "404 Not Found";
cgi.finalize();
end
cgi.outputbuf = {json.encode(thread_tbl)};
end
end
cgi.finalize();
%>