feat: register font/dfont converters in the app and worker
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -10,6 +10,8 @@ import { registerImageToPdfConverter } from './converters/imageToPdf.js';
|
|||||||
import { registerDocumentConverters } from './converters/document.js';
|
import { registerDocumentConverters } from './converters/document.js';
|
||||||
import { registerIcoConverter } from './converters/ico.js';
|
import { registerIcoConverter } from './converters/ico.js';
|
||||||
import { registerHeicConverter } from './converters/heic.js';
|
import { registerHeicConverter } from './converters/heic.js';
|
||||||
|
import { registerFontConverter } from './converters/font.js';
|
||||||
|
import { registerDfontConverter } from './converters/dfont.js';
|
||||||
import { resolveInputFormat } from './mime.js';
|
import { resolveInputFormat } from './mime.js';
|
||||||
import { deleteIfExists } from './storage.js';
|
import { deleteIfExists } from './storage.js';
|
||||||
import { createJob, getJobByUuid } from './jobs/jobRepository.js';
|
import { createJob, getJobByUuid } from './jobs/jobRepository.js';
|
||||||
@@ -40,6 +42,8 @@ function registerAllConverters() {
|
|||||||
registerDocumentConverters();
|
registerDocumentConverters();
|
||||||
registerIcoConverter();
|
registerIcoConverter();
|
||||||
registerHeicConverter();
|
registerHeicConverter();
|
||||||
|
registerFontConverter();
|
||||||
|
registerDfontConverter();
|
||||||
convertersRegistered = true;
|
convertersRegistered = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ import { registerImageToPdfConverter } from './converters/imageToPdf.js';
|
|||||||
import { registerDocumentConverters } from './converters/document.js';
|
import { registerDocumentConverters } from './converters/document.js';
|
||||||
import { registerIcoConverter } from './converters/ico.js';
|
import { registerIcoConverter } from './converters/ico.js';
|
||||||
import { registerHeicConverter } from './converters/heic.js';
|
import { registerHeicConverter } from './converters/heic.js';
|
||||||
|
import { registerFontConverter } from './converters/font.js';
|
||||||
|
import { registerDfontConverter } from './converters/dfont.js';
|
||||||
import { findPendingJobs, markProcessing, markDone, markFailed } from './jobs/jobRepository.js';
|
import { findPendingJobs, markProcessing, markDone, markFailed } from './jobs/jobRepository.js';
|
||||||
|
|
||||||
const JOB_TIMEOUT_MS = 60000;
|
const JOB_TIMEOUT_MS = 60000;
|
||||||
@@ -82,6 +84,8 @@ async function main() {
|
|||||||
registerDocumentConverters();
|
registerDocumentConverters();
|
||||||
registerIcoConverter();
|
registerIcoConverter();
|
||||||
registerHeicConverter();
|
registerHeicConverter();
|
||||||
|
registerFontConverter();
|
||||||
|
registerDfontConverter();
|
||||||
|
|
||||||
startWorker(prisma, config);
|
startWorker(prisma, config);
|
||||||
console.log(`Worker started, polling every ${config.workerPollIntervalMs}ms`);
|
console.log(`Worker started, polling every ${config.workerPollIntervalMs}ms`);
|
||||||
|
|||||||
@@ -179,6 +179,48 @@ describe('POST /api/jobs', () => {
|
|||||||
expect(response.body.jobs[0].error).toMatch(/Invalid quality/);
|
expect(response.body.jobs[0].error).toMatch(/Invalid quality/);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('creates a pending job converting an OTF upload to ttf', async () => {
|
||||||
|
const fixturePath = path.join(import.meta.dirname, '..', 'fixtures', 'sample.otf');
|
||||||
|
|
||||||
|
const response = await request(app)
|
||||||
|
.post('/api/jobs')
|
||||||
|
.field('targetFormats', JSON.stringify(['ttf']))
|
||||||
|
.attach('files', fixturePath, 'font.otf');
|
||||||
|
|
||||||
|
expect(response.status).toBe(201);
|
||||||
|
expect(response.body.jobs[0].status).toBe('pending');
|
||||||
|
|
||||||
|
const job = await getJobByUuid(prisma, response.body.jobs[0].id);
|
||||||
|
expect(job.sourceFormat).toBe('otf');
|
||||||
|
expect(job.targetFormat).toBe('ttf');
|
||||||
|
expect(job.family).toBe('font');
|
||||||
|
expect(job.inputMimeType).toBe('font/otf');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('creates a pending job converting a dfont upload despite file-type misidentifying its content as ico', async () => {
|
||||||
|
const fixturePath = path.join(import.meta.dirname, '..', 'fixtures', 'sample.dfont');
|
||||||
|
|
||||||
|
const response = await request(app)
|
||||||
|
.post('/api/jobs')
|
||||||
|
.field('targetFormats', JSON.stringify(['ttf']))
|
||||||
|
.attach('files', fixturePath, 'font.dfont');
|
||||||
|
|
||||||
|
expect(response.status).toBe(201);
|
||||||
|
expect(response.body.jobs[0].status).toBe('pending');
|
||||||
|
|
||||||
|
const job = await getJobByUuid(prisma, response.body.jobs[0].id);
|
||||||
|
expect(job.sourceFormat).toBe('dfont');
|
||||||
|
expect(job.inputMimeType).toBe('application/x-dfont');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('lists ttf/otf/woff as targets for each other via GET /api/formats, and never lists dfont as a target', async () => {
|
||||||
|
const ttfTargets = await request(app).get('/api/formats').query({ source: 'ttf' });
|
||||||
|
expect(ttfTargets.body.targets).toEqual(expect.arrayContaining(['otf', 'woff']));
|
||||||
|
|
||||||
|
const otfTargets = await request(app).get('/api/formats').query({ source: 'otf' });
|
||||||
|
expect(otfTargets.body.targets).not.toContain('dfont');
|
||||||
|
});
|
||||||
|
|
||||||
it('creates a pending job converting a HEIC upload to jpg', async () => {
|
it('creates a pending job converting a HEIC upload to jpg', async () => {
|
||||||
const fixturePath = path.join(import.meta.dirname, '..', 'fixtures', 'sample.heic');
|
const fixturePath = path.join(import.meta.dirname, '..', 'fixtures', 'sample.heic');
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user