Compute SHA1 against file content instead of file name

This commit is contained in:
louie 2019-11-03 00:20:51 +08:00 committed by louie
parent 308cd97a9d
commit 3c52675134

View file

@ -193,7 +193,10 @@ or raise an error."
(defun anki-editor--anki-connect-store-media-file (path) (defun anki-editor--anki-connect-store-media-file (path)
"Store media file for PATH, which is an absolute file name. "Store media file for PATH, which is an absolute file name.
The result is the path to the newly stored media file." The result is the path to the newly stored media file."
(let* ((hash (secure-hash 'sha1 path)) (let* ((bytes (with-temp-buffer
(insert-file-contents-literally path)
(buffer-string)))
(hash (secure-hash 'sha1 bytes))
(media-file-name (format "%s-%s%s" (media-file-name (format "%s-%s%s"
(file-name-base path) (file-name-base path)
hash hash
@ -203,10 +206,7 @@ The result is the path to the newly stored media file."
"retrieveMediaFile" "retrieveMediaFile"
`((filename . ,media-file-name)))) `((filename . ,media-file-name))))
(message "Storing media file %s to Anki, this might take a while" path) (message "Storing media file %s to Anki, this might take a while" path)
(setq content (base64-encode-string (setq content (base64-encode-string bytes))
(with-temp-buffer
(insert-file-contents path)
(buffer-string))))
(anki-editor--anki-connect-invoke-result (anki-editor--anki-connect-invoke-result
"storeMediaFile" "storeMediaFile"
`((filename . ,media-file-name) `((filename . ,media-file-name)