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
34abf95f
Commit
34abf95f
authored
Aug 18, 2018
by
Ozzie Isaacs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix for empty filename during edit
parent
7dac87fa
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
34 deletions
+36
-34
web.py
cps/web.py
+36
-34
No files found.
cps/web.py
100755 → 100644
View file @
34abf95f
...
@@ -3055,48 +3055,50 @@ def edit_book(book_id):
...
@@ -3055,48 +3055,50 @@ def edit_book(book_id):
# Check and handle Uploaded file
# Check and handle Uploaded file
if
'btn-upload-format'
in
request
.
files
:
if
'btn-upload-format'
in
request
.
files
:
requested_file
=
request
.
files
[
'btn-upload-format'
]
requested_file
=
request
.
files
[
'btn-upload-format'
]
if
'.'
in
requested_file
.
filename
:
# check for empty request
file_ext
=
requested_file
.
filename
.
rsplit
(
'.'
,
1
)[
-
1
]
.
lower
()
if
requested_file
.
filename
!=
''
:
if
file_ext
not
in
ALLOWED_EXTENSIONS
:
if
'.'
in
requested_file
.
filename
:
flash
(
_
(
'File extension "
%
s" is not allowed to be uploaded to this server'
%
file_ext
),
category
=
"error"
)
file_ext
=
requested_file
.
filename
.
rsplit
(
'.'
,
1
)[
-
1
]
.
lower
()
if
file_ext
not
in
ALLOWED_EXTENSIONS
:
flash
(
_
(
'File extension "
%
s" is not allowed to be uploaded to this server'
%
file_ext
),
category
=
"error"
)
return
redirect
(
url_for
(
'show_book'
,
book_id
=
book
.
id
))
else
:
flash
(
_
(
'File to be uploaded must have an extension'
),
category
=
"error"
)
return
redirect
(
url_for
(
'show_book'
,
book_id
=
book
.
id
))
return
redirect
(
url_for
(
'show_book'
,
book_id
=
book
.
id
))
else
:
flash
(
_
(
'File to be uploaded must have an extension'
),
category
=
"error"
)
return
redirect
(
url_for
(
'show_book'
,
book_id
=
book
.
id
))
file_name
=
book
.
path
.
rsplit
(
'/'
,
1
)[
-
1
]
file_name
=
book
.
path
.
rsplit
(
'/'
,
1
)[
-
1
]
filepath
=
os
.
path
.
normpath
(
os
.
path
.
join
(
config
.
config_calibre_dir
,
book
.
path
))
filepath
=
os
.
path
.
normpath
(
os
.
path
.
join
(
config
.
config_calibre_dir
,
book
.
path
))
saved_filename
=
os
.
path
.
join
(
filepath
,
file_name
+
'.'
+
file_ext
)
saved_filename
=
os
.
path
.
join
(
filepath
,
file_name
+
'.'
+
file_ext
)
# check if file path exists, otherwise create it, copy file to calibre path and delete temp file
# check if file path exists, otherwise create it, copy file to calibre path and delete temp file
if
not
os
.
path
.
exists
(
filepath
):
if
not
os
.
path
.
exists
(
filepath
):
try
:
os
.
makedirs
(
filepath
)
except
OSError
:
flash
(
_
(
u"Failed to create path
%
s (Permission denied)."
%
filepath
),
category
=
"error"
)
return
redirect
(
url_for
(
'show_book'
,
book_id
=
book
.
id
))
try
:
try
:
os
.
makedirs
(
filepath
)
requested_file
.
save
(
saved_filename
)
except
OSError
:
except
OSError
:
flash
(
_
(
u"Failed to
create path
%
s (Permission denied)."
%
filepath
),
category
=
"error"
)
flash
(
_
(
u"Failed to
store file
%
s."
%
saved_filename
),
category
=
"error"
)
return
redirect
(
url_for
(
'show_book'
,
book_id
=
book
.
id
))
return
redirect
(
url_for
(
'show_book'
,
book_id
=
book
.
id
))
try
:
requested_file
.
save
(
saved_filename
)
except
OSError
:
flash
(
_
(
u"Failed to store file
%
s."
%
saved_filename
),
category
=
"error"
)
return
redirect
(
url_for
(
'show_book'
,
book_id
=
book
.
id
))
file_size
=
os
.
path
.
getsize
(
saved_filename
)
file_size
=
os
.
path
.
getsize
(
saved_filename
)
is_format
=
db
.
session
.
query
(
db
.
Data
)
.
filter
(
db
.
Data
.
book
==
book_id
)
.
filter
(
db
.
Data
.
format
==
file_ext
.
upper
())
.
first
()
is_format
=
db
.
session
.
query
(
db
.
Data
)
.
filter
(
db
.
Data
.
book
==
book_id
)
.
filter
(
db
.
Data
.
format
==
file_ext
.
upper
())
.
first
()
# Format entry already exists, no need to update the database
if
is_format
:
app
.
logger
.
info
(
'Book format already existing'
)
else
:
db_format
=
db
.
Data
(
book_id
,
file_ext
.
upper
(),
file_size
,
file_name
)
db
.
session
.
add
(
db_format
)
db
.
session
.
commit
()
db
.
session
.
connection
()
.
connection
.
connection
.
create_function
(
"title_sort"
,
1
,
db
.
title_sort
)
# Queue uploader info
# Format entry already exists, no need to update the database
uploadText
=
_
(
u"File format
%
s added to
%
s"
%
(
file_ext
.
upper
(),
book
.
title
))
if
is_format
:
helper
.
global_WorkerThread
.
add_upload
(
current_user
.
nickname
,
app
.
logger
.
info
(
'Book format already existing'
)
"<a href=
\"
"
+
url_for
(
'show_book'
,
book_id
=
book
.
id
)
+
"
\"
>"
+
uploadText
+
"</a>"
)
else
:
db_format
=
db
.
Data
(
book_id
,
file_ext
.
upper
(),
file_size
,
file_name
)
db
.
session
.
add
(
db_format
)
db
.
session
.
commit
()
db
.
session
.
connection
()
.
connection
.
connection
.
create_function
(
"title_sort"
,
1
,
db
.
title_sort
)
# Queue uploader info
uploadText
=
_
(
u"File format
%
s added to
%
s"
%
(
file_ext
.
upper
(),
book
.
title
))
helper
.
global_WorkerThread
.
add_upload
(
current_user
.
nickname
,
"<a href=
\"
"
+
url_for
(
'show_book'
,
book_id
=
book
.
id
)
+
"
\"
>"
+
uploadText
+
"</a>"
)
to_save
=
request
.
form
.
to_dict
()
to_save
=
request
.
form
.
to_dict
()
...
...
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