Content server: Redirect pre 2.x book URLs to new 3.x URLs via a javascript redirect

Merge branch 'master' of https://github.com/Geremia/calibre
This commit is contained in:
Kovid Goyal 2017-12-31 08:42:59 +05:30
commit 799034adf9
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -252,6 +252,19 @@ def mobile(ctx, rd):
@endpoint('/browse/{+rest=""}')
def browse(ctx, rd, rest):
if rest.startswith('book/'):
# implementation of https://bugs.launchpad.net/calibre/+bug/1698411
# redirect old server book URLs to new URLs
redirect = ctx.url_for(None) + '#book_id=' + rest[5:] + "&panel=book_details"
from lxml import etree as ET
return html(ctx, rd, endpoint,
E.html(E.head(
ET.XML('<meta http-equiv="refresh" content="0;url=' + redirect + '"/>'),
ET.XML('<script language="javascript">' +
'window.location.href = "' + redirect + '"' +
'</script>'
))))
else:
raise HTTPRedirect(ctx.url_for(None))