mirror of
https://notabug.org/scuti/pleroma-comments
synced 2025-01-03 16:41:45 +05:30
can fetch from auth-required instance
This commit is contained in:
parent
c4cd40a0de
commit
149c46cf51
@ -54,34 +54,73 @@ 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)
|
||||
print("http/s GET: ".. link)
|
||||
local filename = filename or nil
|
||||
local args = {}
|
||||
if filename then
|
||||
if filename then -- when requesting avatars
|
||||
args = {
|
||||
"--timeout=10",
|
||||
"-qO",
|
||||
filename,
|
||||
link
|
||||
}
|
||||
else
|
||||
else -- when requesting json
|
||||
args = {
|
||||
"-qO-",
|
||||
"--timeout=10",
|
||||
link
|
||||
}
|
||||
end
|
||||
-- don't use auth bearer for downloading images'
|
||||
if pleroma_auth_token and not filename then
|
||||
local h = "--header=\"Authorization: Bearer %s\" "
|
||||
table.insert(
|
||||
args, 1, string.format(h, pleroma_auth_token)
|
||||
)
|
||||
end
|
||||
|
||||
local command = "wget " .. table.concat(args, ' ')
|
||||
print(command)
|
||||
local success, retval = pcall(
|
||||
function ()
|
||||
-- print("!: ".. table.concat(args))
|
||||
return pandoc.pipe("wget", args, "")
|
||||
local handle = io.popen(command)
|
||||
local result = handle:read("*a")
|
||||
handle:close()
|
||||
return result
|
||||
|
||||
-- couldn't get pandoc.pipe() send headers'
|
||||
-- return pandoc.pipe("wget", args, "")
|
||||
end
|
||||
)
|
||||
if not success then
|
||||
print("warning: error while performing http/s GET")
|
||||
print(retval)
|
||||
print("\treturned: " .. tostring(retval))
|
||||
end
|
||||
return retval
|
||||
end
|
||||
@ -330,8 +369,19 @@ end
|
||||
|
||||
function get_status(host, post_id)
|
||||
local url = "https://" .. host .. "/api/v1/statuses/" .. post_id
|
||||
-- print(url)
|
||||
return json.decode(get(url))
|
||||
local success, retval = pcall(
|
||||
function ()
|
||||
local got = get(url)
|
||||
-- print(got)
|
||||
return json.decode(got)
|
||||
end
|
||||
)
|
||||
-- if an error occurred in retrieving a status
|
||||
-- it will cause errors in write_comments
|
||||
--consider skipping over statuses later
|
||||
assert(success)
|
||||
assert(not retval["error"])
|
||||
return retval
|
||||
end
|
||||
|
||||
function get_replies(host, id)
|
||||
@ -382,7 +432,6 @@ function Meta(meta)
|
||||
-- if pleroma_avatar_save_path and pleroma_avatar_path then
|
||||
-- is_hotlink = false
|
||||
-- end
|
||||
|
||||
local all_replies = {}
|
||||
local hrefs = {}
|
||||
local host = ""
|
||||
|
Loading…
Reference in New Issue
Block a user