Skip to content

Commit

Permalink
fix: image uploading from gravatar (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
Artawower committed Sep 30, 2023
1 parent 023b1ac commit 4b70b65
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions blamer.el
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
;; Author: Artur Yaroshenko <artawower@protonmail.com>
;; URL: https://github.com/artawower/blamer.el
;; Package-Requires: ((emacs "27.1") (posframe "1.1.7"))
;; Version: 0.7.2
;; Version: 0.7.3

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -222,7 +222,7 @@ Each element is a cons cell (REGEXP . FUNCTION)."
:type 'list)

(defcustom blamer-fallback-avatar-config
'("http://www.gravatar.com/avatar" blamer--fallback-avatar-uploader)
'("https://www.gravatar.com/avatar" blamer--fallback-avatar-uploader)
"Fallback avatar config."
:group 'blamer
:type 'list)
Expand Down Expand Up @@ -598,15 +598,24 @@ REMOTE-URL - url of resource to download avatar."
(avatar-url (gethash "avatar_url" json-data)))
(blamer--upload-avatar avatar-url file-path)))

(defun blamer--normalize-file-path (file-path)
"Normalize FILE-PATH for Windows."
(setq file-path (replace-regexp-in-string ">" "" file-path))
(setq file-path (replace-regexp-in-string " " "-" file-path))
(setq file-path (replace-regexp-in-string "<" "" file-path))
file-path)

(defun blamer--upload-avatar (url file-path)
"Download the avatar from URL and save it to the path as FILE-PATH.
HOST-NAME is the name of the host for caching.
host folder.
If the file already exists, return the path to the existing file."
(unless (file-exists-p (file-name-directory file-path))
(make-directory (file-name-directory file-path) t))
(url-copy-file url file-path t)
file-path)
(setq file-path (blamer--normalize-file-path file-path))
(ignore-errors
(url-copy-file url file-path t)
file-path))


(defun blamer--find-avatar-uploader (remote-ref)
Expand Down

0 comments on commit 4b70b65

Please sign in to comment.