Skip to content

Commit

Permalink
Use new hook for delete
Browse files Browse the repository at this point in the history
In reference to issue FooSoft#146 

Also added the `deleteMediaFile` when dealing with urls. 

The new functionality of `writeData` means that is there is a name conflict it will rename the file. This way the behavior of your api does not change.

Only potential issues I see with this is that the file is `trashed` but not deleted. So is only cleared up on the usual clear up.

Test locally using my own Anki install at `2.1.22` and POST man to create new media
  • Loading branch information
c-okelly committed Apr 8, 2020
1 parent 5213988 commit 22a58bb
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ def storeMediaFile(self, filename, data=None, url=None):
self.deleteMediaFile(filename)
self.media().writeData(filename, base64.b64decode(data))
elif url:
self.deleteMediaFile(filename)
downloadedData = util.download(url)
self.media().writeData(filename, downloadedData)
else:
Expand All @@ -450,7 +451,10 @@ def retrieveMediaFile(self, filename):

@util.api()
def deleteMediaFile(self, filename):
self.media().syncDelete(filename)
try:
self.media().syncDelete(filename)
except AttributeError:
self.media().trash_files([filename])


@util.api()
Expand Down

0 comments on commit 22a58bb

Please sign in to comment.