Fix storeMediaFile logic

Currently, when `skip` is true and `deleteExisting` is true the `storeMediaFile` will simply delete the media file. 
However, the intended behavior should be to not touch the media file when both conditions are true.
This commit is contained in:
debanjandhar12 2022-06-06 13:47:22 +05:30 committed by GitHub
parent 5774ef7346
commit 504ac68b40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -650,8 +650,6 @@ class AnkiConnect:
def storeMediaFile(self, filename, data=None, path=None, url=None, skipHash=None, deleteExisting=True): def storeMediaFile(self, filename, data=None, path=None, url=None, skipHash=None, deleteExisting=True):
if not (data or path or url): if not (data or path or url):
raise Exception('You must provide a "data", "path", or "url" field.') raise Exception('You must provide a "data", "path", or "url" field.')
if deleteExisting:
self.deleteMediaFile(filename)
if data: if data:
mediaData = base64.b64decode(data) mediaData = base64.b64decode(data)
elif path: elif path:
@ -669,6 +667,8 @@ class AnkiConnect:
if skip: if skip:
return None return None
if deleteExisting:
self.deleteMediaFile(filename)
return self.media().writeData(filename, mediaData) return self.media().writeData(filename, mediaData)