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
4b8fdb04
Commit
4b8fdb04
authored
Jan 15, 2017
by
OzzieIsaacs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improvement mimetypes for downloaded files
parent
99430fc9
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
33 deletions
+41
-33
feed.xml
cps/templates/feed.xml
+1
-16
web.py
cps/web.py
+40
-17
No files found.
cps/templates/feed.xml
View file @
4b8fdb04
...
@@ -56,22 +56,7 @@
...
@@ -56,22 +56,7 @@
{% endif %}
{% endif %}
{% for format in entry.data %}
{% for format in entry.data %}
<link
rel=
"http://opds-spec.org/acquisition"
href=
"{{ url_for('get_opds_download_link', book_id=entry.id, format=format.format|lower)}}"
<link
rel=
"http://opds-spec.org/acquisition"
href=
"{{ url_for('get_opds_download_link', book_id=entry.id, format=format.format|lower)}}"
length=
"{{format.uncompressed_size}}"
mtime=
"{{entry.timestamp}}"
length=
"{{format.uncompressed_size}}"
mtime=
"{{entry.timestamp}}"
type=
"{{format.format|lower|mimetype}}"
/>
{%
if
format.format|
lower =
=
"epub"
%}
type=
"application/epub+zip"
/>
{% elif format.format|lower == "cbr" %}
type="application/x-cbr"/>
{% elif format.format|lower == "mobi" %}
type="application/x-mobipocket-ebook"/>
{% elif format.format|lower == "pdf" %}
type="application/pdf"/>
{% elif format.format|lower == "rtf" %}
type="text/rtf"/>
{% elif format.format|lower == "txt" %}
type="text/plain"/>
{% elif format.format|lower == "doc" %}
type="application/msword"/>
{% endif %}
{% endfor %}
{% endfor %}
</entry>
</entry>
{% endfor %}
{% endfor %}
...
...
cps/web.py
View file @
4b8fdb04
...
@@ -47,7 +47,16 @@ except ImportError, e:
...
@@ -47,7 +47,16 @@ except ImportError, e:
from
shutil
import
copyfile
from
shutil
import
copyfile
from
cgi
import
escape
from
cgi
import
escape
mimetypes
.
init
()
mimetypes
.
add_type
(
'application/xhtml+xml'
,
'.xhtml'
)
mimetypes
.
add_type
(
'application/xhtml+xml'
,
'.xhtml'
)
mimetypes
.
add_type
(
'application/epub+zip'
,
'.epub'
)
mimetypes
.
add_type
(
'application/x-mobipocket-ebook'
,
'.mobi'
)
mimetypes
.
add_type
(
'application/x-mobipocket-ebook'
,
'.prc'
)
mimetypes
.
add_type
(
'application/vnd.amazon.ebook'
,
'.azw'
)
mimetypes
.
add_type
(
'application/x-cbr'
,
'.cbr'
)
mimetypes
.
add_type
(
'application/x-cbz'
,
'.cbz'
)
mimetypes
.
add_type
(
'application/x-cbt'
,
'.cbt'
)
mimetypes
.
add_type
(
'image/vnd.djvu'
,
'.djvu'
)
class
ReverseProxied
(
object
):
class
ReverseProxied
(
object
):
...
@@ -262,6 +271,14 @@ def shortentitle_filter(s):
...
@@ -262,6 +271,14 @@ def shortentitle_filter(s):
s
=
textwrap
.
wrap
(
s
,
60
,
break_long_words
=
False
)[
0
]
+
' [...]'
s
=
textwrap
.
wrap
(
s
,
60
,
break_long_words
=
False
)[
0
]
+
' [...]'
return
s
return
s
@
app
.
template_filter
(
'mimetype'
)
def
mimetype_filter
(
val
):
try
:
s
=
mimetypes
.
types_map
[
'.'
+
val
]
except
:
s
=
'application/octet-stream'
return
s
def
admin_required
(
f
):
def
admin_required
(
f
):
"""
"""
...
@@ -1113,6 +1130,7 @@ def get_download_link(book_id, format):
...
@@ -1113,6 +1130,7 @@ def get_download_link(book_id, format):
format
=
format
.
split
(
"."
)[
0
]
format
=
format
.
split
(
"."
)[
0
]
book
=
db
.
session
.
query
(
db
.
Books
)
.
filter
(
db
.
Books
.
id
==
book_id
)
.
first
()
book
=
db
.
session
.
query
(
db
.
Books
)
.
filter
(
db
.
Books
.
id
==
book_id
)
.
first
()
data
=
db
.
session
.
query
(
db
.
Data
)
.
filter
(
db
.
Data
.
book
==
book
.
id
)
.
filter
(
db
.
Data
.
format
==
format
.
upper
())
.
first
()
data
=
db
.
session
.
query
(
db
.
Data
)
.
filter
(
db
.
Data
.
book
==
book
.
id
)
.
filter
(
db
.
Data
.
format
==
format
.
upper
())
.
first
()
if
data
:
if
current_user
.
is_authenticated
:
# collect downloaded books only for registered user and not for anonymous user
if
current_user
.
is_authenticated
:
# collect downloaded books only for registered user and not for anonymous user
helper
.
update_download
(
book_id
,
int
(
current_user
.
id
))
helper
.
update_download
(
book_id
,
int
(
current_user
.
id
))
author
=
helper
.
get_normalized_author
(
book
.
author_sort
)
author
=
helper
.
get_normalized_author
(
book
.
author_sort
)
...
@@ -1121,6 +1139,10 @@ def get_download_link(book_id, format):
...
@@ -1121,6 +1139,10 @@ def get_download_link(book_id, format):
file_name
=
author
+
'-'
+
file_name
file_name
=
author
+
'-'
+
file_name
file_name
=
helper
.
get_valid_filename
(
file_name
)
file_name
=
helper
.
get_valid_filename
(
file_name
)
response
=
make_response
(
send_from_directory
(
os
.
path
.
join
(
config
.
DB_ROOT
,
book
.
path
),
data
.
name
+
"."
+
format
))
response
=
make_response
(
send_from_directory
(
os
.
path
.
join
(
config
.
DB_ROOT
,
book
.
path
),
data
.
name
+
"."
+
format
))
try
:
response
.
headers
[
"Content-Type"
]
=
mimetypes
.
types_map
[
'.'
+
format
]
except
:
pass
response
.
headers
[
"Content-Disposition"
]
=
\
response
.
headers
[
"Content-Disposition"
]
=
\
"attachment; "
\
"attachment; "
\
"filename={utf_filename}.{suffix};"
\
"filename={utf_filename}.{suffix};"
\
...
@@ -1129,7 +1151,8 @@ def get_download_link(book_id, format):
...
@@ -1129,7 +1151,8 @@ def get_download_link(book_id, format):
suffix
=
format
suffix
=
format
)
)
return
response
return
response
else
:
abort
(
404
)
@
app
.
route
(
'/register'
,
methods
=
[
'GET'
,
'POST'
])
@
app
.
route
(
'/register'
,
methods
=
[
'GET'
,
'POST'
])
def
register
():
def
register
():
...
...
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