-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathimgbb.el
53 lines (49 loc) · 1.55 KB
/
imgbb.el
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
;;; imgbb.el --- Simple image upload client for imgbb.com -*-coding: utf-8; -*-
;;
;; Copyright (C) 2018 [email protected]
;;
;; Author: Peter <[email protected]>
;; URL: https://github.com/ecraven/imgbb.el
;; Package-Version: 20180518
;; Package-Requires: ((emacs "24") (request "0.3.0"))
;; Version: 0.1
;; Keywords: extensions
;; Created: 2018-05-18
;;
;;; License:
;;
;; Licensed under the GPLv3.
;;
;;; Commentary:
;;
;; Run M-x imgbb-upload and enter an image filename. The URL of the uploaded image is shown in the minibuffer and put into the kill ring.
;;
;;; Code:
(require 'request)
(require 'cl-lib)
(defvar imgbb-url
"https://imgbb.com/json"
"The URL of the imgbb service.")
(defvar imgbb-parameters
'((type . "file")
(action . "upload"))
"Default parameters to send.")
;;;###autoload
(defun imgbb-upload (filename)
"Upload FILENAME to imgbb.com, show the image url and put it into the kill ring."
(interactive "fImage file: ")
(request imgbb-url
:params imgbb-parameters
:files `(("source" . (,(file-name-nondirectory filename) :file ,filename)))
:parser 'json-read
:error (cl-function
(lambda (&rest args &key error-thrown &allow-other-keys)
(message "Error uploading image.")))
:success (cl-function
(lambda (&key data &allow-other-keys)
(let ((url (assoc-default 'url (assoc-default 'image (assoc-default 'image data)))))
(message "%s" url)
(kill-new url)))))
(message "Started upload of %S to imgbb.com." filename))
(provide 'imgbb)
;;; imgbb.el ends here