Merge branch 'master' into Develop

This commit is contained in:
Ozzieisaacs 2021-08-29 10:44:13 +02:00
commit 10e212fcde
7 changed files with 1209 additions and 527 deletions

View File

@ -26,6 +26,7 @@ from datetime import datetime
import json import json
from shutil import copyfile from shutil import copyfile
from uuid import uuid4 from uuid import uuid4
from markupsafe import escape
try: try:
from lxml.html.clean import clean_html from lxml.html.clean import clean_html
except ImportError: except ImportError:
@ -468,7 +469,7 @@ def edit_book_comments(comments, book):
comments = clean_html(comments) comments = clean_html(comments)
if len(book.comments): if len(book.comments):
if book.comments[0].text != comments: if book.comments[0].text != comments:
book.comments[0].text = clean_html(comments) book.comments[0].text = comments
modif_date = True modif_date = True
else: else:
if comments: if comments:
@ -663,9 +664,9 @@ def upload_single_file(request, book, book_id):
return redirect(url_for('web.show_book', book_id=book.id)) return redirect(url_for('web.show_book', book_id=book.id))
# Queue uploader info # Queue uploader info
uploadText=_(u"File format %(ext)s added to %(book)s", ext=file_ext.upper(), book=book.title) link = '<a href="{}">{}</a>'.format(url_for('web.show_book', book_id=book.id), escape(book.title))
WorkerThread.add(current_user.name, TaskUpload( uploadText=_(u"File format %(ext)s added to %(book)s", ext=file_ext.upper(), book=link)
"<a href=\"" + url_for('web.show_book', book_id=book.id) + "\">" + uploadText + "</a>")) WorkerThread.add(current_user.name, TaskUpload(uploadText))
return uploader.process( return uploader.process(
saved_filename, *os.path.splitext(requested_file.filename), saved_filename, *os.path.splitext(requested_file.filename),
@ -1038,9 +1039,9 @@ def upload():
gdriveutils.updateGdriveCalibreFromLocal() gdriveutils.updateGdriveCalibreFromLocal()
if error: if error:
flash(error, category="error") flash(error, category="error")
uploadText=_(u"File %(file)s uploaded", file=title) link = '<a href="{}">{}</a>'.format(url_for('web.show_book', book_id=book_id), escape(title))
WorkerThread.add(current_user.name, TaskUpload( uploadText = _(u"File %(file)s uploaded", file=link)
"<a href=\"" + url_for('web.show_book', book_id=book_id) + "\">" + uploadText + "</a>")) WorkerThread.add(current_user.name, TaskUpload(uploadText))
if len(request.files.getlist("btn-upload")) < 2: if len(request.files.getlist("btn-upload")) < 2:
if current_user.role_edit() or current_user.role_admin(): if current_user.role_edit() or current_user.role_admin():

View File

@ -98,10 +98,10 @@ def convert_book_format(book_id, calibrepath, old_book_format, new_book_format,
settings['body'] = _(u'This e-mail has been sent via Calibre-Web.') settings['body'] = _(u'This e-mail has been sent via Calibre-Web.')
else: else:
settings = dict() settings = dict()
link = '<a href="{}">{}</a>"'.format(url_for('web.show_book', book_id=book.id), escape(book.title)) # prevent xss link = '<a href="{}">{}</a>'.format(url_for('web.show_book', book_id=book.id), escape(book.title)) # prevent xss
txt = u"{} -> {}: {}".format( txt = u"{} -> {}: {}".format(
old_book_format, old_book_format.upper(),
new_book_format, new_book_format.upper(),
link) link)
settings['old_book_format'] = old_book_format settings['old_book_format'] = old_book_format
settings['new_book_format'] = new_book_format settings['new_book_format'] = new_book_format
@ -216,9 +216,11 @@ def send_mail(book_id, book_format, convert, kindle_mail, calibrepath, user_id):
for entry in iter(book.data): for entry in iter(book.data):
if entry.format.upper() == book_format.upper(): if entry.format.upper() == book_format.upper():
converted_file_name = entry.name + '.' + book_format.lower() converted_file_name = entry.name + '.' + book_format.lower()
link = '<a href="{}">{}</a>'.format(url_for('web.show_book', book_id=book_id), escape(book.title))
EmailText = _(u"%(book)s send to Kindle", book=link)
WorkerThread.add(user_id, TaskEmail(_(u"Send to Kindle"), book.path, converted_file_name, WorkerThread.add(user_id, TaskEmail(_(u"Send to Kindle"), book.path, converted_file_name,
config.get_mail_settings(), kindle_mail, config.get_mail_settings(), kindle_mail,
_(u"E-mail: %(book)s", book=book.title), _(u'This e-mail has been sent via Calibre-Web.'))) EmailText, _(u'This e-mail has been sent via Calibre-Web.')))
return return
return _(u"The requested file could not be read. Maybe wrong permissions?") return _(u"The requested file could not be read. Maybe wrong permissions?")

View File

@ -61,7 +61,7 @@ def get_user_info(credentials):
return user_info.get('email', "") return user_info.get('email', "")
def send_messsage(token, msg): def send_messsage(token, msg):
log.debug("Start sending email via Gmail") log.debug("Start sending e-mail via Gmail")
creds = Credentials( creds = Credentials(
token=token['token'], token=token['token'],
refresh_token=token['refresh_token'], refresh_token=token['refresh_token'],
@ -80,4 +80,4 @@ def send_messsage(token, msg):
body = {'raw': raw} body = {'raw': raw}
(service.users().messages().send(userId='me', body=body).execute()) (service.users().messages().send(userId='me', body=body).execute())
log.debug("Email send successfully via Gmail") log.debug("E-mail send successfully via Gmail")

View File

@ -36,10 +36,10 @@ $(function() {
async: true, async: true,
timeout: 900, timeout: 900,
success: function (data) { success: function (data) {
$('#table').bootstrapTable("load", data); $('#tasktable').bootstrapTable("load", data);
} }
}); });
}, 2000); }, 1000);
} }
$("#books-table").on("check.bs.table check-all.bs.table uncheck.bs.table uncheck-all.bs.table", $("#books-table").on("check.bs.table check-all.bs.table uncheck.bs.table uncheck-all.bs.table",

View File

@ -5,6 +5,7 @@ import re
from glob import glob from glob import glob
from shutil import copyfile from shutil import copyfile
from markupsafe import escape
from sqlalchemy.exc import SQLAlchemyError from sqlalchemy.exc import SQLAlchemyError
@ -13,6 +14,7 @@ from cps import db
from cps import logger, config from cps import logger, config
from cps.subproc_wrapper import process_open from cps.subproc_wrapper import process_open
from flask_babel import gettext as _ from flask_babel import gettext as _
from flask import url_for
from cps.tasks.mail import TaskEmail from cps.tasks.mail import TaskEmail
from cps import gdriveutils from cps import gdriveutils
@ -24,6 +26,7 @@ class TaskConvert(CalibreTask):
super(TaskConvert, self).__init__(taskMessage) super(TaskConvert, self).__init__(taskMessage)
self.file_path = file_path self.file_path = file_path
self.bookid = bookid self.bookid = bookid
self.title = ""
self.settings = settings self.settings = settings
self.kindle_mail = kindle_mail self.kindle_mail = kindle_mail
self.user = user self.user = user
@ -35,6 +38,7 @@ class TaskConvert(CalibreTask):
if config.config_use_google_drive: if config.config_use_google_drive:
worker_db = db.CalibreDB(expire_on_commit=False) worker_db = db.CalibreDB(expire_on_commit=False)
cur_book = worker_db.get_book(self.bookid) cur_book = worker_db.get_book(self.bookid)
self.title = cur_book.title
data = worker_db.get_book_format(self.bookid, self.settings['old_book_format']) data = worker_db.get_book_format(self.bookid, self.settings['old_book_format'])
df = gdriveutils.getFileFromEbooksFolder(cur_book.path, df = gdriveutils.getFileFromEbooksFolder(cur_book.path,
data.name + "." + self.settings['old_book_format'].lower()) data.name + "." + self.settings['old_book_format'].lower())
@ -66,12 +70,13 @@ class TaskConvert(CalibreTask):
# if we're sending to kindle after converting, create a one-off task and run it immediately # if we're sending to kindle after converting, create a one-off task and run it immediately
# todo: figure out how to incorporate this into the progress # todo: figure out how to incorporate this into the progress
try: try:
EmailText = _(u"%(book)s send to Kindle", book=escape(self.title))
worker_thread.add(self.user, TaskEmail(self.settings['subject'], worker_thread.add(self.user, TaskEmail(self.settings['subject'],
self.results["path"], self.results["path"],
filename, filename,
self.settings, self.settings,
self.kindle_mail, self.kindle_mail,
self.settings['subject'], EmailText,
self.settings['body'], self.settings['body'],
internal=True) internal=True)
) )
@ -93,8 +98,9 @@ class TaskConvert(CalibreTask):
local_db.get_book_format(self.bookid, self.settings['new_book_format']): local_db.get_book_format(self.bookid, self.settings['new_book_format']):
log.info("Book id %d already converted to %s", book_id, format_new_ext) log.info("Book id %d already converted to %s", book_id, format_new_ext)
cur_book = local_db.get_book(book_id) cur_book = local_db.get_book(book_id)
self.title = cur_book.title
self.results['path'] = file_path self.results['path'] = file_path
self.results['title'] = cur_book.title self.results['title'] = self.title
self._handleSuccess() self._handleSuccess()
local_db.session.close() local_db.session.close()
return os.path.basename(file_path + format_new_ext) return os.path.basename(file_path + format_new_ext)
@ -130,7 +136,8 @@ class TaskConvert(CalibreTask):
local_db.session.close() local_db.session.close()
return return
self.results['path'] = cur_book.path self.results['path'] = cur_book.path
self.results['title'] = cur_book.title self.title = cur_book.title
self.results['title'] = self.title
if not config.config_use_google_drive: if not config.config_use_google_drive:
self._handleSuccess() self._handleSuccess()
return os.path.basename(file_path + format_new_ext) return os.path.basename(file_path + format_new_ext)

View File

@ -143,7 +143,7 @@ class TaskEmail(CalibreTask):
self.send_gmail_email(msg) self.send_gmail_email(msg)
except MemoryError as e: except MemoryError as e:
log.debug_or_exception(e) log.debug_or_exception(e)
self._handleError(u'MemoryError sending email: {}'.format(str(e))) self._handleError(u'MemoryError sending e-mail: {}'.format(str(e)))
except (smtplib.SMTPException, smtplib.SMTPAuthenticationError) as e: except (smtplib.SMTPException, smtplib.SMTPAuthenticationError) as e:
log.debug_or_exception(e) log.debug_or_exception(e)
if hasattr(e, "smtp_error"): if hasattr(e, "smtp_error"):
@ -154,13 +154,13 @@ class TaskEmail(CalibreTask):
text = '\n'.join(e.args) text = '\n'.join(e.args)
else: else:
text = '' text = ''
self._handleError(u'Smtplib Error sending email: {}'.format(text)) self._handleError(u'Smtplib Error sending e-mail: {}'.format(text))
except socket.error as e: except socket.error as e:
log.debug_or_exception(e) log.debug_or_exception(e)
self._handleError(u'Socket Error sending email: {}'.format(e.strerror)) self._handleError(u'Socket Error sending e-mail: {}'.format(e.strerror))
except Exception as ex: except Exception as ex:
log.debug_or_exception(ex) log.debug_or_exception(ex)
self._handleError(u'Error sending email: {}'.format(ex)) self._handleError(u'Error sending e-mail: {}'.format(ex))
def send_standard_email(self, msg): def send_standard_email(self, msg):
@ -173,7 +173,7 @@ class TaskEmail(CalibreTask):
org_smtpstderr = smtplib.stderr org_smtpstderr = smtplib.stderr
smtplib.stderr = logger.StderrLogger('worker.smtp') smtplib.stderr = logger.StderrLogger('worker.smtp')
log.debug("Start sending email") log.debug("Start sending e-mail")
if use_ssl == 2: if use_ssl == 2:
self.asyncSMTP = EmailSSL(self.settings["mail_server"], self.settings["mail_port"], self.asyncSMTP = EmailSSL(self.settings["mail_server"], self.settings["mail_port"],
timeout=timeout) timeout=timeout)
@ -196,7 +196,7 @@ class TaskEmail(CalibreTask):
self.asyncSMTP.sendmail(self.settings["mail_from"], self.recipent, fp.getvalue()) self.asyncSMTP.sendmail(self.settings["mail_from"], self.recipent, fp.getvalue())
self.asyncSMTP.quit() self.asyncSMTP.quit()
self._handleSuccess() self._handleSuccess()
log.debug("Email send successfully") log.debug("E-mail send successfully")
if sys.version_info < (3, 0): if sys.version_info < (3, 0):
smtplib.stderr = org_smtpstderr smtplib.stderr = org_smtpstderr
@ -258,7 +258,7 @@ class TaskEmail(CalibreTask):
@property @property
def name(self): def name(self):
return "Email" return "E-mail"
def __str__(self): def __str__(self):
return "{}, {}".format(self.name, self.subject) return "{}, {}".format(self.name, self.subject)

File diff suppressed because it is too large Load Diff