mirror of
https://notabug.org/scuti/pleroma-comments
synced 2025-01-03 16:41:45 +05:30
support auth with multiple instances
This commit is contained in:
parent
17c5474f06
commit
43115f1a42
@ -10,7 +10,8 @@ pleroma_avatar_save_path = nil
|
||||
pleroma_avatar_path = nil
|
||||
|
||||
-- instances may require auth to access api
|
||||
-- pleroma_auth_token = nil
|
||||
-- pleroma_auth = {}
|
||||
-- pleroma_auth["instance.tld"] = "your_auth_key"
|
||||
|
||||
pcall(
|
||||
function ()
|
||||
@ -59,34 +60,12 @@ function tokenizeString(inputString, delimiter)
|
||||
return tokens
|
||||
end
|
||||
|
||||
-- function get(link)
|
||||
-- print("http/s GET: ".. link)
|
||||
-- local args = {link}
|
||||
--
|
||||
-- if pleroma_auth_token then
|
||||
-- local auth = string.format(
|
||||
-- "\'Authorization: Bearer %s\' ", pleroma_auth_token)
|
||||
-- table.insert(args, 1, "-H")
|
||||
-- table.insert(args, 2, auth)
|
||||
-- end
|
||||
--
|
||||
-- local command = "curl " .. table.concat(args, ' ')
|
||||
-- print(command)
|
||||
-- local success, retval = pcall(
|
||||
-- function ()
|
||||
-- return pandoc.pipe("curl", args, "")
|
||||
-- end
|
||||
-- )
|
||||
-- if not success then
|
||||
-- print("warning: error while performing http/s GET")
|
||||
-- print("\treturned: " .. tostring(retval))
|
||||
-- end
|
||||
-- return retval
|
||||
-- end
|
||||
|
||||
function get(link, filename)
|
||||
function get(link, filename, auth)
|
||||
print("http/s GET: ".. link)
|
||||
|
||||
local filename = filename or nil
|
||||
local auth = auth or nil
|
||||
|
||||
local args = {}
|
||||
if filename then -- when requesting avatars
|
||||
args = {
|
||||
@ -105,10 +84,10 @@ function get(link, filename)
|
||||
-- don't use auth bearer for downloading images'
|
||||
-- its either not needed OR
|
||||
-- there should be an extra check on the host
|
||||
if pleroma_auth_token and not filename then
|
||||
if auth and not filename then
|
||||
local h = "--header=\"Authorization: Bearer %s\" "
|
||||
table.insert(
|
||||
args, 1, string.format(h, pleroma_auth_token)
|
||||
args, 1, string.format(h, auth)
|
||||
)
|
||||
end
|
||||
|
||||
@ -374,11 +353,11 @@ function get_url_from_pandoc_str(pandoc_str)
|
||||
return link, host, id
|
||||
end
|
||||
|
||||
function get_status(host, post_id)
|
||||
function get_status(host, post_id, auth)
|
||||
local url = "https://" .. host .. "/api/v1/statuses/" .. post_id
|
||||
local success, retval = pcall(
|
||||
function ()
|
||||
local got = get(url)
|
||||
local got = get(url, nil, auth)
|
||||
-- print(got)
|
||||
return json.decode(got)
|
||||
end
|
||||
@ -391,10 +370,10 @@ function get_status(host, post_id)
|
||||
return retval
|
||||
end
|
||||
|
||||
function get_replies(host, id)
|
||||
function get_replies(host, id, auth)
|
||||
local url = "https://" .. host .. "/api/v1/statuses/" .. id .. "/context"
|
||||
-- print(url)
|
||||
local got = json.decode(get(url))
|
||||
local got = json.decode(get(url, nil, auth))
|
||||
return got["descendants"]
|
||||
end
|
||||
|
||||
@ -458,9 +437,13 @@ function Meta(meta)
|
||||
{link = reply_href, id = id}
|
||||
)
|
||||
|
||||
local op = get_status(host, id)
|
||||
local auth_key = nil
|
||||
if pleroma_auth[host] then
|
||||
auth_key = pleroma_auth[host]
|
||||
end
|
||||
local op = get_status(host, id, auth_key)
|
||||
table.insert(all_replies, op)
|
||||
local replies = get_replies(host, id)
|
||||
local replies = get_replies(host, id, auth_key)
|
||||
combine_tables(all_replies, replies)
|
||||
end
|
||||
table.sort(all_replies,
|
||||
@ -483,5 +466,3 @@ function Meta(meta)
|
||||
meta["pleroma"] = hrefs
|
||||
return meta
|
||||
end
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user