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
bbf609b8
Commit
bbf609b8
authored
Feb 13, 2021
by
Ozzie Isaacs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #1859 (Upload of jpg files without installed imagemagick doesn't work)
parent
3c1b0687
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
16 deletions
+23
-16
helper.py
cps/helper.py
+23
-16
No files found.
cps/helper.py
View file @
bbf609b8
...
...
@@ -32,7 +32,7 @@ from tempfile import gettempdir
import
requests
from
babel.dates
import
format_datetime
from
babel.units
import
format_unit
from
flask
import
send_from_directory
,
make_response
,
redirect
,
abort
,
url_for
,
request
from
flask
import
send_from_directory
,
make_response
,
redirect
,
abort
,
url_for
from
flask_babel
import
gettext
as
_
from
flask_login
import
current_user
from
sqlalchemy.sql.expression
import
true
,
false
,
and_
,
text
...
...
@@ -592,22 +592,29 @@ def save_cover_from_url(url, book_path):
def
save_cover_from_filestorage
(
filepath
,
saved_filename
,
img
):
if
hasattr
(
img
,
"metadata"
):
img
.
save
(
filename
=
os
.
path
.
join
(
filepath
,
saved_filename
))
img
.
close
()
else
:
# check if file path exists, otherwise create it, copy file to calibre path and delete temp file
if
not
os
.
path
.
exists
(
filepath
):
try
:
os
.
makedirs
(
filepath
)
except
OSError
:
log
.
error
(
u"Failed to create path for cover"
)
return
False
,
_
(
u"Failed to create path for cover"
)
# check if file path exists, otherwise create it, copy file to calibre path and delete temp file
if
not
os
.
path
.
exists
(
filepath
):
try
:
img
.
save
(
os
.
path
.
join
(
filepath
,
saved_filename
))
except
(
IOError
,
OSError
):
log
.
error
(
u"Cover-file is not a valid image file, or could not be stored"
)
return
False
,
_
(
u"Cover-file is not a valid image file, or could not be stored"
)
os
.
makedirs
(
filepath
)
except
OSError
:
log
.
error
(
u"Failed to create path for cover"
)
return
False
,
_
(
u"Failed to create path for cover"
)
try
:
# upload of jgp file without wand
if
isinstance
(
img
,
requests
.
Response
):
with
open
(
os
.
path
.
join
(
filepath
,
saved_filename
),
'wb'
)
as
f
:
f
.
write
(
img
.
content
)
else
:
if
hasattr
(
img
,
"metadata"
):
# upload of jpg/png... via url
img
.
save
(
filename
=
os
.
path
.
join
(
filepath
,
saved_filename
))
img
.
close
()
else
:
# upload of jpg/png... from hdd
img
.
save
(
os
.
path
.
join
(
filepath
,
saved_filename
))
except
(
IOError
,
OSError
):
log
.
error
(
u"Cover-file is not a valid image file, or could not be stored"
)
return
False
,
_
(
u"Cover-file is not a valid image file, or could not be stored"
)
return
True
,
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