feat: add ebook MIME types, fix azw3/mobi detection collision, trust undetectable ebook formats
This commit is contained in:
+20
-1
@@ -22,6 +22,15 @@ const OUTPUT_MIME_TYPES = {
|
||||
ttf: 'font/ttf',
|
||||
otf: 'font/otf',
|
||||
woff: 'font/woff',
|
||||
epub: 'application/epub+zip',
|
||||
fb2: 'application/x-fictionbook+xml',
|
||||
lrf: 'application/octet-stream',
|
||||
mobi: 'application/x-mobipocket-ebook',
|
||||
pdb: 'application/vnd.palm',
|
||||
rb: 'application/octet-stream',
|
||||
snb: 'application/octet-stream',
|
||||
tcr: 'application/octet-stream',
|
||||
azw3: 'application/vnd.amazon.ebook',
|
||||
};
|
||||
|
||||
export async function detectInputMime(filePath) {
|
||||
@@ -44,9 +53,19 @@ const UNDETECTABLE_TEXT_FORMATS = {
|
||||
csv: 'text/csv',
|
||||
};
|
||||
|
||||
const UNDETECTABLE_EBOOK_FORMATS = {
|
||||
fb2: 'application/x-fictionbook+xml',
|
||||
lrf: 'application/octet-stream',
|
||||
pdb: 'application/vnd.palm',
|
||||
rb: 'application/octet-stream',
|
||||
snb: 'application/octet-stream',
|
||||
tcr: 'application/octet-stream',
|
||||
};
|
||||
|
||||
function normalizeFormat(format) {
|
||||
if (format === 'jpg') return 'jpeg';
|
||||
if (format === 'heif') return 'heic';
|
||||
if (format === 'azw3') return 'mobi';
|
||||
return format;
|
||||
}
|
||||
|
||||
@@ -61,7 +80,7 @@ export async function resolveInputFormat(filePath, declaredFormat) {
|
||||
const detected = await detectInputMime(filePath);
|
||||
|
||||
if (!detected) {
|
||||
const fallbackMime = UNDETECTABLE_TEXT_FORMATS[declaredFormat];
|
||||
const fallbackMime = UNDETECTABLE_TEXT_FORMATS[declaredFormat] ?? UNDETECTABLE_EBOOK_FORMATS[declaredFormat];
|
||||
if (fallbackMime) {
|
||||
return { mime: fallbackMime, valid: true };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user