Start working on addon api.

This commit is contained in:
Robin Malley 2023-02-20 02:39:42 +00:00
parent 4514a42cfc
commit 87bccb959d
4 changed files with 39 additions and 8 deletions

View File

@ -7,6 +7,7 @@ local db = require("db")
local queries = require("queries")
local sql = require("lsqlite3")
local cache = require("cache")
local api = require("hooks")
local oldconfigure = configure
local stmnt_delete
@ -15,6 +16,18 @@ function configure(...)
return oldconfigure(...)
end
local oldspec = api.get.page_owner
function api.get.page_owner = function(env)
local ret = oldspec()
table.insert(oldret,{
endpoint = string.format("https://%s/_delete",env.domain),
method = "POST",
fields = {story = env.short},
text = "Delete"
})
return ret
end
local function delete_post(req)
local host = http_request_get_host(req)
local path = http_request_get_path(req)

View File

@ -8,6 +8,7 @@ local pages = require("pages")
local tags = require("tags")
local session = require("session")
local config = require("config")
local api = require("hooks")
local stmnt_edit
local oldconfigure = configure
@ -16,6 +17,18 @@ function configure(...)
return oldconfigure(...)
end
local oldspec = api.get.page_owner
function api.get.page_owner = function(env)
local ret = oldspec()
table.insert(oldret,{
endpoint = string.format("https://%s/_edit",env.domain),
method = "GET",
fields = {story = env.short},
text = "Edit"
})
return ret
end
local function edit_get(req)
local host = http_request_get_host(req)
local path = http_request_get_path(req)

View File

@ -10,6 +10,7 @@ print("Really fast print from init.lua")
local et = require("etlua")
local sql = require("lsqlite3")
local zlib = require("zlib")
local api = require("hooks")
--stubs for detouring
function configure(...) end
@ -105,7 +106,9 @@ for funcname, spec in pairs({
else
log(LOG_DEBUG,string.format("Endpoint %s called with method %s",funcname,method))
end
api.pre_request(req)
spec[method](req)
api.post_request(req)
end
log(LOG_INFO,string.format("Associateing endpoint %q", funcname))
end
@ -118,7 +121,9 @@ function teardown()
if cache then
cache.close()
end
api.worker_shutdown()
print("Finished lua teardown")
end
api.worker_init()
print("Done with init.lua")

View File

@ -4,14 +4,14 @@
</nav>
<% if owner then -%>
<div class="row">
<form action="https://<%= domain %>/_edit" method="get"><fieldset>
<input type="hidden" name="story" value="<%= short %>"/>
<input type="submit" value="edit" class="button column column-0"/>
</fieldset></form>
<form action="https://<%= domain %>/_delete" method="post"><fieldset>
<input type="hidden" name="story" value="<%= short %>"/>
<input type="submit" value="delete" class="button column column-0"/>
<% for _, spec in ipairs(api.get.page_owner(_ENV)) do %>
<form action="<%= spec.endpoint %>" method="<%= spec.method %=>"><fieldset>
<% for key, value in pairs(spec.fields) %>
<input type="hidden" name="<%= key %>" value="<%= value %>"/>
<% end %>
<input type="submit" value="<%= spec.text %>" class="button column column-0"/>
</fieldset></form>
<% end %>
</div>
<% end -%>
<article>