Compute SHA1 against file content instead of file name
This commit is contained in:
parent
308cd97a9d
commit
3c52675134
1 changed files with 5 additions and 5 deletions
|
@ -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)
|
||||||
|
|
Loading…
Reference in a new issue