feat: add font MIME types and fix dfont/ico detection collision
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
+12
@@ -1,4 +1,6 @@
|
||||
import { fileTypeFromFile } from 'file-type';
|
||||
import fs from 'node:fs/promises';
|
||||
import { probeDfont } from './converters/dfont.js';
|
||||
|
||||
const OUTPUT_MIME_TYPES = {
|
||||
jpg: 'image/jpeg',
|
||||
@@ -17,6 +19,9 @@ const OUTPUT_MIME_TYPES = {
|
||||
md: 'text/markdown',
|
||||
csv: 'text/csv',
|
||||
xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||
ttf: 'font/ttf',
|
||||
otf: 'font/otf',
|
||||
woff: 'font/woff',
|
||||
};
|
||||
|
||||
export async function detectInputMime(filePath) {
|
||||
@@ -46,6 +51,13 @@ function normalizeFormat(format) {
|
||||
}
|
||||
|
||||
export async function resolveInputFormat(filePath, declaredFormat) {
|
||||
if (declaredFormat === 'dfont') {
|
||||
const buffer = await fs.readFile(filePath);
|
||||
return probeDfont(buffer)
|
||||
? { mime: 'application/x-dfont', valid: true }
|
||||
: { mime: null, valid: false };
|
||||
}
|
||||
|
||||
const detected = await detectInputMime(filePath);
|
||||
|
||||
if (!detected) {
|
||||
|
||||
Reference in New Issue
Block a user