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
e04aa80f
Commit
e04aa80f
authored
Feb 08, 2020
by
Ozzie Isaacs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #1181 and Fix #1182 handle removed "is_xhr" on werkzeug version 1.0.0
parent
2535bbbc
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
15 additions
and
13 deletions
+15
-13
README.md
README.md
+1
-1
oauth_bb.py
cps/oauth_bb.py
+1
-1
shelf.py
cps/shelf.py
+11
-9
web.py
cps/web.py
+2
-2
No files found.
README.md
View file @
e04aa80f
...
@@ -30,7 +30,7 @@ Calibre-Web is a web app providing a clean interface for browsing, reading and d
...
@@ -30,7 +30,7 @@ Calibre-Web is a web app providing a clean interface for browsing, reading and d
## Quick start
## Quick start
1.
Install dependencies by running
`pip3 install --target vendor -r requirements.txt`
.
1.
Install dependencies by running
`pip3 install --target vendor -r requirements.txt`
(python3.x) or
`pip install --target vendor -r requirements.txt`
(python2.7)
.
2.
Execute the command:
`python cps.py`
(or
`nohup python cps.py`
- recommended if you want to exit the terminal window)
2.
Execute the command:
`python cps.py`
(or
`nohup python cps.py`
- recommended if you want to exit the terminal window)
3.
Point your browser to
`http://localhost:8083`
or
`http://localhost:8083/opds`
for the OPDS catalog
3.
Point your browser to
`http://localhost:8083`
or
`http://localhost:8083/opds`
for the OPDS catalog
4.
Set
`Location of Calibre database`
to the path of the folder where your Calibre library (metadata.db) lives, push "submit" button
\
4.
Set
`Location of Calibre database`
to the path of the folder where your Calibre library (metadata.db) lives, push "submit" button
\
...
...
cps/oauth_bb.py
View file @
e04aa80f
...
@@ -50,7 +50,7 @@ def oauth_required(f):
...
@@ -50,7 +50,7 @@ def oauth_required(f):
def
inner
(
*
args
,
**
kwargs
):
def
inner
(
*
args
,
**
kwargs
):
if
config
.
config_login_type
==
constants
.
LOGIN_OAUTH
:
if
config
.
config_login_type
==
constants
.
LOGIN_OAUTH
:
return
f
(
*
args
,
**
kwargs
)
return
f
(
*
args
,
**
kwargs
)
if
request
.
is_xhr
:
if
request
.
headers
.
get
(
'X-Requested-With'
)
==
'XMLHttpRequest'
:
data
=
{
'status'
:
'error'
,
'message'
:
'Not Found'
}
data
=
{
'status'
:
'error'
,
'message'
:
'Not Found'
}
response
=
make_response
(
json
.
dumps
(
data
,
ensure_ascii
=
False
))
response
=
make_response
(
json
.
dumps
(
data
,
ensure_ascii
=
False
))
response
.
headers
[
"Content-Type"
]
=
"application/json; charset=utf-8"
response
.
headers
[
"Content-Type"
]
=
"application/json; charset=utf-8"
...
...
cps/shelf.py
View file @
e04aa80f
...
@@ -40,17 +40,18 @@ log = logger.create()
...
@@ -40,17 +40,18 @@ log = logger.create()
@
shelf
.
route
(
"/shelf/add/<int:shelf_id>/<int:book_id>"
)
@
shelf
.
route
(
"/shelf/add/<int:shelf_id>/<int:book_id>"
)
@
login_required
@
login_required
def
add_to_shelf
(
shelf_id
,
book_id
):
def
add_to_shelf
(
shelf_id
,
book_id
):
xhr
=
request
.
headers
.
get
(
'X-Requested-With'
)
==
'XMLHttpRequest'
shelf
=
ub
.
session
.
query
(
ub
.
Shelf
)
.
filter
(
ub
.
Shelf
.
id
==
shelf_id
)
.
first
()
shelf
=
ub
.
session
.
query
(
ub
.
Shelf
)
.
filter
(
ub
.
Shelf
.
id
==
shelf_id
)
.
first
()
if
shelf
is
None
:
if
shelf
is
None
:
log
.
error
(
"Invalid shelf specified:
%
s"
,
shelf_id
)
log
.
error
(
"Invalid shelf specified:
%
s"
,
shelf_id
)
if
not
request
.
is_
xhr
:
if
not
xhr
:
flash
(
_
(
u"Invalid shelf specified"
),
category
=
"error"
)
flash
(
_
(
u"Invalid shelf specified"
),
category
=
"error"
)
return
redirect
(
url_for
(
'web.index'
))
return
redirect
(
url_for
(
'web.index'
))
return
"Invalid shelf specified"
,
400
return
"Invalid shelf specified"
,
400
if
not
shelf
.
is_public
and
not
shelf
.
user_id
==
int
(
current_user
.
id
):
if
not
shelf
.
is_public
and
not
shelf
.
user_id
==
int
(
current_user
.
id
):
log
.
error
(
"User
%
s not allowed to add a book to
%
s"
,
current_user
,
shelf
)
log
.
error
(
"User
%
s not allowed to add a book to
%
s"
,
current_user
,
shelf
)
if
not
request
.
is_
xhr
:
if
not
xhr
:
flash
(
_
(
u"Sorry you are not allowed to add a book to the the shelf:
%(shelfname)
s"
,
shelfname
=
shelf
.
name
),
flash
(
_
(
u"Sorry you are not allowed to add a book to the the shelf:
%(shelfname)
s"
,
shelfname
=
shelf
.
name
),
category
=
"error"
)
category
=
"error"
)
return
redirect
(
url_for
(
'web.index'
))
return
redirect
(
url_for
(
'web.index'
))
...
@@ -58,7 +59,7 @@ def add_to_shelf(shelf_id, book_id):
...
@@ -58,7 +59,7 @@ def add_to_shelf(shelf_id, book_id):
if
shelf
.
is_public
and
not
current_user
.
role_edit_shelfs
():
if
shelf
.
is_public
and
not
current_user
.
role_edit_shelfs
():
log
.
info
(
"User
%
s not allowed to edit public shelves"
,
current_user
)
log
.
info
(
"User
%
s not allowed to edit public shelves"
,
current_user
)
if
not
request
.
is_
xhr
:
if
not
xhr
:
flash
(
_
(
u"You are not allowed to edit public shelves"
),
category
=
"error"
)
flash
(
_
(
u"You are not allowed to edit public shelves"
),
category
=
"error"
)
return
redirect
(
url_for
(
'web.index'
))
return
redirect
(
url_for
(
'web.index'
))
return
"User is not allowed to edit public shelves"
,
403
return
"User is not allowed to edit public shelves"
,
403
...
@@ -67,7 +68,7 @@ def add_to_shelf(shelf_id, book_id):
...
@@ -67,7 +68,7 @@ def add_to_shelf(shelf_id, book_id):
ub
.
BookShelf
.
book_id
==
book_id
)
.
first
()
ub
.
BookShelf
.
book_id
==
book_id
)
.
first
()
if
book_in_shelf
:
if
book_in_shelf
:
log
.
error
(
"Book
%
s is already part of
%
s"
,
book_id
,
shelf
)
log
.
error
(
"Book
%
s is already part of
%
s"
,
book_id
,
shelf
)
if
not
request
.
is_
xhr
:
if
not
xhr
:
flash
(
_
(
u"Book is already part of the shelf:
%(shelfname)
s"
,
shelfname
=
shelf
.
name
),
category
=
"error"
)
flash
(
_
(
u"Book is already part of the shelf:
%(shelfname)
s"
,
shelfname
=
shelf
.
name
),
category
=
"error"
)
return
redirect
(
url_for
(
'web.index'
))
return
redirect
(
url_for
(
'web.index'
))
return
"Book is already part of the shelf:
%
s"
%
shelf
.
name
,
400
return
"Book is already part of the shelf:
%
s"
%
shelf
.
name
,
400
...
@@ -81,7 +82,7 @@ def add_to_shelf(shelf_id, book_id):
...
@@ -81,7 +82,7 @@ def add_to_shelf(shelf_id, book_id):
ins
=
ub
.
BookShelf
(
shelf
=
shelf
.
id
,
book_id
=
book_id
,
order
=
maxOrder
+
1
)
ins
=
ub
.
BookShelf
(
shelf
=
shelf
.
id
,
book_id
=
book_id
,
order
=
maxOrder
+
1
)
ub
.
session
.
add
(
ins
)
ub
.
session
.
add
(
ins
)
ub
.
session
.
commit
()
ub
.
session
.
commit
()
if
not
request
.
is_
xhr
:
if
not
xhr
:
flash
(
_
(
u"Book has been added to shelf:
%(sname)
s"
,
sname
=
shelf
.
name
),
category
=
"success"
)
flash
(
_
(
u"Book has been added to shelf:
%(sname)
s"
,
sname
=
shelf
.
name
),
category
=
"success"
)
if
"HTTP_REFERER"
in
request
.
environ
:
if
"HTTP_REFERER"
in
request
.
environ
:
return
redirect
(
request
.
environ
[
"HTTP_REFERER"
])
return
redirect
(
request
.
environ
[
"HTTP_REFERER"
])
...
@@ -147,10 +148,11 @@ def search_to_shelf(shelf_id):
...
@@ -147,10 +148,11 @@ def search_to_shelf(shelf_id):
@
shelf
.
route
(
"/shelf/remove/<int:shelf_id>/<int:book_id>"
)
@
shelf
.
route
(
"/shelf/remove/<int:shelf_id>/<int:book_id>"
)
@
login_required
@
login_required
def
remove_from_shelf
(
shelf_id
,
book_id
):
def
remove_from_shelf
(
shelf_id
,
book_id
):
xhr
=
request
.
headers
.
get
(
'X-Requested-With'
)
==
'XMLHttpRequest'
shelf
=
ub
.
session
.
query
(
ub
.
Shelf
)
.
filter
(
ub
.
Shelf
.
id
==
shelf_id
)
.
first
()
shelf
=
ub
.
session
.
query
(
ub
.
Shelf
)
.
filter
(
ub
.
Shelf
.
id
==
shelf_id
)
.
first
()
if
shelf
is
None
:
if
shelf
is
None
:
log
.
error
(
"Invalid shelf specified:
%
s"
,
shelf_id
)
log
.
error
(
"Invalid shelf specified:
%
s"
,
shelf_id
)
if
not
request
.
is_
xhr
:
if
not
xhr
:
return
redirect
(
url_for
(
'web.index'
))
return
redirect
(
url_for
(
'web.index'
))
return
"Invalid shelf specified"
,
400
return
"Invalid shelf specified"
,
400
...
@@ -169,20 +171,20 @@ def remove_from_shelf(shelf_id, book_id):
...
@@ -169,20 +171,20 @@ def remove_from_shelf(shelf_id, book_id):
if
book_shelf
is
None
:
if
book_shelf
is
None
:
log
.
error
(
"Book
%
s already removed from
%
s"
,
book_id
,
shelf
)
log
.
error
(
"Book
%
s already removed from
%
s"
,
book_id
,
shelf
)
if
not
request
.
is_
xhr
:
if
not
xhr
:
return
redirect
(
url_for
(
'web.index'
))
return
redirect
(
url_for
(
'web.index'
))
return
"Book already removed from shelf"
,
410
return
"Book already removed from shelf"
,
410
ub
.
session
.
delete
(
book_shelf
)
ub
.
session
.
delete
(
book_shelf
)
ub
.
session
.
commit
()
ub
.
session
.
commit
()
if
not
request
.
is_
xhr
:
if
not
xhr
:
flash
(
_
(
u"Book has been removed from shelf:
%(sname)
s"
,
sname
=
shelf
.
name
),
category
=
"success"
)
flash
(
_
(
u"Book has been removed from shelf:
%(sname)
s"
,
sname
=
shelf
.
name
),
category
=
"success"
)
return
redirect
(
request
.
environ
[
"HTTP_REFERER"
])
return
redirect
(
request
.
environ
[
"HTTP_REFERER"
])
return
""
,
204
return
""
,
204
else
:
else
:
log
.
error
(
"User
%
s not allowed to remove a book from
%
s"
,
current_user
,
shelf
)
log
.
error
(
"User
%
s not allowed to remove a book from
%
s"
,
current_user
,
shelf
)
if
not
request
.
is_
xhr
:
if
not
xhr
:
flash
(
_
(
u"Sorry you are not allowed to remove a book from this shelf:
%(sname)
s"
,
sname
=
shelf
.
name
),
flash
(
_
(
u"Sorry you are not allowed to remove a book from this shelf:
%(sname)
s"
,
sname
=
shelf
.
name
),
category
=
"error"
)
category
=
"error"
)
return
redirect
(
url_for
(
'web.index'
))
return
redirect
(
url_for
(
'web.index'
))
...
...
cps/web.py
View file @
e04aa80f
...
@@ -172,7 +172,7 @@ def remote_login_required(f):
...
@@ -172,7 +172,7 @@ def remote_login_required(f):
def
inner
(
*
args
,
**
kwargs
):
def
inner
(
*
args
,
**
kwargs
):
if
config
.
config_remote_login
:
if
config
.
config_remote_login
:
return
f
(
*
args
,
**
kwargs
)
return
f
(
*
args
,
**
kwargs
)
if
request
.
is_xhr
:
if
request
.
headers
.
get
(
'X-Requested-With'
)
==
'XMLHttpRequest'
:
data
=
{
'status'
:
'error'
,
'message'
:
'Forbidden'
}
data
=
{
'status'
:
'error'
,
'message'
:
'Forbidden'
}
response
=
make_response
(
json
.
dumps
(
data
,
ensure_ascii
=
False
))
response
=
make_response
(
json
.
dumps
(
data
,
ensure_ascii
=
False
))
response
.
headers
[
"Content-Type"
]
=
"application/json; charset=utf-8"
response
.
headers
[
"Content-Type"
]
=
"application/json; charset=utf-8"
...
@@ -1468,7 +1468,7 @@ def show_book(book_id):
...
@@ -1468,7 +1468,7 @@ def show_book(book_id):
audioentries
.
append
(
media_format
.
format
.
lower
())
audioentries
.
append
(
media_format
.
format
.
lower
())
return
render_title_template
(
'detail.html'
,
entry
=
entries
,
audioentries
=
audioentries
,
cc
=
cc
,
return
render_title_template
(
'detail.html'
,
entry
=
entries
,
audioentries
=
audioentries
,
cc
=
cc
,
is_xhr
=
request
.
is_xhr
,
title
=
entries
.
title
,
books_shelfs
=
book_in_shelfs
,
is_xhr
=
request
.
headers
.
get
(
'X-Requested-With'
)
==
'XMLHttpRequest'
,
title
=
entries
.
title
,
books_shelfs
=
book_in_shelfs
,
have_read
=
have_read
,
kindle_list
=
kindle_list
,
reader_list
=
reader_list
,
page
=
"book"
)
have_read
=
have_read
,
kindle_list
=
kindle_list
,
reader_list
=
reader_list
,
page
=
"book"
)
else
:
else
:
log
.
debug
(
u"Error opening eBook. File does not exist or file is not accessible:"
)
log
.
debug
(
u"Error opening eBook. File does not exist or file is not accessible:"
)
...
...
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