mirror of
https://notabug.org/scuti/pleroma-comments
synced 2025-01-20 18:12:42 +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
|
return tokens
|
||||||
end
|
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)
|
||||||
print("http/s GET: ".. link)
|
print("http/s GET: ".. link)
|
||||||
local filename = filename or nil
|
local filename = filename or nil
|
||||||
local args = {}
|
local args = {}
|
||||||
if filename then
|
if filename then -- when requesting avatars
|
||||||
args = {
|
args = {
|
||||||
"--timeout=10",
|
"--timeout=10",
|
||||||
"-qO",
|
"-qO",
|
||||||
filename,
|
filename,
|
||||||
link
|
link
|
||||||
}
|
}
|
||||||
else
|
else -- when requesting json
|
||||||
args = {
|
args = {
|
||||||
"-qO-",
|
"-qO-",
|
||||||
"--timeout=10",
|
"--timeout=10",
|
||||||
link
|
link
|
||||||
}
|
}
|
||||||
end
|
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, ' ')
|
local command = "wget " .. table.concat(args, ' ')
|
||||||
|
print(command)
|
||||||
local success, retval = pcall(
|
local success, retval = pcall(
|
||||||
function ()
|
function ()
|
||||||
-- print("!: ".. table.concat(args))
|
local handle = io.popen(command)
|
||||||
return pandoc.pipe("wget", args, "")
|
local result = handle:read("*a")
|
||||||
|
handle:close()
|
||||||
|
return result
|
||||||
|
|
||||||
|
-- couldn't get pandoc.pipe() send headers'
|
||||||
|
-- return pandoc.pipe("wget", args, "")
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
if not success then
|
if not success then
|
||||||
print("warning: error while performing http/s GET")
|
print("warning: error while performing http/s GET")
|
||||||
print(retval)
|
print("\treturned: " .. tostring(retval))
|
||||||
end
|
end
|
||||||
return retval
|
return retval
|
||||||
end
|
end
|
||||||
@ -330,8 +369,19 @@ end
|
|||||||
|
|
||||||
function get_status(host, post_id)
|
function get_status(host, post_id)
|
||||||
local url = "https://" .. host .. "/api/v1/statuses/" .. post_id
|
local url = "https://" .. host .. "/api/v1/statuses/" .. post_id
|
||||||
-- print(url)
|
local success, retval = pcall(
|
||||||
return json.decode(get(url))
|
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
|
end
|
||||||
|
|
||||||
function get_replies(host, id)
|
function get_replies(host, id)
|
||||||
@ -382,7 +432,6 @@ function Meta(meta)
|
|||||||
-- if pleroma_avatar_save_path and pleroma_avatar_path then
|
-- if pleroma_avatar_save_path and pleroma_avatar_path then
|
||||||
-- is_hotlink = false
|
-- is_hotlink = false
|
||||||
-- end
|
-- end
|
||||||
|
|
||||||
local all_replies = {}
|
local all_replies = {}
|
||||||
local hrefs = {}
|
local hrefs = {}
|
||||||
local host = ""
|
local host = ""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user