mirror of
				https://github.com/janeczku/calibre-web
				synced 2025-10-31 15:23:02 +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:
		 Matt Hazinski
					Matt Hazinski
				
			
				
					committed by
					
						 Ozzie Isaacs
						Ozzie Isaacs
					
				
			
			
				
	
			
			
			 Ozzie Isaacs
						Ozzie Isaacs
					
				
			
						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" | ||||||
|   | |||||||
| @@ -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): | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user