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
e3d416db
Commit
e3d416db
authored
Aug 17, 2017
by
OzzieIsaacs
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'adv/cover-upload'
parents
a1538e12
6f797ba4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
12 deletions
+20
-12
web.py
cps/web.py
+20
-12
No files found.
cps/web.py
View file @
e3d416db
...
...
@@ -2791,18 +2791,7 @@ def edit_book(book_id):
edited_books_id
.
add
(
book
.
id
)
book
.
author_sort
=
helper
.
get_sorted_author
(
input_authors
[
0
])
if
to_save
[
"cover_url"
]
and
os
.
path
.
splitext
(
to_save
[
"cover_url"
])[
1
]
.
lower
()
==
".jpg"
:
img
=
requests
.
get
(
to_save
[
"cover_url"
])
if
config
.
config_use_google_drive
:
tmpDir
=
tempfile
.
gettempdir
()
f
=
open
(
os
.
path
.
join
(
tmpDir
,
"uploaded_cover.jpg"
),
"wb"
)
f
.
write
(
img
.
content
)
f
.
close
()
gdriveutils
.
uploadFileToEbooksFolder
(
Gdrive
.
Instance
()
.
drive
,
os
.
path
.
join
(
book
.
path
,
'cover.jpg'
),
os
.
path
.
join
(
tmpDir
,
f
.
name
))
else
:
f
=
open
(
os
.
path
.
join
(
config
.
config_calibre_dir
,
book
.
path
,
"cover.jpg"
),
"wb"
)
f
.
write
(
img
.
content
)
f
.
close
()
if
to_save
[
"cover_url"
]
and
save_cover
(
to_save
[
"cover_url"
],
book
.
path
):
book
.
has_cover
=
1
if
book
.
series_index
!=
to_save
[
"series_index"
]:
...
...
@@ -2954,6 +2943,25 @@ def edit_book(book_id):
title
=
_
(
u"edit metadata"
))
def
save_cover
(
url
,
book_path
):
img
=
requests
.
get
(
url
)
if
img
.
headers
.
get
(
'content-type'
)
!=
'image/jpeg'
:
return
false
if
config
.
config_use_google_drive
:
tmpDir
=
tempfile
.
gettempdir
()
f
=
open
(
os
.
path
.
join
(
tmpDir
,
"uploaded_cover.jpg"
),
"wb"
)
f
.
write
(
img
.
content
)
f
.
close
()
gdriveutils
.
uploadFileToEbooksFolder
(
Gdrive
.
Instance
()
.
drive
,
os
.
path
.
join
(
book_path
,
'cover.jpg'
),
os
.
path
.
join
(
tmpDir
,
f
.
name
))
return
true
f
=
open
(
os
.
path
.
join
(
config
.
config_calibre_dir
,
book_path
,
"cover.jpg"
),
"wb"
)
f
.
write
(
img
.
content
)
f
.
close
()
return
true
@
app
.
route
(
"/upload"
,
methods
=
[
"GET"
,
"POST"
])
@
login_required_if_no_ano
@
upload_required
...
...
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