Drop support for Anki <2.0.27
This commit is contained in:
parent
b0cb424770
commit
67830218eb
@ -57,35 +57,20 @@ class SyncCollectionHandler(Syncer):
|
|||||||
# So that 'server' (the 3rd argument) can't get set
|
# So that 'server' (the 3rd argument) can't get set
|
||||||
Syncer.__init__(self, col)
|
Syncer.__init__(self, col)
|
||||||
|
|
||||||
def meta(self, cv=None):
|
def meta(self):
|
||||||
# Make sure the media database is open!
|
# Make sure the media database is open!
|
||||||
if self.col.media.db is None:
|
if self.col.media.db is None:
|
||||||
self.col.media.connect()
|
self.col.media.connect()
|
||||||
|
|
||||||
if cv is not None:
|
return {
|
||||||
client, version, platform = cv.split(',')
|
'scm': self.col.scm,
|
||||||
else:
|
'ts': intTime(),
|
||||||
client = 'ankidesktop'
|
'mod': self.col.mod,
|
||||||
version = '2.0.12'
|
'usn': self.col._usn,
|
||||||
platform = 'unknown'
|
'musn': self.col.media.lastUsn(),
|
||||||
|
'msg': '',
|
||||||
version_int = [ int(str(x).translate(None, string.ascii_letters))
|
'cont': True,
|
||||||
for x in version.split('.') ]
|
}
|
||||||
|
|
||||||
# Some insanity added in Anki 2.0.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 {
|
|
||||||
'scm': self.col.scm,
|
|
||||||
'ts': intTime(),
|
|
||||||
'mod': self.col.mod,
|
|
||||||
'usn': self.col._usn,
|
|
||||||
'musn': self.col.media.lastUsn(),
|
|
||||||
'msg': '',
|
|
||||||
'cont': True,
|
|
||||||
}
|
|
||||||
else:
|
|
||||||
return (self.col.mod, self.col.scm, self.col._usn, intTime(), self.col.media.lastUsn())
|
|
||||||
|
|
||||||
class SyncMediaHandler(MediaSyncer):
|
class SyncMediaHandler(MediaSyncer):
|
||||||
operations = ['begin', 'mediaChanges', 'mediaSanity', 'mediaList', 'uploadChanges', 'downloadFiles']
|
operations = ['begin', 'mediaChanges', 'mediaSanity', 'mediaList', 'uploadChanges', 'downloadFiles']
|
||||||
@ -358,7 +343,7 @@ class SimpleUserManager(object):
|
|||||||
return username
|
return username
|
||||||
|
|
||||||
class SyncApp(object):
|
class SyncApp(object):
|
||||||
valid_urls = SyncCollectionHandler.operations + SyncMediaHandler.operations + ['hostKey', 'upload', 'download', 'getDecks']
|
valid_urls = SyncCollectionHandler.operations + SyncMediaHandler.operations + ['hostKey', 'upload', 'download']
|
||||||
|
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
from ankisyncd.thread import getCollectionManager
|
from ankisyncd.thread import getCollectionManager
|
||||||
@ -491,18 +476,6 @@ class SyncApp(object):
|
|||||||
if url not in self.valid_urls:
|
if url not in self.valid_urls:
|
||||||
raise HTTPNotFound()
|
raise HTTPNotFound()
|
||||||
|
|
||||||
if url == 'getDecks':
|
|
||||||
# This is an Anki 1.x client! Tell them to upgrade.
|
|
||||||
import zlib, logging
|
|
||||||
u = req.params.getone('u')
|
|
||||||
if u:
|
|
||||||
logging.warn("'%s' is attempting to sync with an Anki 1.x client" % u)
|
|
||||||
return Response(
|
|
||||||
status='200 OK',
|
|
||||||
content_type='application/json',
|
|
||||||
content_encoding='deflate',
|
|
||||||
body=zlib.compress(json.dumps({'status': 'oldVersion'})))
|
|
||||||
|
|
||||||
if url == 'hostKey':
|
if url == 'hostKey':
|
||||||
try:
|
try:
|
||||||
u = data['u']
|
u = data['u']
|
||||||
@ -541,6 +514,15 @@ class SyncApp(object):
|
|||||||
del data['v']
|
del data['v']
|
||||||
if data.has_key('cv'):
|
if data.has_key('cv'):
|
||||||
session.client_version = data['cv']
|
session.client_version = data['cv']
|
||||||
|
client, version, platform = data['cv'].split(',')
|
||||||
|
del data['cv']
|
||||||
|
|
||||||
|
version_int = [ int(str(x).translate(None, string.ascii_letters))
|
||||||
|
for x in version.split('.') ]
|
||||||
|
|
||||||
|
if (client == 'ankidroid' and version_int < [2, 3, 0]) \
|
||||||
|
or (client == 'ankidesktop' and version_int < [2, 0, 27]):
|
||||||
|
return Response(status="501") # client needs upgrade
|
||||||
self.session_manager.save(hkey, session)
|
self.session_manager.save(hkey, session)
|
||||||
session = self.session_manager.load(hkey, self.create_session)
|
session = self.session_manager.load(hkey, self.create_session)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user