Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
D
douban-api-proxy
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
captainwong
douban-api-proxy
Commits
de0e27c5
Commit
de0e27c5
authored
Mar 12, 2020
by
Michael Shavit
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #1164 merge.
parent
09e7d76c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
10 deletions
+18
-10
kobo.py
cps/kobo.py
+9
-8
SyncToken.py
cps/services/SyncToken.py
+9
-2
No files found.
cps/kobo.py
View file @
de0e27c5
...
...
@@ -39,10 +39,10 @@ from flask import (
redirect
,
abort
)
from
flask_login
import
login_required
,
current_user
from
flask_login
import
current_user
,
login_required
from
werkzeug.datastructures
import
Headers
from
sqlalchemy
import
func
from
sqlalchemy.sql.expression
import
or_
from
sqlalchemy.sql.expression
import
and_
,
or_
import
requests
from
.
import
config
,
logger
,
kobo_auth
,
db
,
helper
,
ub
...
...
@@ -152,7 +152,7 @@ def HandleSyncRequest():
# (Ideally we would use a join for this logic, however cross-database joins don't look trivial in SqlAlchemy.)
recently_restored_or_archived_books
=
[]
archived_book_ids
=
{}
new_archived_last_modified
=
datetime
.
min
new_archived_last_modified
=
datetime
.
datetime
.
min
for
archived_book
in
archived_books
:
if
archived_book
.
last_modified
>
sync_token
.
archive_last_modified
:
recently_restored_or_archived_books
.
append
(
archived_book
.
book_id
)
...
...
@@ -213,6 +213,7 @@ def HandleSyncRequest():
sync_token
.
books_last_created
=
new_books_last_created
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
if
config
.
config_kobo_proxy
:
return
generate_sync_response
(
request
,
sync_token
,
sync_results
)
...
...
@@ -288,7 +289,7 @@ def create_book_entitlement(book, archived):
"IsRemoved"
:
archived
,
"IsHiddenFromArchive"
:
False
,
"IsLocked"
:
False
,
"LastModified"
:
book
.
last_modified
,
"LastModified"
:
convert_to_kobo_timestamp_string
(
book
.
last_modified
)
,
"OriginCategory"
:
"Imported"
,
"RevisionId"
:
book_uuid
,
"Status"
:
"Active"
,
...
...
@@ -568,7 +569,7 @@ def HandleBookDeletionRequest(book_uuid):
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
.
utcnow
()
archived_book
.
last_modified
=
datetime
.
datetime
.
utcnow
()
ub
.
session
.
merge
(
archived_book
)
ub
.
session
.
commit
()
...
...
@@ -577,12 +578,12 @@ def HandleBookDeletionRequest(book_uuid):
# TODO: Implement the following routes
@
kobo
.
route
(
"/v1/library/<
book_uuid>/state"
,
methods
=
[
"PU
T"
])
@
kobo
.
route
(
"/v1/library/<
dummy>"
,
methods
=
[
"DELETE"
,
"GE
T"
])
@
kobo
.
route
(
"/v1/library/tags"
,
methods
=
[
"POST"
])
@
kobo
.
route
(
"/v1/library/tags/<shelf_name>"
,
methods
=
[
"POST"
])
@
kobo
.
route
(
"/v1/library/tags/<tag_id>"
,
methods
=
[
"DELETE"
])
def
HandleUnimplementedRequest
(
book_uuid
=
None
,
shelf_name
=
None
,
tag_id
=
None
):
log
.
debug
(
"
Alternative Request received:"
)
def
HandleUnimplementedRequest
(
dummy
=
None
,
book_uuid
=
None
,
shelf_name
=
None
,
tag_id
=
None
):
log
.
debug
(
"
Unimplemented Library Request received:
%
s"
,
request
.
base_url
)
return
redirect_or_proxy_request
()
...
...
cps/services/SyncToken.py
View file @
de0e27c5
...
...
@@ -77,6 +77,7 @@ class SyncToken():
"books_last_modified"
:
{
"type"
:
"string"
},
"books_last_created"
:
{
"type"
:
"string"
},
"archive_last_modified"
:
{
"type"
:
"string"
},
"reading_state_last_modified"
:
{
"type"
:
"string"
},
},
}
...
...
@@ -86,11 +87,14 @@ class SyncToken():
books_last_created
=
datetime
.
min
,
books_last_modified
=
datetime
.
min
,
archive_last_modified
=
datetime
.
min
,
reading_state_last_modified
=
datetime
.
min
,
):
self
.
raw_kobo_store_token
=
raw_kobo_store_token
self
.
books_last_created
=
books_last_created
self
.
books_last_modified
=
books_last_modified
self
.
archive_last_modified
=
archive_last_modified
self
.
reading_state_last_modified
=
reading_state_last_modified
@
staticmethod
def
from_headers
(
headers
):
...
...
@@ -123,6 +127,7 @@ class SyncToken():
books_last_modified
=
get_datetime_from_json
(
data_json
,
"books_last_modified"
)
books_last_created
=
get_datetime_from_json
(
data_json
,
"books_last_created"
)
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"
)
except
TypeError
:
log
.
error
(
"SyncToken timestamps don't parse to a datetime."
)
return
SyncToken
(
raw_kobo_store_token
=
raw_kobo_store_token
)
...
...
@@ -131,7 +136,8 @@ class SyncToken():
raw_kobo_store_token
=
raw_kobo_store_token
,
books_last_created
=
books_last_created
,
books_last_modified
=
books_last_modified
,
archive_last_modified
=
archive_last_modified
archive_last_modified
=
archive_last_modified
,
reading_state_last_modified
=
reading_state_last_modified
)
def
set_kobo_store_header
(
self
,
store_headers
):
...
...
@@ -152,7 +158,8 @@ class SyncToken():
"raw_kobo_store_token"
:
self
.
raw_kobo_store_token
,
"books_last_modified"
:
to_epoch_timestamp
(
self
.
books_last_modified
),
"books_last_created"
:
to_epoch_timestamp
(
self
.
books_last_created
),
"archive_last_modified"
:
to_epoch_timestamp
(
self
.
archive_last_modified
)
"archive_last_modified"
:
to_epoch_timestamp
(
self
.
archive_last_modified
),
"reading_state_last_modified"
:
to_epoch_timestamp
(
self
.
reading_state_last_modified
)
},
}
return
b64encode_json
(
token
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment