Deleted book formats remove book from synced to kobo table
updated teststatus
This commit is contained in:
+2
-1
@@ -341,7 +341,8 @@ def delete_book_from_table(book_id, book_format, jsonResponse):
|
||||
else:
|
||||
calibre_db.session.query(db.Data).filter(db.Data.book == book.id).\
|
||||
filter(db.Data.format == book_format).delete()
|
||||
kobo_sync_status.remove_synced_book(book.id, True)
|
||||
if book_format.upper() in ['KEPUB', 'EPUB', 'EPUB3']:
|
||||
kobo_sync_status.remove_synced_book(book.id, True)
|
||||
calibre_db.session.commit()
|
||||
except Exception as ex:
|
||||
log.debug_or_exception(ex)
|
||||
|
||||
+10
-4
@@ -17,18 +17,18 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import sys
|
||||
import os
|
||||
import io
|
||||
import mimetypes
|
||||
import re
|
||||
import shutil
|
||||
import time
|
||||
import socket
|
||||
import unicodedata
|
||||
from datetime import datetime, timedelta
|
||||
from tempfile import gettempdir
|
||||
|
||||
from urllib.parse import urlparse
|
||||
import requests
|
||||
|
||||
from babel.dates import format_datetime
|
||||
from babel.units import format_unit
|
||||
from flask import send_from_directory, make_response, redirect, abort, url_for
|
||||
@@ -584,10 +584,16 @@ def get_book_cover_internal(book, use_generic_cover_on_failure):
|
||||
# saves book cover from url
|
||||
def save_cover_from_url(url, book_path):
|
||||
try:
|
||||
# 127.0.x.x, localhost, [::1], [::ffff:7f00:1]
|
||||
ip = socket.getaddrinfo(urlparse(url).hostname, 0)[0][4][0]
|
||||
if ip.startswith("127.") or ip.startswith('::ffff:7f') or ip == "::1":
|
||||
log.error("Localhost was accessed for cover upload")
|
||||
return False, _("You are not allowed to access localhost for cover uploads")
|
||||
img = requests.get(url, timeout=(10, 200)) # ToDo: Error Handling
|
||||
img.raise_for_status()
|
||||
return save_cover(img, book_path)
|
||||
except (requests.exceptions.HTTPError,
|
||||
except (socket.gaierror,
|
||||
requests.exceptions.HTTPError,
|
||||
requests.exceptions.ConnectionError,
|
||||
requests.exceptions.Timeout) as ex:
|
||||
log.info(u'Cover Download Error %s', ex)
|
||||
|
||||
@@ -21,6 +21,7 @@ from flask_login import current_user
|
||||
from . import ub
|
||||
import datetime
|
||||
from sqlalchemy.sql.expression import or_, and_, true
|
||||
from sqlalchemy import exc
|
||||
|
||||
# Add the current book id to kobo_synced_books table for current user, if entry is already present,
|
||||
# do nothing (safety precaution)
|
||||
@@ -36,14 +37,18 @@ def add_synced_books(book_id):
|
||||
|
||||
|
||||
# Select all entries of current book in kobo_synced_books table, which are from current user and delete them
|
||||
def remove_synced_book(book_id, all=False):
|
||||
def remove_synced_book(book_id, all=False, session=None):
|
||||
if not all:
|
||||
user = ub.KoboSyncedBooks.user_id == current_user.id
|
||||
else:
|
||||
user = true()
|
||||
ub.session.query(ub.KoboSyncedBooks).filter(ub.KoboSyncedBooks.book_id == book_id) \
|
||||
.filter(user).delete()
|
||||
ub.session_commit()
|
||||
if not session:
|
||||
ub.session.query(ub.KoboSyncedBooks).filter(ub.KoboSyncedBooks.book_id == book_id).filter(user).delete()
|
||||
ub.session_commit()
|
||||
else:
|
||||
session.query(ub.KoboSyncedBooks).filter(ub.KoboSyncedBooks.book_id == book_id).filter(user).delete()
|
||||
ub.session_commit(sess=session)
|
||||
|
||||
|
||||
|
||||
def change_archived_books(book_id, state=None, message=None):
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import sys
|
||||
import os
|
||||
import re
|
||||
|
||||
@@ -31,7 +30,8 @@ from cps import db
|
||||
from cps import logger, config
|
||||
from cps.subproc_wrapper import process_open
|
||||
from flask_babel import gettext as _
|
||||
from flask import url_for
|
||||
from cps.kobo_sync_status import remove_synced_book
|
||||
from cps.ub import ini
|
||||
|
||||
from cps.tasks.mail import TaskEmail
|
||||
from cps import gdriveutils
|
||||
@@ -147,6 +147,10 @@ class TaskConvert(CalibreTask):
|
||||
try:
|
||||
local_db.session.merge(new_format)
|
||||
local_db.session.commit()
|
||||
if self.settings['new_book_format'].upper() in ['KEPUB', 'EPUB', 'EPUB3']:
|
||||
ub_session = ini()
|
||||
remove_synced_book(book_id, True, ub_session)
|
||||
ub_session.close()
|
||||
except SQLAlchemyError as e:
|
||||
local_db.session.rollback()
|
||||
log.error("Database error: %s", e)
|
||||
|
||||
@@ -773,6 +773,14 @@ def create_admin_user(session):
|
||||
except Exception:
|
||||
session.rollback()
|
||||
|
||||
def ini():
|
||||
global app_DB_path
|
||||
engine = create_engine(u'sqlite:///{0}'.format(app_DB_path), echo=False)
|
||||
|
||||
Session = scoped_session(sessionmaker())
|
||||
Session.configure(bind=engine)
|
||||
return Session()
|
||||
|
||||
|
||||
def init_db(app_db_path):
|
||||
# Open session for database connection
|
||||
@@ -830,12 +838,13 @@ def dispose():
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def session_commit(success=None):
|
||||
def session_commit(success=None, sess=None):
|
||||
s = sess if sess else session
|
||||
try:
|
||||
session.commit()
|
||||
s.commit()
|
||||
if success:
|
||||
log.info(success)
|
||||
except (exc.OperationalError, exc.InvalidRequestError) as e:
|
||||
session.rollback()
|
||||
s.rollback()
|
||||
log.debug_or_exception(e)
|
||||
return ""
|
||||
|
||||
Reference in New Issue
Block a user