feat: register ebook converter in the app so the API serves the new family
Also fixes a real bug found via the fb2 API test: file-type sniffs a real fb2 file's XML declaration as generic "xml", not "fb2" and not undetected, so it never reached the undetectable-format fallback added in the previous commit. Added an fb2->xml alias in normalizeFormat, same pattern as the existing azw3->mobi one.
This commit is contained in:
+28
-1
@@ -169,7 +169,6 @@ describe('resolveInputFormat — azw3/mobi collision', () => {
|
||||
|
||||
describe('resolveInputFormat — undetectable ebook formats', () => {
|
||||
const undetectableFormats = {
|
||||
fb2: 'application/x-fictionbook+xml',
|
||||
lrf: 'application/octet-stream',
|
||||
pdb: 'application/vnd.palm',
|
||||
rb: 'application/octet-stream',
|
||||
@@ -192,6 +191,34 @@ describe('resolveInputFormat — undetectable ebook formats', () => {
|
||||
);
|
||||
});
|
||||
|
||||
describe('resolveInputFormat — fb2', () => {
|
||||
it('accepts real fb2 content (file-type sniffs its XML declaration as generic "xml", not "fb2")', async () => {
|
||||
const fixturePath = path.join(import.meta.dirname, 'fixtures', 'sample-real.fb2');
|
||||
await fs.writeFile(
|
||||
fixturePath,
|
||||
'<?xml version="1.0" encoding="utf-8"?><FictionBook><body><p>hello</p></body></FictionBook>'
|
||||
);
|
||||
|
||||
const detected = await detectInputMime(fixturePath);
|
||||
expect(detected).toEqual({ ext: 'xml', mime: 'application/xml' });
|
||||
|
||||
const result = await resolveInputFormat(fixturePath, 'fb2');
|
||||
expect(result).toEqual({ mime: 'application/xml', valid: true });
|
||||
|
||||
await fs.unlink(fixturePath);
|
||||
});
|
||||
|
||||
it('falls back to trusting the declared format for fb2 content with no recognizable XML declaration', async () => {
|
||||
const fixturePath = path.join(import.meta.dirname, 'fixtures', 'sample-no-prolog.fb2');
|
||||
await fs.writeFile(fixturePath, 'arbitrary bytes with no recognizable magic number');
|
||||
|
||||
const result = await resolveInputFormat(fixturePath, 'fb2');
|
||||
expect(result).toEqual({ mime: 'application/x-fictionbook+xml', valid: true });
|
||||
|
||||
await fs.unlink(fixturePath);
|
||||
});
|
||||
});
|
||||
|
||||
describe('resolveInputFormat — dfont', () => {
|
||||
it('confirms file-type alone misidentifies the dfont fixture as ico (documents the bug this fix works around)', async () => {
|
||||
const fixturePath = path.join(import.meta.dirname, 'fixtures', 'sample.dfont');
|
||||
|
||||
Reference in New Issue
Block a user