Use new hook for delete
In reference to issue #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
This commit is contained in:
parent
521398870c
commit
22a58bb707
@ -429,6 +429,7 @@ class AnkiConnect:
|
|||||||
self.deleteMediaFile(filename)
|
self.deleteMediaFile(filename)
|
||||||
self.media().writeData(filename, base64.b64decode(data))
|
self.media().writeData(filename, base64.b64decode(data))
|
||||||
elif url:
|
elif url:
|
||||||
|
self.deleteMediaFile(filename)
|
||||||
downloadedData = util.download(url)
|
downloadedData = util.download(url)
|
||||||
self.media().writeData(filename, downloadedData)
|
self.media().writeData(filename, downloadedData)
|
||||||
else:
|
else:
|
||||||
@ -450,7 +451,10 @@ class AnkiConnect:
|
|||||||
|
|
||||||
@util.api()
|
@util.api()
|
||||||
def deleteMediaFile(self, filename):
|
def deleteMediaFile(self, filename):
|
||||||
self.media().syncDelete(filename)
|
try:
|
||||||
|
self.media().syncDelete(filename)
|
||||||
|
except AttributeError:
|
||||||
|
self.media().trash_files([filename])
|
||||||
|
|
||||||
|
|
||||||
@util.api()
|
@util.api()
|
||||||
|
Loading…
Reference in New Issue
Block a user