-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.lua
29 lines (27 loc) · 917 Bytes
/
index.lua
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
-- Adapted from
-- https://rpdillon.net/redbean-tiddlywiki-saver.html
-- and
-- https://gist.github.com/coderofsalvation/f9e22cef04222bca03f7bc342b2a0a2c
method = GetMethod()
if method == "GET" then
ServeAsset(WIKI_PATH)
elseif method == "HEAD" then
wiki = LoadAsset(WIKI_PATH)
SetStatus(200)
SetHeader("Content-Type", "text/html")
SetHeader("Content-Length", tostring(#wiki))
elseif method == "OPTIONS" then
SetStatus(200)
SetHeader("Allow", "GET,HEAD,POST,OPTIONS,CONNECT,PUT,DAV,dav")
SetHeader("x-api-access-type", "file")
SetHeader("dav", "tw5/put")
elseif method == "PUT" then
length = tonumber(GetHeader("Content-Length"))
if GetHostOs() == "WINDOWS" then
local ok, err = Barf(WIKI_PATH, GetBody())
if err then printf("could not save:", err) end
else
StoreAsset(WIKI_PATH, GetBody())
end
SetStatus(204, "No Content")
end