mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Implement versioning for the cdb API
This commit is contained in:
parent
1f1fe6b024
commit
0710ed215d
@ -193,7 +193,7 @@ class DBCtx(object):
|
||||
def remote_run(self, name, m, *args):
|
||||
from mechanize import HTTPError, Request
|
||||
from calibre.utils.serialize import msgpack_loads, msgpack_dumps
|
||||
url = self.url + '/cdb/run/' + name
|
||||
url = self.url + '/cdb/run/{}/{}'.format(name, getattr(m, 'version', 0))
|
||||
if self.library_id:
|
||||
url += '?' + urlencode({'library_id':self.library_id})
|
||||
rq = Request(url, data=msgpack_dumps(args),
|
||||
|
@ -14,14 +14,18 @@ from calibre.utils.serialize import MSGPACK_MIME, msgpack_loads, json_loads
|
||||
receive_data_methods = {'GET', 'POST'}
|
||||
|
||||
|
||||
@endpoint('/cdb/run/{which}', postprocess=msgpack_or_json, methods=receive_data_methods)
|
||||
def cdb_run(ctx, rd, which):
|
||||
@endpoint('/cdb/run/{which}/{version=0}', postprocess=msgpack_or_json, methods=receive_data_methods)
|
||||
def cdb_run(ctx, rd, which, version):
|
||||
try:
|
||||
m = module_for_cmd(which)
|
||||
except ImportError:
|
||||
raise HTTPNotFound('No module named: {}'.format(which))
|
||||
if not getattr(m, 'readonly', False):
|
||||
ctx.check_for_write_access(rd)
|
||||
if getattr(m, 'version', 0) != int(version):
|
||||
raise HTTPNotFound(('The module {} is not available in version: {}.'
|
||||
'Make sure the version of calibre used for the'
|
||||
' server and calibredb match').format(which, version))
|
||||
raw = rd.read()
|
||||
ct = rd.inheaders.get('Content-Type', all=True)
|
||||
try:
|
||||
|
Loading…
x
Reference in New Issue
Block a user