|
|
|
@ -7,7 +7,7 @@ import logging
|
|
|
|
|
from logging.handlers import RotatingFileHandler
|
|
|
|
|
import textwrap
|
|
|
|
|
from flask import Flask, render_template, session, request, Response, redirect, url_for, send_from_directory, \
|
|
|
|
|
make_response, g, flash, abort, send_file
|
|
|
|
|
make_response, g, flash, abort, send_file, Markup
|
|
|
|
|
from flask import __version__ as flaskVersion
|
|
|
|
|
import ub
|
|
|
|
|
from ub import config
|
|
|
|
@ -765,16 +765,16 @@ def get_opds_download_link(book_id, format):
|
|
|
|
|
file_name = book.title
|
|
|
|
|
if len(book.authors) > 0:
|
|
|
|
|
file_name = book.authors[0].name + '-' + file_name
|
|
|
|
|
|
|
|
|
|
file_name = helper.get_valid_filename(file_name)
|
|
|
|
|
if config.config_use_google_drive:
|
|
|
|
|
df=gdriveutils.getFileFromEbooksFolder(Gdrive.Instance().drive, book.path, '%s.%s' % (data.name, format))
|
|
|
|
|
df=gdriveutils.getFileFromEbooksFolder(Gdrive.Instance().drive, book.path, data.name + "." + format)
|
|
|
|
|
download_url = df.metadata.get('downloadUrl')
|
|
|
|
|
resp, content = df.auth.Get_Http_Object().request(download_url)
|
|
|
|
|
response=send_file(io.BytesIO(content))
|
|
|
|
|
else:
|
|
|
|
|
# file_name = helper.get_valid_filename(file_name)
|
|
|
|
|
response = make_response(send_from_directory(os.path.join(config.config_calibre_dir, book.path), data.name + "." + format))
|
|
|
|
|
response.headers["Content-Disposition"] = "attachment; filename=\"%s.%s\"" % (data.name, format)
|
|
|
|
|
response.headers["Content-Disposition"] = "attachment; filename*=UTF-8''%s.%s" % (urllib.quote(file_name.encode('utf8')), format)
|
|
|
|
|
return response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -1160,7 +1160,7 @@ def stats():
|
|
|
|
|
categorys = len(db.session.query(db.Tags).all())
|
|
|
|
|
series = len(db.session.query(db.Series).all())
|
|
|
|
|
versions = uploader.book_formats.get_versions()
|
|
|
|
|
vendorpath = os.path.join(config.get_main_dir + "vendor" + os.sep)
|
|
|
|
|
vendorpath = os.path.join(config.get_main_dir, "vendor")
|
|
|
|
|
if sys.platform == "win32":
|
|
|
|
|
kindlegen = os.path.join(vendorpath, u"kindlegen.exe")
|
|
|
|
|
else:
|
|
|
|
@ -1577,7 +1577,7 @@ def get_download_link(book_id, format):
|
|
|
|
|
response.headers["Content-Type"] = mimetypes.types_map['.' + format]
|
|
|
|
|
except:
|
|
|
|
|
pass
|
|
|
|
|
response.headers["Content-Disposition"] = "attachment; filename=\"%s.%s\"" % (file_name.encode('utf-8'), format)
|
|
|
|
|
response.headers["Content-Disposition"] = "attachment; filename*=UTF-8''%s.%s" % (urllib.quote(file_name.encode('utf-8')), format)
|
|
|
|
|
return response
|
|
|
|
|
else:
|
|
|
|
|
abort(404)
|
|
|
|
@ -2549,16 +2549,39 @@ def upload():
|
|
|
|
|
else:
|
|
|
|
|
db_author = db.Authors(author, helper.get_sorted_author(author), "")
|
|
|
|
|
db.session.add(db_author)
|
|
|
|
|
|
|
|
|
|
#add language actually one value in list
|
|
|
|
|
input_language = meta.languages
|
|
|
|
|
db_language = None
|
|
|
|
|
if input_language != "":
|
|
|
|
|
input_language = isoLanguages.get(name=input_language).part3
|
|
|
|
|
hasLanguage = db.session.query(db.Languages).filter(db.Languages.lang_code == input_language).first()
|
|
|
|
|
if hasLanguage:
|
|
|
|
|
db_language = hasLanguage
|
|
|
|
|
else:
|
|
|
|
|
db_language = db.Languages(input_language)
|
|
|
|
|
db.session.add(db_language)
|
|
|
|
|
# combine path and normalize path from windows systems
|
|
|
|
|
path = os.path.join(author_dir, title_dir).replace('\\','/')
|
|
|
|
|
db_book = db.Books(title, "", db_author.sort, datetime.datetime.now(), datetime.datetime(101, 01, 01), 1,
|
|
|
|
|
datetime.datetime.now(), path, has_cover, db_author, [])
|
|
|
|
|
datetime.datetime.now(), path, has_cover, db_author, [], db_language)
|
|
|
|
|
db_book.authors.append(db_author)
|
|
|
|
|
if db_language is not None:
|
|
|
|
|
db_book.languages.append(db_language)
|
|
|
|
|
db_data = db.Data(db_book, meta.extension.upper()[1:], file_size, data_name)
|
|
|
|
|
db_book.data.append(db_data)
|
|
|
|
|
|
|
|
|
|
db.session.add(db_book)
|
|
|
|
|
db.session.flush()# flush content get db_book.id avalible
|
|
|
|
|
#add comment
|
|
|
|
|
upload_comment = Markup(meta.description).unescape()
|
|
|
|
|
db_comment = None
|
|
|
|
|
if upload_comment != "":
|
|
|
|
|
db_comment = db.Comments(upload_comment, db_book.id)
|
|
|
|
|
db.session.add(db_comment)
|
|
|
|
|
db.session.commit()
|
|
|
|
|
if db_language is not None: #display Full name instead of iso639.part3
|
|
|
|
|
db_book.languages[0].language_name = _(meta.languages)
|
|
|
|
|
author_names = []
|
|
|
|
|
for author in db_book.authors:
|
|
|
|
|
author_names.append(author.name)
|
|
|
|
|