forked from sloria/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 3
/
imgur.lua
25 lines (21 loc) · 892 Bytes
/
imgur.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
-- imgur upload from pasteboard
hs.hotkey.bind(hyper, "u", function()
local image = hs.pasteboard.readImage()
if image then
local tempfile = "/tmp/tmp.png"
image:saveToFile(tempfile)
local b64 = hs.execute("base64 -i "..tempfile)
b64 = hs.http.encodeForQuery(string.gsub(b64, "\n", ""))
local url = "https://api.imgur.com/3/upload.json"
local headers = {Authorization = "Client-ID "..hs.settings.get("imgurKey")}
local payload = "type='base64'&image="..b64
hs.http.asyncPost(url, payload, headers, function(status, body, headers)
print(status, headers, body)
if status == 200 then
local response = hs.json.decode(body)
local imageURL = response.data.link
hs.urlevent.openURLWithBundle(imageURL, hs.urlevent.getDefaultHandler("http"))
end
end)
end
end)