62 lines
1.8 KiB
Lua
62 lines
1.8 KiB
Lua
local lapis = require("lapis")
|
|
local app = lapis.Application()
|
|
|
|
local config = require("lapis.config").get()
|
|
|
|
members = {{"fynn","https://fynngodau.de"},
|
|
{"anton","https://anton.ehrmanntraut.de"},
|
|
{"max","https://aaahhh.de"},
|
|
{"cups",config.host}}
|
|
members[#members+1] = members[1]
|
|
|
|
math.randomseed(os.time())
|
|
|
|
app:get("/", function()
|
|
return 'Welcome to the CUPS (Cool Unique People System) webring </br> <embed type="text/html" src="' .. config.host .. '/embed?from=cups" style="width:350px;">'
|
|
end)
|
|
|
|
app:get("/embed", function(self)
|
|
local from = self.params.from
|
|
if from == nil then
|
|
return {"cups webring embed needs from defined (.../embed?from=me)"}
|
|
end
|
|
return string.format('<div style="display:flex; flex-direction:row; align-items:center;"><a href="%s/prev?from=%s" target="_parent"><img src="%s/static/arrow_left.svg" width=50 height=50/></a><img src="%s/static/logo_cut.svg" width=200 height=100/><a href="%s/next?from=%s" target="_parent"><img src="%s/static/arrow_right.svg" width=50 height=50/></a></div>', config.host, from, config.host, config.host, config.host, from, config.host), {layout = false, content_type="text/html"}
|
|
end)
|
|
|
|
app:get("/random", function(self)
|
|
rand = math.random(1,#members-1)
|
|
return {redirect_to=members[rand][2]}
|
|
end)
|
|
|
|
app:get("/next", function(self)
|
|
local found
|
|
for _, elem in ipairs(members) do
|
|
local name = elem[1]
|
|
local url = elem[2]
|
|
if found == true then
|
|
return {redirect_to=url}
|
|
end
|
|
if name == self.params.from then
|
|
found = true
|
|
end
|
|
end
|
|
return {redirect_to="/"}
|
|
end)
|
|
|
|
|
|
app:get("/prev", function(self)
|
|
local found
|
|
for i=#members, 1, -1 do
|
|
local name = members[i][1]
|
|
local url = members[i][2]
|
|
if found == true then
|
|
return {redirect_to=url}
|
|
end
|
|
if name == self.params.from then
|
|
found = true
|
|
end
|
|
end
|
|
return {redirect_to="/"}
|
|
end)
|
|
|
|
return app
|