mirror of
				https://github.com/janeczku/calibre-web
				synced 2025-10-31 15:23:02 +00:00 
			
		
		
		
	Added error messages in log and UI if cover url can't downloaded, changed label for cover URL to clarify function #449
This commit is contained in:
		| @@ -48,7 +48,7 @@ | |||||||
|       <input type="number"  name="rating" id="rating" class="rating input-lg" data-clearable="" value="{% if book.ratings %}{{(book.ratings[0].rating / 2)|int}}{% endif %}"> |       <input type="number"  name="rating" id="rating" class="rating input-lg" data-clearable="" value="{% if book.ratings %}{{(book.ratings[0].rating / 2)|int}}{% endif %}"> | ||||||
|     </div> |     </div> | ||||||
|     <div class="form-group"> |     <div class="form-group"> | ||||||
|       <label for="cover_url">{{_('Cover URL (jpg)')}}</label> |       <label for="cover_url">{{_('Cover URL (jpg, cover is downloaded and stored in database, field is afterwards empty again)')}}</label> | ||||||
|       <input type="text" class="form-control" name="cover_url" id="cover_url" value=""> |       <input type="text" class="form-control" name="cover_url" id="cover_url" value=""> | ||||||
|     </div> |     </div> | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										10
									
								
								cps/web.py
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								cps/web.py
									
									
									
									
									
								
							| @@ -3002,8 +3002,11 @@ def edit_book(book_id): | |||||||
|         updateGdriveCalibreFromLocal() |         updateGdriveCalibreFromLocal() | ||||||
|  |  | ||||||
|     if not error: |     if not error: | ||||||
|         if to_save["cover_url"] and save_cover(to_save["cover_url"], book.path): |         if to_save["cover_url"]: | ||||||
|             book.has_cover = 1 |             if save_cover(to_save["cover_url"], book.path) is true: | ||||||
|  |                 book.has_cover = 1 | ||||||
|  |             else: | ||||||
|  |                 flash(_(u"Cover is not a jpg file, can't save"), category="error") | ||||||
|  |  | ||||||
|         if book.series_index != to_save["series_index"]: |         if book.series_index != to_save["series_index"]: | ||||||
|             book.series_index = to_save["series_index"] |             book.series_index = to_save["series_index"] | ||||||
| @@ -3155,6 +3158,7 @@ def edit_book(book_id): | |||||||
| def save_cover(url, book_path): | def save_cover(url, book_path): | ||||||
|     img = requests.get(url) |     img = requests.get(url) | ||||||
|     if img.headers.get('content-type') != 'image/jpeg': |     if img.headers.get('content-type') != 'image/jpeg': | ||||||
|  |         app.logger.error("Cover is no jpg file, can't save") | ||||||
|         return false |         return false | ||||||
|  |  | ||||||
|     if config.config_use_google_drive: |     if config.config_use_google_drive: | ||||||
| @@ -3163,11 +3167,13 @@ def save_cover(url, book_path): | |||||||
|         f.write(img.content) |         f.write(img.content) | ||||||
|         f.close() |         f.close() | ||||||
|         gdriveutils.uploadFileToEbooksFolder(Gdrive.Instance().drive, os.path.join(book_path, 'cover.jpg'), os.path.join(tmpDir, f.name)) |         gdriveutils.uploadFileToEbooksFolder(Gdrive.Instance().drive, os.path.join(book_path, 'cover.jpg'), os.path.join(tmpDir, f.name)) | ||||||
|  |         app.logger.info("Cover is saved on gdrive") | ||||||
|         return true |         return true | ||||||
|  |  | ||||||
|     f = open(os.path.join(config.config_calibre_dir, book_path, "cover.jpg"), "wb") |     f = open(os.path.join(config.config_calibre_dir, book_path, "cover.jpg"), "wb") | ||||||
|     f.write(img.content) |     f.write(img.content) | ||||||
|     f.close() |     f.close() | ||||||
|  |     app.logger.info("Cover is saved") | ||||||
|     return true |     return true | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 OzzieIsaacs
					OzzieIsaacs