From 040242c9be4ca1fe6d22501e48c13e6c30637d31 Mon Sep 17 00:00:00 2001 From: David Peter Date: Sun, 29 May 2022 20:57:08 +0200 Subject: [PATCH] Add initial version of curl plugin --- plugins/curl.lua | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 plugins/curl.lua diff --git a/plugins/curl.lua b/plugins/curl.lua new file mode 100644 index 00000000..6f3c3db0 --- /dev/null +++ b/plugins/curl.lua @@ -0,0 +1,21 @@ +function tempdir() + local stream = assert(io.popen('mktemp --directory')) + local output = stream:read('*all') + stream:close() + return string.gsub(output, "\n", "") +end + +function preprocess(path_or_url) + filename_from_url = string.match(path_or_url, '^https?://.*/(.*)$') + if filename_from_url then + local temp_directory = tempdir() + local new_path = temp_directory .. "/" .. filename_from_url + + -- TODO: how to prevent shell injection bugs? + os.execute("curl --silent '" .. path_or_url .. "' --output '" .. new_path .. "'") + + return new_path + else + return path_or_url + end +end