mirror of
https://github.com/calibrain/shelfmark.git
synced 2026-10-05 16:21:11 +01:00
@@ -239,19 +239,19 @@ def api_local_download() -> Union[Response, Tuple[Response, int]]:
|
||||
return jsonify({"error": "No book ID provided"}), 400
|
||||
|
||||
try:
|
||||
file_data, file_name = backend.get_book_data(book_id)
|
||||
file_data, book_info = backend.get_book_data(book_id)
|
||||
if file_data is None:
|
||||
# Book data not found or not available
|
||||
return jsonify({"error": "File not found"}), 404
|
||||
# Santize the file name
|
||||
file_name = re.sub(r'[\\/:*?"<>|]', '_', file_name.strip())[:255]
|
||||
file_name = book_info.title
|
||||
file_name = re.sub(r'[\\/:*?"<>|]', '_', file_name.strip())[:245]
|
||||
file_extension = book_info.format
|
||||
# Prepare the file for sending to the client
|
||||
epub_file = io.BytesIO(file_data)
|
||||
# Typically EPUB mime-type: 'application/epub+zip'
|
||||
data = io.BytesIO(file_data)
|
||||
return send_file(
|
||||
epub_file,
|
||||
mimetype='application/epub+zip',
|
||||
download_name=f"{file_name}.epub",
|
||||
data,
|
||||
download_name=f"{file_name}.{file_extension}",
|
||||
as_attachment=True
|
||||
)
|
||||
|
||||
|
||||
+2
-2
@@ -84,7 +84,7 @@ def queue_status() -> Dict[str, Dict[str, Any]]:
|
||||
for status_type, books in status.items()
|
||||
}
|
||||
|
||||
def get_book_data(book_id: str) -> Tuple[Optional[bytes], str] :
|
||||
def get_book_data(book_id: str) -> Tuple[Optional[bytes], BookInfo]:
|
||||
"""Get book data for a specific book, including its title.
|
||||
|
||||
Args:
|
||||
@@ -97,7 +97,7 @@ def get_book_data(book_id: str) -> Tuple[Optional[bytes], str] :
|
||||
book_info = book_queue._book_data[book_id]
|
||||
path = book_info.download_path
|
||||
with open(path, "rb") as f:
|
||||
return f.read(), book_info.title
|
||||
return f.read(), book_info
|
||||
except Exception as e:
|
||||
logger.error_trace(f"Error getting book data: {e}")
|
||||
book_info.download_path = None
|
||||
|
||||
Reference in New Issue
Block a user