Fix syncing with AnkiDroid

This commit is contained in:
jdoe0 2015-11-29 11:53:58 +07:00
parent d3eab4266e
commit 3baad9cfac
3 changed files with 11 additions and 8 deletions

View File

@ -83,7 +83,7 @@ like ankisyncd.py) containing the code below and put it in ~/Anki/addons.
import anki.sync import anki.sync
anki.sync.SYNC_BASE = 'http://127.0.0.1:27701/' anki.sync.SYNC_BASE = 'http://127.0.0.1:27701/'
anki.sync.SYNC_MEDIA_BASE = 'http://127.0.0.1:27701/mediasync/' anki.sync.SYNC_MEDIA_BASE = 'http://127.0.0.1:27701/msync/'
Replace 127.0.0.1 with the IP address or the domain name of your server if Replace 127.0.0.1 with the IP address or the domain name of your server if
ankisyncd is not running on the same machine as Anki. ankisyncd is not running on the same machine as Anki.

View File

@ -3,5 +3,5 @@ host = 127.0.0.1
port = 27701 port = 27701
data_root = ./collections data_root = ./collections
base_url = /sync/ base_url = /sync/
base_media_url = /mediasync/ base_media_url = /msync/
auth_db_path = ./auth.db auth_db_path = ./auth.db

View File

@ -22,6 +22,7 @@ from webob import Response
import os import os
import hashlib import hashlib
import string
import ankisyncd import ankisyncd
@ -64,10 +65,12 @@ class SyncCollectionHandler(Syncer):
version = '2.0.12' version = '2.0.12'
platform = 'unknown' platform = 'unknown'
version_int = [int(x) for x in version.split('.')] version_int = [ int(str(x).translate(None, string.ascii_letters))
for x in version.split('.') ]
# Some insanity added in Anki 2.0.13 # Some insanity added in Anki 2.0.13
if client == 'ankidesktop' and version_int[0] >= 2 and version_int[1] >= 0 and version_int[2] >= 13: if (client == 'ankidroid' and version_int[0] >=2 and version_int[1] >= 3) \
or (client == 'ankidesktop' and version_int[0] >= 2 and version_int[1] >= 0 and version_int[2] >= 13):
return { return {
'scm': self.col.scm, 'scm': self.col.scm,
'ts': intTime(), 'ts': intTime(),
@ -87,7 +90,7 @@ class SyncMediaHandler(MediaSyncer):
MediaSyncer.__init__(self, col) MediaSyncer.__init__(self, col)
def begin(self, skey): def begin(self, skey):
return json.dumps({'data':{'sk':skey, 'usn':self.col._usn}, 'err':None}) return json.dumps({'data':{'sk':skey, 'usn':self.col._usn}, 'err':''})
def uploadChanges(self, data, skey): def uploadChanges(self, data, skey):
"""Adds files based from ZIP file data and returns the usn.""" """Adds files based from ZIP file data and returns the usn."""
@ -146,7 +149,7 @@ class SyncMediaHandler(MediaSyncer):
if finished: if finished:
self.col.media.syncMod() self.col.media.syncMod()
return json.dumps({'data':[processedCnt, usn], 'err':None}) return json.dumps({'data':[processedCnt, usn], 'err':''})
def downloadFiles(self, files): def downloadFiles(self, files):
import zipfile import zipfile
@ -179,7 +182,7 @@ class SyncMediaHandler(MediaSyncer):
for fname,mtime,csum, in self.col.media.db.execute("select fname,mtime,csum from media"): for fname,mtime,csum, in self.col.media.db.execute("select fname,mtime,csum from media"):
result.append([fname, usn, csum]) result.append([fname, usn, csum])
return json.dumps({'data':result, 'err':None}) return json.dumps({'data':result, 'err':''})
def mediaSanity(self, local=None): def mediaSanity(self, local=None):
if self.col.media.mediaCount() == local: if self.col.media.mediaCount() == local:
@ -187,7 +190,7 @@ class SyncMediaHandler(MediaSyncer):
else: else:
result = "FAILED" result = "FAILED"
return json.dumps({'data':result, 'err':None}) return json.dumps({'data':result, 'err':''})
class SyncUserSession(object): class SyncUserSession(object):
def __init__(self, name, path, collection_manager, setup_new_collection=None): def __init__(self, name, path, collection_manager, setup_new_collection=None):