Skip to content
This repository has been archived by the owner on Dec 31, 2023. It is now read-only.

"storeMediaFile" returning error for syncDelete #146

Closed
pnewell opened this issue Mar 22, 2020 · 7 comments
Closed

"storeMediaFile" returning error for syncDelete #146

pnewell opened this issue Mar 22, 2020 · 7 comments

Comments

@pnewell
Copy link

pnewell commented Mar 22, 2020

When I try to use storeMediaFile I am consistently getting the following error as of recent:

Error: 'MediaManager' object has no attribute 'syncDelete'

Looking at Anki's code, it does not look like media.py has syncDelete as of recent versions:
https://github.com/ankitects/anki/blob/cc44523449cda621c20f80e6583040deb57debb1/pylib/anki/media.py

@c-okelly
Copy link
Contributor

c-okelly commented Apr 7, 2020

The updated function is here I think:

trash_files

https://github.com/ankitects/anki/blob/master/pylib/anki/media.py#L117

The change appears after version 2.1.21 in version 2.1.22 with the removal of syncDelete

Unfortunately the new function only appears in 2.1.22. Method signature has also changed from str -> [str]

It also appears the functionality of add_file has changed. It now no longer overwrites an existing file but will rename the file if unique and return the filename

I would be concerned by these changes overall as its not super clear where we should be hooking into at all and will probably need to have more then one implementation for different versions.

It appears a 'hooks' repository has appeared that maps out supported addOn functionality

@c-okelly
Copy link
Contributor

c-okelly commented Apr 7, 2020

Following code does seem to work. I'm still testing backward compatibility though

    def some_function(filename):
        try:
            self.media().syncDelete(filename)
        except AttributeError:
            self.media().trash_files([filename])

@c-okelly
Copy link
Contributor

c-okelly commented Apr 7, 2020

This is the new docs do anki addons on which hooks we should be using I think. Pretty sparse for a lot of the functionality really

https://github.com/ankitects/addon-docs/blob/master/hooks-and-filters.md

@FooSoft
Copy link
Owner

FooSoft commented Apr 7, 2020

Following code does seem to work. I'm still testing backward compatibility though

    def some_function(filename):
        try:
            self.media().syncDelete(filename)
        except AttributeError:
            self.media().trash_files([filename])

@c-okelly that looks like it should work -- if you could open a PR with that change after verification, I would appreciate it :)

@toasted-nutbread
Copy link
Contributor

Ran into this error with Yomichan's screenshot feature also. Confirming that @c-okelly's solution seemed to work.

https://github.com/FooSoft/yomichan/blob/f177e3699ae85bafa3a648f5c03fbb8e303a6be3/ext/bg/js/anki-note-builder.js#L112-L116

c-okelly added a commit to c-okelly/anki-connect that referenced this issue Apr 8, 2020
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
@c-okelly
Copy link
Contributor

c-okelly commented Apr 8, 2020

Just opened there. Only issue I really see is that the files are trashed rather then deleted.

It seems some parts of this project might have migrated to Rust

@FooSoft
Copy link
Owner

FooSoft commented Apr 10, 2020

AnkiConnect with this change has now been pushed to AnkiWeb, thanks all 👍

@FooSoft FooSoft closed this as completed Apr 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants