fix: OpenFile now gets the right mime type (#173)

This commit is contained in:
Daniel
2026-07-13 15:11:24 +02:00
parent 1fde5359ca
commit c94f842cd4
2 changed files with 35 additions and 1 deletions
+30
View File
@@ -0,0 +1,30 @@
/// MIME types for the book formats Calibre-Web can serve.
const Map<String, String> bookMimeTypes = {
'epub': 'application/epub+zip',
'kepub': 'application/epub+zip',
'pdf': 'application/pdf',
'mobi': 'application/x-mobipocket-ebook',
'prc': 'application/x-mobipocket-ebook',
'pdb': 'application/x-mobipocket-ebook',
'azw': 'application/vnd.amazon.ebook',
'azw3': 'application/vnd.amazon.ebook',
'fb2': 'application/x-fictionbook+xml',
'cbz': 'application/vnd.comicbook+zip',
'cbr': 'application/vnd.comicbook-rar',
'djvu': 'image/vnd.djvu',
'djv': 'image/vnd.djvu',
'txt': 'text/plain',
'rtf': 'application/rtf',
'htm': 'text/html',
'html': 'text/html',
'doc': 'application/msword',
'docx':
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'odt': 'application/vnd.oasis.opendocument.text',
};
/// Resolves the MIME type of a file path or a bare format such as `epub`.
String? bookMimeType(String pathOrFormat) {
final extension = pathOrFormat.split('.').last.toLowerCase().trim();
return bookMimeTypes[extension];
}
@@ -15,6 +15,7 @@ import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter/foundation.dart';
import 'package:calibre_web_companion/core/services/api_service.dart';
import 'package:calibre_web_companion/core/utils/book_mime_types.dart';
import 'package:calibre_web_companion/features/settings/data/models/download_schema.dart';
import 'package:calibre_web_companion/features/book_details/data/models/book_details_model.dart';
import 'package:calibre_web_companion/features/book_view/data/models/book_view_model.dart';
@@ -832,7 +833,10 @@ class BookDetailsRemoteDatasource {
await onFileDownloaded?.call(durablePath);
final result = await OpenFile.open(localPath);
final result = await OpenFile.open(
localPath,
type: bookMimeType(localPath) ?? bookMimeType(format),
);
if (result.type != ResultType.done) {
logger.e('Error while opening the file: ${result.message}');