Start working on addon api.
This commit is contained in:
parent
4514a42cfc
commit
87bccb959d
|
@ -7,6 +7,7 @@ local db = require("db")
|
||||||
local queries = require("queries")
|
local queries = require("queries")
|
||||||
local sql = require("lsqlite3")
|
local sql = require("lsqlite3")
|
||||||
local cache = require("cache")
|
local cache = require("cache")
|
||||||
|
local api = require("hooks")
|
||||||
|
|
||||||
local oldconfigure = configure
|
local oldconfigure = configure
|
||||||
local stmnt_delete
|
local stmnt_delete
|
||||||
|
@ -15,6 +16,18 @@ function configure(...)
|
||||||
return oldconfigure(...)
|
return oldconfigure(...)
|
||||||
end
|
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 function delete_post(req)
|
||||||
local host = http_request_get_host(req)
|
local host = http_request_get_host(req)
|
||||||
local path = http_request_get_path(req)
|
local path = http_request_get_path(req)
|
||||||
|
|
|
@ -8,6 +8,7 @@ local pages = require("pages")
|
||||||
local tags = require("tags")
|
local tags = require("tags")
|
||||||
local session = require("session")
|
local session = require("session")
|
||||||
local config = require("config")
|
local config = require("config")
|
||||||
|
local api = require("hooks")
|
||||||
|
|
||||||
local stmnt_edit
|
local stmnt_edit
|
||||||
local oldconfigure = configure
|
local oldconfigure = configure
|
||||||
|
@ -16,6 +17,18 @@ function configure(...)
|
||||||
return oldconfigure(...)
|
return oldconfigure(...)
|
||||||
end
|
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 function edit_get(req)
|
||||||
local host = http_request_get_host(req)
|
local host = http_request_get_host(req)
|
||||||
local path = http_request_get_path(req)
|
local path = http_request_get_path(req)
|
||||||
|
|
|
@ -10,6 +10,7 @@ print("Really fast print from init.lua")
|
||||||
local et = require("etlua")
|
local et = require("etlua")
|
||||||
local sql = require("lsqlite3")
|
local sql = require("lsqlite3")
|
||||||
local zlib = require("zlib")
|
local zlib = require("zlib")
|
||||||
|
local api = require("hooks")
|
||||||
|
|
||||||
--stubs for detouring
|
--stubs for detouring
|
||||||
function configure(...) end
|
function configure(...) end
|
||||||
|
@ -105,7 +106,9 @@ for funcname, spec in pairs({
|
||||||
else
|
else
|
||||||
log(LOG_DEBUG,string.format("Endpoint %s called with method %s",funcname,method))
|
log(LOG_DEBUG,string.format("Endpoint %s called with method %s",funcname,method))
|
||||||
end
|
end
|
||||||
|
api.pre_request(req)
|
||||||
spec[method](req)
|
spec[method](req)
|
||||||
|
api.post_request(req)
|
||||||
end
|
end
|
||||||
log(LOG_INFO,string.format("Associateing endpoint %q", funcname))
|
log(LOG_INFO,string.format("Associateing endpoint %q", funcname))
|
||||||
end
|
end
|
||||||
|
@ -118,7 +121,9 @@ function teardown()
|
||||||
if cache then
|
if cache then
|
||||||
cache.close()
|
cache.close()
|
||||||
end
|
end
|
||||||
|
api.worker_shutdown()
|
||||||
print("Finished lua teardown")
|
print("Finished lua teardown")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
api.worker_init()
|
||||||
print("Done with init.lua")
|
print("Done with init.lua")
|
||||||
|
|
|
@ -4,14 +4,14 @@
|
||||||
</nav>
|
</nav>
|
||||||
<% if owner then -%>
|
<% if owner then -%>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<form action="https://<%= domain %>/_edit" method="get"><fieldset>
|
<% for _, spec in ipairs(api.get.page_owner(_ENV)) do %>
|
||||||
<input type="hidden" name="story" value="<%= short %>"/>
|
<form action="<%= spec.endpoint %>" method="<%= spec.method %=>"><fieldset>
|
||||||
<input type="submit" value="edit" class="button column column-0"/>
|
<% for key, value in pairs(spec.fields) %>
|
||||||
</fieldset></form>
|
<input type="hidden" name="<%= key %>" value="<%= value %>"/>
|
||||||
<form action="https://<%= domain %>/_delete" method="post"><fieldset>
|
<% end %>
|
||||||
<input type="hidden" name="story" value="<%= short %>"/>
|
<input type="submit" value="<%= spec.text %>" class="button column column-0"/>
|
||||||
<input type="submit" value="delete" class="button column column-0"/>
|
</fieldset></form>
|
||||||
</fieldset></form>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
<% end -%>
|
<% end -%>
|
||||||
<article>
|
<article>
|
||||||
|
|
Loading…
Reference in New Issue