2020-12-21 05:22:22 +01:00
|
|
|
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
|
2021-01-11 04:34:22 +01:00
|
|
|
print("doing anon paste")
|
2020-12-21 05:22:22 +01:00
|
|
|
text = cache.render(string.format("%s/_paste",host),function()
|
2020-12-23 07:02:02 +01:00
|
|
|
log(LOG_DEBUG, "Cache missing, rendering post page")
|
2021-01-04 03:48:29 +01:00
|
|
|
return assert(pages.paste{
|
2020-12-21 05:22:22 +01:00
|
|
|
domain = config.domain,
|
|
|
|
err = "",
|
2021-02-14 08:30:20 +01:00
|
|
|
extra_load = {
|
|
|
|
'<script src="/_js/suggest_tags.js"></script>'
|
|
|
|
}
|
2021-01-04 03:48:29 +01:00
|
|
|
})
|
2020-12-21 05:22:22 +01:00
|
|
|
end)
|
|
|
|
http_response(req,200,text)
|
|
|
|
elseif host ~= config.domain and author then
|
2021-01-11 04:34:22 +01:00
|
|
|
print("doing author paste")
|
2021-01-04 03:48:29 +01:00
|
|
|
text = assert(pages.author_paste{
|
2020-12-21 05:22:22 +01:00
|
|
|
domain = config.domain,
|
|
|
|
user = author,
|
|
|
|
err = "",
|
|
|
|
text="",
|
2021-02-14 08:30:20 +01:00
|
|
|
extra_load = {
|
|
|
|
'<script src="/_js/suggest_tags.js"></script>'
|
|
|
|
}
|
2021-01-04 03:48:29 +01:00
|
|
|
})
|
2020-12-21 05:22:22 +01:00
|
|
|
elseif host ~= config.domain and author == nil then
|
|
|
|
http_response_header(req,"Location",string.format("https://%s/_paste",config.domain))
|
|
|
|
http_response(req,303,"")
|
2021-01-04 03:48:29 +01:00
|
|
|
return
|
2020-12-21 05:22:22 +01:00
|
|
|
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
|