mirror of
https://github.com/janeczku/calibre-web
synced 2024-12-25 09:30:31 +00:00
* Ensure file paths in uploads are non-empty, fix #183 * Fix AttributeError in process(), handle strings of spaces
This commit is contained in:
parent
ede8ae6742
commit
6f7a240ce2
@ -41,16 +41,21 @@ except ImportError as e:
|
|||||||
|
|
||||||
|
|
||||||
def process(tmp_file_path, original_file_name, original_file_extension):
|
def process(tmp_file_path, original_file_name, original_file_extension):
|
||||||
|
meta = None
|
||||||
try:
|
try:
|
||||||
if ".PDF" == original_file_extension.upper():
|
if ".PDF" == original_file_extension.upper():
|
||||||
return pdf_meta(tmp_file_path, original_file_name, original_file_extension)
|
meta = pdf_meta(tmp_file_path, original_file_name, original_file_extension)
|
||||||
if ".EPUB" == original_file_extension.upper() and use_epub_meta is True:
|
if ".EPUB" == original_file_extension.upper() and use_epub_meta is True:
|
||||||
return epub.get_epub_info(tmp_file_path, original_file_name, original_file_extension)
|
meta = epub.get_epub_info(tmp_file_path, original_file_name, original_file_extension)
|
||||||
if ".FB2" == original_file_extension.upper() and use_fb2_meta is True:
|
if ".FB2" == original_file_extension.upper() and use_fb2_meta is True:
|
||||||
return fb2.get_fb2_info(tmp_file_path, original_file_extension)
|
meta = fb2.get_fb2_info(tmp_file_path, original_file_extension)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning('cannot parse metadata, using default: %s', e)
|
logger.warning('cannot parse metadata, using default: %s', e)
|
||||||
return default_meta(tmp_file_path, original_file_name, original_file_extension)
|
|
||||||
|
if meta and meta.title.strip() and meta.author.strip():
|
||||||
|
return meta
|
||||||
|
else:
|
||||||
|
return default_meta(tmp_file_path, original_file_name, original_file_extension)
|
||||||
|
|
||||||
|
|
||||||
def default_meta(tmp_file_path, original_file_name, original_file_extension):
|
def default_meta(tmp_file_path, original_file_name, original_file_extension):
|
||||||
@ -76,8 +81,8 @@ def pdf_meta(tmp_file_path, original_file_name, original_file_extension):
|
|||||||
doc_info = None
|
doc_info = None
|
||||||
|
|
||||||
if doc_info is not None:
|
if doc_info is not None:
|
||||||
author = doc_info.author if doc_info.author is not None else u"Unknown"
|
author = doc_info.author if doc_info.author else u"Unknown"
|
||||||
title = doc_info.title if doc_info.title is not None else original_file_name
|
title = doc_info.title if doc_info.title else original_file_name
|
||||||
subject = doc_info.subject
|
subject = doc_info.subject
|
||||||
else:
|
else:
|
||||||
author = u"Unknown"
|
author = u"Unknown"
|
||||||
@ -115,4 +120,4 @@ def get_versions():
|
|||||||
PVersion=PyPdfVersion
|
PVersion=PyPdfVersion
|
||||||
else:
|
else:
|
||||||
PVersion=_(u'not installed')
|
PVersion=_(u'not installed')
|
||||||
return {'ImageVersion':IVersion,'PyPdfVersion':PVersion}
|
return {'ImageVersion':IVersion,'PyPdfVersion':PVersion}
|
||||||
|
@ -89,7 +89,7 @@ def get_epub_info(tmp_file_path, original_file_name, original_file_extension):
|
|||||||
else:
|
else:
|
||||||
coverfile = extractCover(epubZip, coversection[0], coverpath, tmp_file_path)
|
coverfile = extractCover(epubZip, coversection[0], coverpath, tmp_file_path)
|
||||||
|
|
||||||
if epub_metadata['title'] is None:
|
if not epub_metadata['title']:
|
||||||
title = original_file_name
|
title = original_file_name
|
||||||
else:
|
else:
|
||||||
title = epub_metadata['title']
|
title = epub_metadata['title']
|
||||||
|
@ -261,6 +261,9 @@ def get_valid_filename(value, replace_whitespace=True):
|
|||||||
value = re.sub('[\*\+:\\\"/<>\?]+', u'_', value, flags=re.U)
|
value = re.sub('[\*\+:\\\"/<>\?]+', u'_', value, flags=re.U)
|
||||||
|
|
||||||
value = value[:128]
|
value = value[:128]
|
||||||
|
if not value:
|
||||||
|
raise ValueError("Filename cannot be empty")
|
||||||
|
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def get_sorted_author(value):
|
def get_sorted_author(value):
|
||||||
|
Loading…
Reference in New Issue
Block a user