smr/src/lua/endpoints/paste_get.lua

50 lines
1.3 KiB
Lua

local config = require("config")
local session = require("session")
local pages = require("pages")
local cache = require("cache")
local function paste_get(req)
--Get the paste page
local host = http_request_get_host(req)
local text
local author,_ = session.get(req)
if host == config.domain and author then
http_response_header(req,"Location",string.format("https://%s.%s/_paste",author,config.domain))
http_response(req,303,"")
return
elseif host == config.domain and author == nil then
print("doing anon paste")
text = cache.render(string.format("%s/_paste",host),function()
log(LOG_DEBUG, "Cache missing, rendering post page")
return assert(pages.paste{
domain = config.domain,
err = "",
})
end)
http_response(req,200,text)
elseif host ~= config.domain and author then
print("doing author paste")
text = assert(pages.author_paste{
domain = config.domain,
user = author,
err = "",
text="",
})
elseif host ~= config.domain and author == nil then
http_response_header(req,"Location",string.format("https://%s/_paste",config.domain))
http_response(req,303,"")
return
else
error(string.format(
"Unable to find a good case for paste:%s,%s,%s",
host,
config.domain,
author
))
end
assert(text)
http_response(req,200,text)
end
return paste_get