Merge pull request #1 from ayes-web/catbox-linux-mac

Add linux and macos support
This commit is contained in:
Alexander Thoren 2023-06-19 05:37:29 -07:00 committed by GitHub
commit d49c404816
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -455,7 +455,6 @@ function main_menu:upload_litterbox()
function(outfile)
notify("Uploading to " .. (config.litterbox and "litterbox.catbox.moe..." or "catbox.moe..."), "info", 9999)
if os_type == 'windows' then
-- This uses cURL to send a request to the cat-/litterbox API.
-- (cURL is included with Windows 10 and up)
@ -465,13 +464,14 @@ function main_menu:upload_litterbox()
capture_stdout = true,
capture_stderr = true,
args = {
'curl.exe', '-s',
os_type == 'window' and 'curl.exe' or 'curl', '-s',
'-F', 'reqtype=fileupload',
'-F', 'time=' .. config['litterbox_expire'],
'-F', 'fileToUpload=@"' .. outfile .. '"',
endpoint
}
})
-- This really only happens for people that should have upgraded their system years ago.
-- Or people running a minimal installation i guess.
if r.status == -3 then
@ -484,16 +484,25 @@ function main_menu:upload_litterbox()
end
-- Copy to clipboard
print(r.stdout)
if os_type == 'windows' then
local clipboard_command = 'powershell -command "Set-Clipboard -Value ' .. r.stdout .. '"'
mp.command('run ' .. clipboard_command)
end
if os_type == 'macos' then
notify("Not yet implemented for macOS.", "error", 2)
local clipboard_command = 'echo ' .. r.stdout .. ' | pbcopy'
mp.command("run /bin/sh -c \"" .. clipboard_command .. "\"")
end
if os_type == 'linux' then
notify("Not yet implemented for Linux.", "error", 2)
if os_type == "linux" then
local session_type = io.popen('/bin/sh -c "echo $XDG_SESSION_TYPE"'):read("*a")
-- wl-copy is from wl-clipboard
local clipboard_command = session_type == "x11\n" and
"/bin/sh -c \"echo " .. r.stdout .. "| xclip -sel clip\"" or
"wl-copy " .. r.stdout
mp.command('run ' .. clipboard_command)
end
notify("Done! Copied URL to clipboard.", "info", 2)