From 42bf40d7bb3ee488a6c742b29b72c706e974df19 Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Sat, 11 Dec 2021 17:40:36 +0100 Subject: [PATCH] Change 2 timestamps to utctime --- cps/editbooks.py | 2 ++ cps/kobo.py | 19 +++---------------- cps/kobo_sync_status.py | 2 +- cps/services/SyncToken.py | 9 ++------- 4 files changed, 8 insertions(+), 24 deletions(-) diff --git a/cps/editbooks.py b/cps/editbooks.py index dbb14f79..448a52bd 100644 --- a/cps/editbooks.py +++ b/cps/editbooks.py @@ -1100,6 +1100,7 @@ def upload(): flash(_(u"Database error: %(error)s.", error=e), category="error") return Response(json.dumps({"location": url_for("web.index")}), mimetype='application/json') + @editbook.route("/admin/book/convert/", methods=['POST']) @login_required_if_no_ano @edit_required @@ -1298,6 +1299,7 @@ def merge_list_book(): return json.dumps({'success': True}) return "" + @editbook.route("/ajax/xchange", methods=['POST']) @login_required @edit_required diff --git a/cps/kobo.py b/cps/kobo.py index b0917a47..1bcf3f8d 100644 --- a/cps/kobo.py +++ b/cps/kobo.py @@ -133,7 +133,7 @@ def convert_to_kobo_timestamp_string(timestamp): return timestamp.strftime("%Y-%m-%dT%H:%M:%SZ") except AttributeError as exc: log.debug("Timestamp not valid: {}".format(exc)) - return datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%SZ") + return datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ") @kobo.route("/v1/library/sync") @@ -310,7 +310,6 @@ def HandleSyncRequest(): sync_token.books_last_modified = new_books_last_modified sync_token.archive_last_modified = new_archived_last_modified sync_token.reading_state_last_modified = new_reading_state_last_modified - # sync_token.books_last_id = books_last_id return generate_sync_response(sync_token, sync_results, cont_sync) @@ -388,7 +387,7 @@ def create_book_entitlement(book, archived): book_uuid = str(book.uuid) return { "Accessibility": "Full", - "ActivePeriod": {"From": convert_to_kobo_timestamp_string(datetime.datetime.now())}, + "ActivePeriod": {"From": convert_to_kobo_timestamp_string(datetime.datetime.utcnow())}, "Created": convert_to_kobo_timestamp_string(book.timestamp), "CrossRevisionId": book_uuid, "Id": book_uuid, @@ -942,7 +941,7 @@ def TopLevelEndpoint(): @kobo.route("/v1/library/", methods=["DELETE"]) @requires_kobo_auth def HandleBookDeletionRequest(book_uuid): - log.info("Kobo book deletion request received for book %s" % book_uuid) + log.info("Kobo book delete request received for book %s" % book_uuid) book = calibre_db.get_book_by_uuid(book_uuid) if not book: log.info(u"Book %s not found in database", book_uuid) @@ -950,18 +949,6 @@ def HandleBookDeletionRequest(book_uuid): book_id = book.id is_archived = kobo_sync_status.change_archived_books(book_id, True) - '''archived_book = ( - ub.session.query(ub.ArchivedBook) - .filter(ub.ArchivedBook.book_id == book_id) - .first() - ) - if not archived_book: - archived_book = ub.ArchivedBook(user_id=current_user.id, book_id=book_id) - archived_book.is_archived = True - archived_book.last_modified = datetime.datetime.utcnow() - - ub.session.merge(archived_book) - ub.session_commit()''' if is_archived: kobo_sync_status.remove_synced_book(book_id) return "", 204 diff --git a/cps/kobo_sync_status.py b/cps/kobo_sync_status.py index eee47d89..580ac8ea 100644 --- a/cps/kobo_sync_status.py +++ b/cps/kobo_sync_status.py @@ -49,7 +49,7 @@ def change_archived_books(book_id, state=None, message=None): archived_book = ub.ArchivedBook(user_id=current_user.id, book_id=book_id) archived_book.is_archived = state if state else not archived_book.is_archived - archived_book.last_modified = datetime.datetime.utcnow() + archived_book.last_modified = datetime.datetime.utcnow() # toDo. Check utc timestamp ub.session.merge(archived_book) ub.session_commit(message) diff --git a/cps/services/SyncToken.py b/cps/services/SyncToken.py index 85ed5032..0072a20d 100644 --- a/cps/services/SyncToken.py +++ b/cps/services/SyncToken.py @@ -138,12 +138,9 @@ class SyncToken: archive_last_modified = get_datetime_from_json(data_json, "archive_last_modified") reading_state_last_modified = get_datetime_from_json(data_json, "reading_state_last_modified") tags_last_modified = get_datetime_from_json(data_json, "tags_last_modified") - # books_last_id = data_json["books_last_id"] except TypeError: log.error("SyncToken timestamps don't parse to a datetime.") return SyncToken(raw_kobo_store_token=raw_kobo_store_token) - #except KeyError: - # books_last_id = -1 return SyncToken( raw_kobo_store_token=raw_kobo_store_token, @@ -152,7 +149,6 @@ class SyncToken: archive_last_modified=archive_last_modified, reading_state_last_modified=reading_state_last_modified, tags_last_modified=tags_last_modified, - #books_last_id=books_last_id ) def set_kobo_store_header(self, store_headers): @@ -176,7 +172,6 @@ class SyncToken: "archive_last_modified": to_epoch_timestamp(self.archive_last_modified), "reading_state_last_modified": to_epoch_timestamp(self.reading_state_last_modified), "tags_last_modified": to_epoch_timestamp(self.tags_last_modified), - #"books_last_id":self.books_last_id }, } return b64encode_json(token) @@ -186,5 +181,5 @@ class SyncToken: self.books_last_modified, self.archive_last_modified, self.reading_state_last_modified, - self.tags_last_modified, self.raw_kobo_store_token) - #self.books_last_id) + self.tags_last_modified, + self.raw_kobo_store_token)