|
|
@ -2,6 +2,8 @@
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
|
|
|
|
import mimetypes
|
|
|
|
import mimetypes
|
|
|
|
|
|
|
|
import logging
|
|
|
|
|
|
|
|
import sys
|
|
|
|
mimetypes.add_type('application/xhtml+xml','.xhtml')
|
|
|
|
mimetypes.add_type('application/xhtml+xml','.xhtml')
|
|
|
|
from flask import Flask, render_template, session, request, Response, redirect, url_for, send_from_directory, make_response, g, flash, abort
|
|
|
|
from flask import Flask, render_template, session, request, Response, redirect, url_for, send_from_directory, make_response, g, flash, abort
|
|
|
|
from cps import db, config, ub, helper
|
|
|
|
from cps import db, config, ub, helper
|
|
|
@ -20,6 +22,15 @@ from sqlalchemy.sql import *
|
|
|
|
|
|
|
|
|
|
|
|
app = (Flask(__name__))
|
|
|
|
app = (Flask(__name__))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Log only in production mode.
|
|
|
|
|
|
|
|
#if not app.debug:
|
|
|
|
|
|
|
|
file_handler = logging.StreamHandler(sys.stdout)
|
|
|
|
|
|
|
|
file_handler.setLevel(logging.INFO)
|
|
|
|
|
|
|
|
app.logger.addHandler(file_handler)
|
|
|
|
|
|
|
|
app.logger_name = 'calibre web'
|
|
|
|
|
|
|
|
app.logger.setLevel(logging.INFO)
|
|
|
|
|
|
|
|
app.logger.info('Starting Calibre Web...')
|
|
|
|
|
|
|
|
|
|
|
|
Principal(app)
|
|
|
|
Principal(app)
|
|
|
|
|
|
|
|
|
|
|
|
lm = LoginManager(app)
|
|
|
|
lm = LoginManager(app)
|
|
|
@ -41,8 +52,6 @@ def load_user_from_header(header_val):
|
|
|
|
header_val = base64.b64decode(header_val)
|
|
|
|
header_val = base64.b64decode(header_val)
|
|
|
|
basic_username = header_val.split(':')[0]
|
|
|
|
basic_username = header_val.split(':')[0]
|
|
|
|
basic_password = header_val.split(':')[1]
|
|
|
|
basic_password = header_val.split(':')[1]
|
|
|
|
#print basic_username
|
|
|
|
|
|
|
|
#print basic_password
|
|
|
|
|
|
|
|
except TypeError:
|
|
|
|
except TypeError:
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
user = ub.session.query(ub.User).filter(ub.User.nickname == basic_username).first()
|
|
|
|
user = ub.session.query(ub.User).filter(ub.User.nickname == basic_username).first()
|
|
|
@ -212,14 +221,7 @@ def get_opds_download_link(book_id, format):
|
|
|
|
file_name = author+'-'+file_name
|
|
|
|
file_name = author+'-'+file_name
|
|
|
|
file_name = helper.get_valid_filename(file_name)
|
|
|
|
file_name = helper.get_valid_filename(file_name)
|
|
|
|
response = make_response(send_from_directory(os.path.join(config.DB_ROOT, book.path), data.name + "." +format))
|
|
|
|
response = make_response(send_from_directory(os.path.join(config.DB_ROOT, book.path), data.name + "." +format))
|
|
|
|
#response.headers["Content-Disposition"] = "attachment; filename=%s.%s" % (data.name, format)
|
|
|
|
response.headers["Content-Disposition"] = "attachment; filename=%s.%s" % (data.name, format)
|
|
|
|
response.headers["Content-Disposition"] = \
|
|
|
|
|
|
|
|
"attachment; " \
|
|
|
|
|
|
|
|
"filename={utf_filename}.{suffix};" \
|
|
|
|
|
|
|
|
"filename*=UTF-8''{utf_filename}.{suffix}".format(
|
|
|
|
|
|
|
|
utf_filename=file_name.encode('utf-8'),
|
|
|
|
|
|
|
|
suffix=format
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
return response
|
|
|
|
return response
|
|
|
|
|
|
|
|
|
|
|
|
@app.route("/", defaults={'page': 1})
|
|
|
|
@app.route("/", defaults={'page': 1})
|
|
|
@ -238,12 +240,6 @@ def index(page):
|
|
|
|
@app.route('/hot/page/<int:page>')
|
|
|
|
@app.route('/hot/page/<int:page>')
|
|
|
|
def hot_books(page):
|
|
|
|
def hot_books(page):
|
|
|
|
random = db.session.query(db.Books).filter(false())
|
|
|
|
random = db.session.query(db.Books).filter(false())
|
|
|
|
# if page == 1:
|
|
|
|
|
|
|
|
# entries = db.session.query(db.Books).filter(db.Books.ratings.any(db.Ratings.rating > 9)).order_by(db.Books.last_modified.desc()).limit(config.NEWEST_BOOKS)
|
|
|
|
|
|
|
|
# else:
|
|
|
|
|
|
|
|
# off = int(int(config.NEWEST_BOOKS) * (page - 1))
|
|
|
|
|
|
|
|
# entries = db.session.query(db.Books).filter(db.Books.ratings.any(db.Ratings.rating > 9)).order_by(db.Books.last_modified.desc()).offset(60).limit(config.NEWEST_BOOKS)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
off = int(int(6) * (page - 1))
|
|
|
|
off = int(int(6) * (page - 1))
|
|
|
|
all_books = ub.session.query(ub.Downloads, ub.func.count(ub.Downloads.book_id)).order_by(ub.func.count(ub.Downloads.book_id).desc()).group_by(ub.Downloads.book_id)
|
|
|
|
all_books = ub.session.query(ub.Downloads, ub.func.count(ub.Downloads.book_id)).order_by(ub.func.count(ub.Downloads.book_id).desc()).group_by(ub.Downloads.book_id)
|
|
|
|
hot_books = all_books.offset(off).limit(config.NEWEST_BOOKS)
|
|
|
|
hot_books = all_books.offset(off).limit(config.NEWEST_BOOKS)
|
|
|
@ -370,7 +366,6 @@ def get_download_link(book_id, format):
|
|
|
|
file_name = author+'-'+file_name
|
|
|
|
file_name = author+'-'+file_name
|
|
|
|
file_name = helper.get_valid_filename(file_name)
|
|
|
|
file_name = helper.get_valid_filename(file_name)
|
|
|
|
response = make_response(send_from_directory(os.path.join(config.DB_ROOT, book.path), data.name + "." +format))
|
|
|
|
response = make_response(send_from_directory(os.path.join(config.DB_ROOT, book.path), data.name + "." +format))
|
|
|
|
#response.headers["Content-Disposition"] = "attachment; filename=%s.%s" % (file_name, format)
|
|
|
|
|
|
|
|
response.headers["Content-Disposition"] = \
|
|
|
|
response.headers["Content-Disposition"] = \
|
|
|
|
"attachment; " \
|
|
|
|
"attachment; " \
|
|
|
|
"filename={utf_filename}.{suffix};" \
|
|
|
|
"filename={utf_filename}.{suffix};" \
|
|
|
@ -544,7 +539,6 @@ def profile():
|
|
|
|
downloads.append(db.session.query(db.Books).filter(db.Books.id == book.book_id).first())
|
|
|
|
downloads.append(db.session.query(db.Books).filter(db.Books.id == book.book_id).first())
|
|
|
|
if request.method == "POST":
|
|
|
|
if request.method == "POST":
|
|
|
|
to_save = request.form.to_dict()
|
|
|
|
to_save = request.form.to_dict()
|
|
|
|
#print to_save
|
|
|
|
|
|
|
|
if to_save["password"]:
|
|
|
|
if to_save["password"]:
|
|
|
|
content.password = generate_password_hash(to_save["password"])
|
|
|
|
content.password = generate_password_hash(to_save["password"])
|
|
|
|
if to_save["kindle_mail"] and to_save["kindle_mail"] != content.kindle_mail:
|
|
|
|
if to_save["kindle_mail"] and to_save["kindle_mail"] != content.kindle_mail:
|
|
|
@ -660,7 +654,6 @@ def edit_book(book_id):
|
|
|
|
book = db.session.query(db.Books).filter(db.Books.id == book_id).first()
|
|
|
|
book = db.session.query(db.Books).filter(db.Books.id == book_id).first()
|
|
|
|
if request.method == 'POST':
|
|
|
|
if request.method == 'POST':
|
|
|
|
to_save = request.form.to_dict()
|
|
|
|
to_save = request.form.to_dict()
|
|
|
|
#print to_save
|
|
|
|
|
|
|
|
book.title = to_save["book_title"]
|
|
|
|
book.title = to_save["book_title"]
|
|
|
|
book.authors[0].name = to_save["author_name"]
|
|
|
|
book.authors[0].name = to_save["author_name"]
|
|
|
|
|
|
|
|
|
|
|
@ -679,7 +672,6 @@ def edit_book(book_id):
|
|
|
|
|
|
|
|
|
|
|
|
for tag in to_save["tags"].split(","):
|
|
|
|
for tag in to_save["tags"].split(","):
|
|
|
|
if tag.strip():
|
|
|
|
if tag.strip():
|
|
|
|
#print tag
|
|
|
|
|
|
|
|
is_tag = db.session.query(db.Tags).filter(db.Tags.name.like('%' + tag.strip() + '%')).first()
|
|
|
|
is_tag = db.session.query(db.Tags).filter(db.Tags.name.like('%' + tag.strip() + '%')).first()
|
|
|
|
if is_tag:
|
|
|
|
if is_tag:
|
|
|
|
book.tags.append(is_tag)
|
|
|
|
book.tags.append(is_tag)
|
|
|
@ -707,11 +699,3 @@ def edit_book(book_id):
|
|
|
|
return render_template('edit_book.html', book=book)
|
|
|
|
return render_template('edit_book.html', book=book)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
return render_template('edit_book.html', book=book)
|
|
|
|
return render_template('edit_book.html', book=book)
|
|
|
|
|
|
|
|
|
|
|
|
# @app.route('/admin/delete/<int:book_id>')
|
|
|
|
|
|
|
|
# def delete_book(book_id):
|
|
|
|
|
|
|
|
# to_delete = db.session.query(db.Books).filter(db.Books.id == book_id).first()
|
|
|
|
|
|
|
|
# print to_delete
|
|
|
|
|
|
|
|
# db.session.delete(to_delete)
|
|
|
|
|
|
|
|
# db.session.commit()
|
|
|
|
|
|
|
|
# return redirect(url_for('index'))
|
|
|
|
|
|
|
|