mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add a robots.txt
This commit is contained in:
parent
0a44163d82
commit
6af8bdab97
@ -2,8 +2,7 @@
|
|||||||
# vim:fileencoding=utf-8
|
# vim:fileencoding=utf-8
|
||||||
# License: GPLv3 Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPLv3 Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
from __future__ import (unicode_literals, division, absolute_import,
|
from __future__ import (unicode_literals, division, absolute_import, print_function)
|
||||||
print_function)
|
|
||||||
import hashlib, random, zipfile, shutil, sys
|
import hashlib, random, zipfile, shutil, sys
|
||||||
from json import load as load_json_file
|
from json import load as load_json_file
|
||||||
|
|
||||||
@ -33,6 +32,11 @@ def appcache(ctx, rd):
|
|||||||
return lopen(P('content-server/calibre.appcache'), 'rb')
|
return lopen(P('content-server/calibre.appcache'), 'rb')
|
||||||
|
|
||||||
|
|
||||||
|
@endpoint('/robots.txt', auth_required=False)
|
||||||
|
def robots(ctx, rd):
|
||||||
|
return b'User-agent: *\nDisallow: /'
|
||||||
|
|
||||||
|
|
||||||
@endpoint('/auto-reload-port', auth_required=False, cache_control='no-cache')
|
@endpoint('/auto-reload-port', auth_required=False, cache_control='no-cache')
|
||||||
def auto_reload(ctx, rd):
|
def auto_reload(ctx, rd):
|
||||||
auto_reload_port = getattr(rd.opts, 'auto_reload_port', 0)
|
auto_reload_port = getattr(rd.opts, 'auto_reload_port', 0)
|
||||||
@ -40,7 +44,7 @@ def auto_reload(ctx, rd):
|
|||||||
return str(max(0, auto_reload_port))
|
return str(max(0, auto_reload_port))
|
||||||
|
|
||||||
|
|
||||||
@endpoint('/console-print', methods=('POST',))
|
@endpoint('/console-print', methods=('POST', ))
|
||||||
def console_print(ctx, rd):
|
def console_print(ctx, rd):
|
||||||
if not getattr(rd.opts, 'allow_console_print', False):
|
if not getattr(rd.opts, 'allow_console_print', False):
|
||||||
raise HTTPNotFound('console printing is not allowed')
|
raise HTTPNotFound('console printing is not allowed')
|
||||||
@ -76,7 +80,9 @@ def get_translations():
|
|||||||
global _cached_translations
|
global _cached_translations
|
||||||
if _cached_translations is None:
|
if _cached_translations is None:
|
||||||
_cached_translations = False
|
_cached_translations = False
|
||||||
with zipfile.ZipFile(P('content-server/locales.zip', allow_user_override=False), 'r') as zf:
|
with zipfile.ZipFile(
|
||||||
|
P('content-server/locales.zip', allow_user_override=False), 'r'
|
||||||
|
) as zf:
|
||||||
names = set(zf.namelist())
|
names = set(zf.namelist())
|
||||||
lang = get_lang()
|
lang = get_lang()
|
||||||
if lang not in names:
|
if lang not in names:
|
||||||
@ -93,15 +99,17 @@ DEFAULT_NUMBER_OF_BOOKS = 50
|
|||||||
|
|
||||||
def basic_interface_data(ctx, rd):
|
def basic_interface_data(ctx, rd):
|
||||||
ans = {
|
ans = {
|
||||||
'username':rd.username,
|
'username': rd.username,
|
||||||
'output_format':prefs['output_format'].upper(),
|
'output_format': prefs['output_format'].upper(),
|
||||||
'input_formats':{x.upper():True for x in available_input_formats()},
|
'input_formats': {x.upper(): True
|
||||||
'gui_pubdate_display_format':tweaks['gui_pubdate_display_format'],
|
for x in available_input_formats()},
|
||||||
'gui_timestamp_display_format':tweaks['gui_timestamp_display_format'],
|
'gui_pubdate_display_format': tweaks['gui_pubdate_display_format'],
|
||||||
'gui_last_modified_display_format':tweaks['gui_last_modified_display_format'],
|
'gui_timestamp_display_format': tweaks['gui_timestamp_display_format'],
|
||||||
|
'gui_last_modified_display_format':
|
||||||
|
tweaks['gui_last_modified_display_format'],
|
||||||
'use_roman_numerals_for_series_number': get_use_roman(),
|
'use_roman_numerals_for_series_number': get_use_roman(),
|
||||||
'translations': get_translations(),
|
'translations': get_translations(),
|
||||||
'allow_console_print':getattr(rd.opts, 'allow_console_print', False),
|
'allow_console_print': getattr(rd.opts, 'allow_console_print', False),
|
||||||
'icon_map': icon_map(),
|
'icon_map': icon_map(),
|
||||||
'icon_path': ctx.url_for('/icon', which=''),
|
'icon_path': ctx.url_for('/icon', which=''),
|
||||||
}
|
}
|
||||||
@ -121,18 +129,28 @@ def get_library_init_data(ctx, rd, db, num, sorts, orders):
|
|||||||
ans = {}
|
ans = {}
|
||||||
with db.safe_read_lock:
|
with db.safe_read_lock:
|
||||||
try:
|
try:
|
||||||
ans['search_result'] = search_result(ctx, rd, db, rd.query.get('search', ''), num, 0, ','.join(sorts), ','.join(orders))
|
ans['search_result'] = search_result(
|
||||||
|
ctx, rd, db,
|
||||||
|
rd.query.get('search', ''), num, 0, ','.join(sorts),
|
||||||
|
','.join(orders)
|
||||||
|
)
|
||||||
except ParseException:
|
except ParseException:
|
||||||
ans['search_result'] = search_result(ctx, rd, db, '', num, 0, ','.join(sorts), ','.join(orders))
|
ans['search_result'] = search_result(
|
||||||
|
ctx, rd, db, '', num, 0, ','.join(sorts), ','.join(orders)
|
||||||
|
)
|
||||||
sf = db.field_metadata.ui_sortable_field_keys()
|
sf = db.field_metadata.ui_sortable_field_keys()
|
||||||
sf.pop('ondevice', None)
|
sf.pop('ondevice', None)
|
||||||
ans['sortable_fields'] = sorted(((
|
ans['sortable_fields'] = sorted(
|
||||||
sanitize_sort_field_name(db.field_metadata, k), v) for k, v in sf.iteritems()),
|
((sanitize_sort_field_name(db.field_metadata, k), v)
|
||||||
key=lambda (field, name):sort_key(name))
|
for k, v in sf.iteritems()),
|
||||||
|
key=lambda (field, name): sort_key(name)
|
||||||
|
)
|
||||||
ans['field_metadata'] = db.field_metadata.all_metadata()
|
ans['field_metadata'] = db.field_metadata.all_metadata()
|
||||||
mdata = ans['metadata'] = {}
|
mdata = ans['metadata'] = {}
|
||||||
try:
|
try:
|
||||||
extra_books = set(int(x) for x in rd.query.get('extra_books', '').split(','))
|
extra_books = set(
|
||||||
|
int(x) for x in rd.query.get('extra_books', '').split(',')
|
||||||
|
)
|
||||||
except Exception:
|
except Exception:
|
||||||
extra_books = ()
|
extra_books = ()
|
||||||
for coll in (ans['search_result']['book_ids'], extra_books):
|
for coll in (ans['search_result']['book_ids'], extra_books):
|
||||||
@ -209,14 +227,18 @@ def more_books(ctx, rd):
|
|||||||
raise HTTPNotFound('Invalid number of books: %r' % rd.query.get('num'))
|
raise HTTPNotFound('Invalid number of books: %r' % rd.query.get('num'))
|
||||||
try:
|
try:
|
||||||
search_query = load_json_file(rd.request_body_file)
|
search_query = load_json_file(rd.request_body_file)
|
||||||
query, offset, sorts, orders = search_query['query'], search_query['offset'], search_query['sort'], search_query['sort_order']
|
query, offset, sorts, orders = search_query['query'], search_query[
|
||||||
|
'offset'
|
||||||
|
], search_query['sort'], search_query['sort_order']
|
||||||
except KeyError as err:
|
except KeyError as err:
|
||||||
raise HTTPBadRequest('Search query missing key: %s' % as_unicode(err))
|
raise HTTPBadRequest('Search query missing key: %s' % as_unicode(err))
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
raise HTTPBadRequest('Invalid query: %s' % as_unicode(err))
|
raise HTTPBadRequest('Invalid query: %s' % as_unicode(err))
|
||||||
ans = {}
|
ans = {}
|
||||||
with db.safe_read_lock:
|
with db.safe_read_lock:
|
||||||
ans['search_result'] = search_result(ctx, rd, db, query, num, offset, sorts, orders)
|
ans['search_result'] = search_result(
|
||||||
|
ctx, rd, db, query, num, offset, sorts, orders
|
||||||
|
)
|
||||||
mdata = ans['metadata'] = {}
|
mdata = ans['metadata'] = {}
|
||||||
for book_id in ans['search_result']['book_ids']:
|
for book_id in ans['search_result']['book_ids']:
|
||||||
data = book_as_json(db, book_id)
|
data = book_as_json(db, book_id)
|
||||||
@ -262,7 +284,9 @@ def get_books(ctx, rd):
|
|||||||
mdata = ans['metadata'] = {}
|
mdata = ans['metadata'] = {}
|
||||||
with db.safe_read_lock:
|
with db.safe_read_lock:
|
||||||
try:
|
try:
|
||||||
ans['search_result'] = search_result(ctx, rd, db, searchq, num, 0, ','.join(sorts), ','.join(orders))
|
ans['search_result'] = search_result(
|
||||||
|
ctx, rd, db, searchq, num, 0, ','.join(sorts), ','.join(orders)
|
||||||
|
)
|
||||||
except ParseException as err:
|
except ParseException as err:
|
||||||
# This must not be translated as it is used by the front end to
|
# This must not be translated as it is used by the front end to
|
||||||
# detect invalid search expressions
|
# detect invalid search expressions
|
||||||
@ -286,6 +310,7 @@ def book_metadata(ctx, rd, book_id):
|
|||||||
|
|
||||||
def notfound():
|
def notfound():
|
||||||
raise HTTPNotFound(_('No book with id: %d in library') % book_id)
|
raise HTTPNotFound(_('No book with id: %d in library') % book_id)
|
||||||
|
|
||||||
if not book_ids:
|
if not book_ids:
|
||||||
notfound()
|
notfound()
|
||||||
if not book_id:
|
if not book_id:
|
||||||
@ -313,4 +338,5 @@ def tag_browser(ctx, rd):
|
|||||||
def generate():
|
def generate():
|
||||||
db, library_id = get_library_data(ctx, rd)[:2]
|
db, library_id = get_library_data(ctx, rd)[:2]
|
||||||
return json(ctx, rd, tag_browser, categories_as_json(ctx, rd, db))
|
return json(ctx, rd, tag_browser, categories_as_json(ctx, rd, db))
|
||||||
|
|
||||||
return rd.etagged_dynamic_response(etag, generate)
|
return rd.etagged_dynamic_response(etag, generate)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user