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
28dac341
Unverified
Commit
28dac341
authored
Jan 11, 2018
by
Andriy Zasypkin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto select format if only one
parent
e66068d6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
37 deletions
+58
-37
detail.html
cps/templates/detail.html
+28
-15
web.py
cps/web.py
+30
-22
No files found.
cps/templates/detail.html
View file @
28dac341
...
...
@@ -41,22 +41,35 @@
{% if g.user.kindle_mail and g.user.is_authenticated %}
<a
href=
"{{url_for('send_to_kindle', book_id=entry.id)}}"
id=
"sendbtn"
class=
"btn btn-primary"
role=
"button"
><span
class=
"glyphicon glyphicon-send"
></span>
{{_('Send to Kindle')}}
</a>
{% endif %}
{% if (g.user.role_download() and g.user.is_anonymous) or g.user.is_authenticated %}
<div
class=
"btn-group"
role=
"group"
>
<button
id=
"read-in-browser"
type=
"button"
class=
"btn btn-primary dropdown-toggle"
data-toggle=
"dropdown"
aria-haspopup=
"true"
aria-expanded=
"false"
>
<span
class=
"glyphicon glyphicon-eye-open"
></span>
{{_('Read in browser')}}
<span
class=
"caret"
></span>
</button>
<ul
class=
"dropdown-menu"
aria-labelledby=
"read-in-browser"
>
{% for format in entry.data %}
{%if format.format|lower == 'epub' or format.format|lower == 'txt' or format.format|lower == 'pdf' or ( format.format|lower == 'cbr' and rarsupport ) or format.format|lower == 'cbt' or format.format|lower == 'cbz' %}
<li><a
target=
"_blank"
href=
"{{ url_for('read_book', book_id=entry.id, book_format=format.format|lower) }}"
>
{{format.format}}
</a></li>
{% endif %}
{%endfor%}
</ul>
</div>
{% endif %}
{% if (g.user.role_download() and g.user.is_anonymous) or g.user.is_authenticated %}
{% with formats = entry.data|select('canread')|list %}
{% if formats|length == 1 %}
{% set format = formats|first %}
<div
class=
"btn-group"
role=
"group"
>
<a
target=
"_blank"
class=
"btn btn-primary"
href=
"{{ url_for('read_book', book_id=entry.id, book_format=format.format|lower) }}"
>
{{format.format}}
<span
class=
"glyphicon glyphicon-eye-open"
></span>
{{_('Read in browser')}}
</a>
</div>
{% elif formats|length > 1 %}
<div
class=
"btn-group"
role=
"group"
>
<button
id=
"read-in-browser"
type=
"button"
class=
"btn btn-primary dropdown-toggle"
data-toggle=
"dropdown"
aria-haspopup=
"true"
aria-expanded=
"false"
>
<span
class=
"glyphicon glyphicon-eye-open"
></span>
{{_('Read in browser')}}
<span
class=
"caret"
></span>
</button>
<ul
class=
"dropdown-menu"
aria-labelledby=
"read-in-browser"
>
{% for format in formats %}
{%if format.format|lower|canread %}
<li><a
target=
"_blank"
href=
"{{ url_for('read_book', book_id=entry.id, book_format=format.format|lower) }}"
>
{{format.format}}
</a></li>
{% endif %}
{%endfor%}
</ul>
</div>
{%else%}
{{formats|length}}
{%endif%}
{%endwith%}
{%endif%}
</div>
</div>
<h2>
{{entry.title}}
</h2>
...
...
cps/web.py
View file @
28dac341
...
...
@@ -116,6 +116,7 @@ gdrive_watch_callback_token = 'target=calibreweb-watch_files'
global_task
=
None
ALLOWED_EXTENSIONS
=
set
([
'txt'
,
'pdf'
,
'epub'
,
'mobi'
,
'azw'
,
'azw3'
,
'cbr'
,
'cbz'
,
'cbt'
,
'djvu'
,
'prc'
,
'doc'
,
'docx'
,
'fb2'
])
READER_EXTENSIONS
=
set
([
'txt'
,
'pdf'
,
'epub'
,
'zip'
,
'cbz'
,
'tar'
,
'cbt'
]
+
([
'rar'
,
'cbr'
]
if
rar_support
else
[]))
def
md5
(
fname
):
hash_md5
=
hashlib
.
md5
()
...
...
@@ -473,6 +474,14 @@ def yesno(value, yes, no):
return
yes
if
value
else
no
@
app
.
template_filter
(
'canread'
)
@
app
.
template_test
(
'canread'
)
def
canread
(
ext
):
if
type
(
ext
)
==
db
.
Data
:
ext
=
ext
.
format
return
ext
.
lower
()
in
READER_EXTENSIONS
def
admin_required
(
f
):
"""
Checks if current_user.role == 1
...
...
@@ -937,10 +946,8 @@ def get_comic_book(book_id, book_format, page):
rarfile
.
UNRAR_TOOL
=
config
.
config_rarfile_location
try
:
rf
=
rarfile
.
RarFile
(
cbr_file
)
rarNames
=
sort
(
rf
.
namelist
())
b64
=
codecs
.
encode
(
rf
.
read
(
rarNames
[
page
]),
'base64'
)
.
decode
()
extractedfile
=
"data:image/png;base64,"
+
b64
fileData
=
{
"name"
:
rarNames
[
page
],
"page"
:
page
,
"last"
:
rarNames
.
__len__
()
-
1
,
"content"
:
extractedfile
}
names
=
sort
(
rf
.
namelist
())
extract
=
lambda
page
:
rf
.
read
(
names
[
page
])
except
:
# rarfile not valid
app
.
logger
.
error
(
'Unrar binary not found, or unable to decompress file '
+
cbr_file
)
...
...
@@ -949,25 +956,27 @@ def get_comic_book(book_id, book_format, page):
app
.
logger
.
info
(
'Unrar is not supported please install python rarfile extension'
)
# no support means return nothing
return
""
,
204
if
book_format
in
(
"cbz"
,
"zip"
):
el
if
book_format
in
(
"cbz"
,
"zip"
):
zf
=
zipfile
.
ZipFile
(
cbr_file
)
zipNames
=
sort
(
zf
.
namelist
())
if
sys
.
version_info
.
major
>=
3
:
b64
=
codecs
.
encode
(
zf
.
read
(
zipNames
[
page
]),
'base64'
)
.
decode
()
else
:
b64
=
zf
.
read
(
zipNames
[
page
])
.
encode
(
'base64'
)
extractedfile
=
"data:image/png;base64,"
+
b64
fileData
=
{
"name"
:
zipNames
[
page
],
"page"
:
page
,
"last"
:
zipNames
.
__len__
()
-
1
,
"content"
:
extractedfile
}
if
book_format
in
(
"cbt"
,
"tar"
):
names
=
sort
(
zf
.
namelist
())
extract
=
lambda
page
:
zf
.
read
(
names
[
page
])
elif
book_format
in
(
"cbt"
,
"tar"
):
tf
=
tarfile
.
TarFile
(
cbr_file
)
tarNames
=
sort
(
tf
.
getnames
())
if
sys
.
version_info
.
major
>=
3
:
b64
=
codecs
.
encode
(
tf
.
extractfile
(
tarNames
[
page
])
.
read
(),
'base64'
)
.
decode
()
else
:
b64
=
(
tf
.
extractfile
(
tarNames
[
page
])
.
read
())
.
encode
(
'base64'
)
extractedfile
=
"data:image/png;base64,"
+
bs
fileData
=
{
"name"
:
tarNames
[
page
],
"page"
:
page
,
"last"
:
tarNames
.
__len__
()
-
1
,
"content"
:
extractedfile
}
names
=
sort
(
tf
.
getnames
())
extract
=
lambda
page
:
tf
.
extractfile
(
names
[
page
])
.
read
()
else
:
app
.
logger
.
error
(
'unsupported comic format'
)
return
""
,
204
if
sys
.
version_info
.
major
>=
3
:
b64
=
codecs
.
encode
(
extract
(
page
),
'base64'
)
.
decode
()
else
:
b64
=
extract
(
page
)
.
encode
(
'base64'
)
ext
=
names
[
page
]
.
rpartition
(
'.'
)[
-
1
]
if
ext
not
in
(
'png'
,
'gif'
,
'jpg'
,
'jpeg'
):
ext
=
'png'
extractedfile
=
"data:image/"
+
ext
+
";base64,"
+
b64
fileData
=
{
"name"
:
names
[
page
],
"page"
:
page
,
"last"
:
len
(
names
)
-
1
,
"content"
:
extractedfile
}
return
make_response
(
json
.
dumps
(
fileData
))
return
""
,
204
...
...
@@ -3264,4 +3273,3 @@ def start_gevent():
app
.
logger
.
info
(
'Unable to listen on
\'\'
, trying on IPv4 only...'
)
gevent_server
=
WSGIServer
((
'0.0.0.0'
,
ub
.
config
.
config_port
),
app
)
gevent_server
.
serve_forever
()
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