add initialization callback for filters
This commit is contained in:
parent
eefdecb1e9
commit
a747fe8182
2 changed files with 21 additions and 19 deletions
|
@ -1,24 +1,23 @@
|
|||
function webfingerCallback(cfg)
|
||||
function webfingerInit(cfg)
|
||||
local accounts_set = {}
|
||||
for _, account in ipairs(cfg.accounts) do
|
||||
accounts_set["acct:" .. account] = true
|
||||
end
|
||||
return accounts_set
|
||||
end
|
||||
|
||||
function webfingerCallback(cfg, accounts_set)
|
||||
local args, err = ngx.req.get_uri_args()
|
||||
if err == "truncated" then
|
||||
return false, 'uri args too long'
|
||||
return 400, 'uri args too long'
|
||||
end
|
||||
|
||||
local resource = args['resource']
|
||||
if resource ~= nil then
|
||||
-- TODO this is O(n) but we can make it O(1) by doing a funny and making
|
||||
-- cfg.accounts be transformed into keys in a table
|
||||
--
|
||||
-- this would require us to do some setup() callback as well as
|
||||
-- the request() callback
|
||||
for _, account in ipairs(cfg.accounts) do
|
||||
if resource == account then
|
||||
return true
|
||||
end
|
||||
end
|
||||
if accounts_set[resource] then
|
||||
return nil
|
||||
else
|
||||
return 404, "Couldn't find user"
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
return {
|
||||
|
@ -32,6 +31,7 @@ return {
|
|||
Useful for small instances.
|
||||
]],
|
||||
apiVersion=1,
|
||||
init=webfingerInit,
|
||||
callbacks = {
|
||||
['/.well-known/webfinger'] = webfingerCallback
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue