sync: return error if full sync required or auth not set up

I run Anki on a headless machine (using Xvfb on Linux), and have clients
interact with it using Anki Connect. Currently, if a full sync is
required, I have no way of knowing about it from any error that Anki
Connect returns. It's easy to detect if a full sync would be required,
so return an error in this case.
This commit is contained in:
Robert Irelan 2024-06-21 17:46:58 -07:00 committed by Alex Yatskov
parent 7c171d6722
commit aab9346deb

View File

@ -488,7 +488,15 @@ class AnkiConnect:
@util.api()
def sync(self):
self.window().onSync()
mw = self.window()
auth = mw.pm.sync_auth()
if not auth:
raise Exception("sync: auth not configured")
out = mw.col.sync_collection(auth, mw.pm.media_syncing_enabled())
accepted_sync_statuses = [out.NO_CHANGES, out.NORMAL_SYNC]
if out.required not in accepted_sync_statuses:
raise Exception(f"Sync status {out.required} not one of {accepted_sync_statuses} - see SyncCollectionResponse.ChangesRequired for list of sync statuses: https://github.com/ankitects/anki/blob/e41c4573d789afe8b020fab5d9d1eede50c3fa3d/proto/anki/sync.proto#L57-L65")
mw.onSync()
@util.api()