Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addon does not set the sync-server url in Anki versions > 2.1.26 #19

Closed
kalehmann opened this issue Aug 25, 2020 · 2 comments
Closed

Addon does not set the sync-server url in Anki versions > 2.1.26 #19

kalehmann opened this issue Aug 25, 2020 · 2 comments

Comments

@kalehmann
Copy link

As of Anki version 2.1.28, the server address is not affected by the addon anymore.

What did I do?

I installed Anki 2.1.28 and created an addon with the following content:

import anki.sync, anki.hooks, aqt

addr = "http://127.0.0.1:27701/" # put your server address here
anki.sync.SYNC_BASE = "%s" + addr
def resetHostNum():
    aqt.mw.pm.profile['hostNum'] = None
anki.hooks.addHook("profileLoaded", resetHostNum)

Then I started Anki and hit the Sync button.

What did I expect to happen?

I expected Anki to make a request to the url specified in the addon.

What did happen instead?

Anki made a request to https://sync.ankiweb.net/msync/ instead.

Further information

The urls used for synchronizaton are hardcoded to https://sync.ankiweb.net since the commits 0e5b7da62aa0fd3726ca958f1cdae265d2dc0d91 and 529e89f48e747904ffd9c8ebac09739fb410bcaf.
Therefore they cannot be easily changed by the addon anymore.

@AntonOfTheWoods
Copy link
Contributor

AntonOfTheWoods commented Aug 25, 2020

Yeah, I keep telling people the upstream author really doesn't care about other server implementations. This is at least going to mean changing your hosts file (or similar, though that means you need to be able to use port 80). Is it still possible to allow for bad certs on the desktop client?

EDIT: I need to stop being an ass regarding the upstream author! Actually it is still perfectly possible to point to alternative server implementations. The base url(s) https://sync{i}.ankiweb.net have always been hardcoded. Previously it was python so we could do a nasty hack to replace via the plugin, now this part is compiled rust. However, whether it was for us or his own purposes, he has very kindly made it possible to configure these via envvars.

This gets Anki 2.1.32 pointing to a local server implementation (from source):

SYNC_ENDPOINT_MEDIA=http://localhost:8001/msync/ SYNC_ENDPOINT=http://localhost:8001/sync/ ./run

And obviously the same thing will work on any platform, one just needs to configure the envvars correctly.

@kalehmann
Copy link
Author

Wow, I am blind 🤦

Thank you for pointing this out. With

import os

addr = "http://127.0.0.1:27701/"

os.environ["SYNC_ENDPOINT"] = addr + "sync/"
os.environ["SYNC_ENDPOINT_MEDIA"] = addr + "msync/"

as addon for Anki and

server {
        listen      27701;
        server_name default;

        location / {
                proxy_pass https://sync3.ankiweb.net/;
        }
}

as local nginx proxy, I am able to intercept synchronization requests with Anki versions >= 2.1.28.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants