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
313116dc
Commit
313116dc
authored
Oct 30, 2016
by
OzzieIsaacs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Uploader is working on windows
parent
12db3952
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
54 deletions
+63
-54
detail.html
cps/templates/detail.html
+1
-1
uploader.py
cps/uploader.py
+4
-5
web.py
cps/web.py
+58
-48
No files found.
cps/templates/detail.html
View file @
313116dc
...
...
@@ -106,7 +106,7 @@
{% endif %}
<div
class=
"btn-group"
role=
"group"
>
<button
id=
"btnGroupDrop2"
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=
"glyphicon glyphicon-eye-open"
></span>
Read in browser
<span
class=
"caret"
></span>
</button>
<ul
class=
"dropdown-menu"
aria-labelledby=
"btnGroupDrop2"
>
...
...
cps/uploader.py
View file @
313116dc
import
os
from
tempfile
import
gettempdir
import
hashlib
from
collections
import
namedtuple
import
book_formats
tmp_dir
=
"/tmp/calibre-web"
BookMeta
=
namedtuple
(
'BookMeta'
,
'file_path, extension, title, author, cover, description, tags, series, series_id'
)
"""
:rtype: BookMeta
"""
def
upload
(
file
):
tmp_dir
=
os
.
path
.
join
(
gettempdir
(),
'calibre_web'
)
if
not
os
.
path
.
isdir
(
tmp_dir
):
os
.
mkdir
(
tmp_dir
)
filename
=
file
.
filename
filename_root
,
file_extension
=
os
.
path
.
splitext
(
filename
)
md5
=
hashlib
.
md5
()
md5
.
update
(
filename
)
md5
.
update
(
filename
.
encode
(
'utf-8'
)
)
tmp_file_path
=
os
.
path
.
join
(
tmp_dir
,
md5
.
hexdigest
())
file
.
save
(
tmp_file_path
)
meta
=
book_formats
.
process
(
tmp_file_path
,
filename_root
,
file_extension
)
...
...
cps/web.py
View file @
313116dc
...
...
@@ -544,6 +544,7 @@ def get_cover(cover_path):
@
login_required
def
read_book
(
book_id
,
format
):
book
=
db
.
session
.
query
(
db
.
Books
)
.
filter
(
db
.
Books
.
id
==
book_id
)
.
first
()
if
book
:
book_dir
=
os
.
path
.
join
(
config
.
MAIN_DIR
,
"cps"
,
"static"
,
str
(
book_id
))
if
not
os
.
path
.
exists
(
book_dir
):
os
.
mkdir
(
book_dir
)
...
...
@@ -586,6 +587,10 @@ def read_book(book_id,format):
txt_file
=
os
.
path
.
join
(
config
.
DB_ROOT
,
book
.
path
,
book
.
data
[
0
]
.
name
)
+
".txt"
copyfile
(
txt_file
,
tmp_file
)
return
render_template
(
'readtxt.html'
,
txtfile
=
all_name
,
title
=
"Read a Book"
)
else
:
flash
(
"Error opening eBook. File does not exist or file is not accessible:"
,
category
=
"error"
)
return
redirect
(
'/'
or
url_for
(
"index"
,
_external
=
True
))
@
app
.
route
(
"/download/<int:book_id>/<format>"
)
@
login_required
...
...
@@ -1167,14 +1172,15 @@ def upload():
file
=
request
.
files
[
'btn-upload'
]
meta
=
uploader
.
upload
(
file
)
title
=
meta
.
title
author
=
meta
.
author
title
=
meta
.
title
.
encode
(
'utf-8'
)
author
=
meta
.
author
.
encode
(
'utf-8'
)
title_dir
=
helper
.
get_valid_filename
(
title
.
decode
(
'utf-8'
),
False
)
author_dir
=
helper
.
get_valid_filename
(
author
.
decode
(
'utf-8'
),
False
)
data_name
=
title_dir
filepath
=
config
.
DB_ROOT
+
"/"
+
author_dir
+
"/"
+
title_dir
saved_filename
=
filepath
+
"/"
+
data_name
+
meta
.
extension
filepath
=
config
.
DB_ROOT
+
os
.
sep
+
author_dir
+
os
.
sep
+
title_dir
saved_filename
=
filepath
+
os
.
sep
+
data_name
+
meta
.
extension
if
not
os
.
path
.
exists
(
filepath
):
try
:
os
.
makedirs
(
filepath
)
...
...
@@ -1182,10 +1188,14 @@ def upload():
flash
(
"Failed to create path
%
s (Permission denied)."
%
filepath
,
category
=
"error"
)
return
redirect
(
url_for
(
'index'
,
_external
=
True
))
try
:
mov
e
(
meta
.
file_path
,
saved_filename
)
except
OSError
:
copyfil
e
(
meta
.
file_path
,
saved_filename
)
except
OSError
,
e
:
flash
(
"Failed to store file
%
s (Permission denied)."
%
saved_filename
,
category
=
"error"
)
return
redirect
(
url_for
(
'index'
,
_external
=
True
))
try
:
os
.
unlink
(
meta
.
file_path
)
except
OSError
,
e
:
flash
(
"Failed to delete file
%
s (Permission denied)."
%
meta
.
file_path
,
category
=
"warning"
)
file_size
=
os
.
path
.
getsize
(
saved_filename
)
if
meta
.
cover
is
None
:
...
...
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