feat(scan): whiten receipt backgrounds and embed OCR in PDFs
This commit is contained in:
@@ -152,6 +152,7 @@ export default async function instanceAgentRoutes(server: FastifyInstance) {
|
||||
active: instanceAgents.active,
|
||||
preferredScannerName: instanceAgents.preferredScannerName,
|
||||
scanDefaults: instanceAgents.scanDefaults,
|
||||
capabilities: instanceAgents.capabilities,
|
||||
})
|
||||
.from(instanceAgents)
|
||||
.where(eq(instanceAgents.id, body.agentId))
|
||||
@@ -161,6 +162,14 @@ export default async function instanceAgentRoutes(server: FastifyInstance) {
|
||||
return reply.code(404).send({ error: "Active agent not found" })
|
||||
}
|
||||
|
||||
const settings = { ...((agent.scanDefaults || {}) as Record<string, any>), ...(body.settings || {}) }
|
||||
const enabled = (value: unknown) => value === true || (typeof value === "string" && ["1", "true", "yes", "ja", "on"].includes(value.toLowerCase().trim()))
|
||||
const capabilities = agent.capabilities as Record<string, any>
|
||||
if (((settings.format || "pdf") === "pdf" && enabled(settings.ocr) && !capabilities?.ocr) ||
|
||||
(enabled(settings.backgroundCleanup) && !capabilities?.backgroundCleanup)) {
|
||||
return reply.code(409).send({ error: "Bitte den Scanner-Agenten mit Tesseract und OpenCV aktualisieren. Die angeforderte Scan-Verarbeitung ist dort noch nicht verfügbar." })
|
||||
}
|
||||
|
||||
const [job] = await server.db
|
||||
.insert(instanceAgentScanJobs)
|
||||
.values({
|
||||
@@ -169,10 +178,7 @@ export default async function instanceAgentRoutes(server: FastifyInstance) {
|
||||
requestedBy: req.user?.user_id,
|
||||
scannerName: body.scannerName || agent.preferredScannerName,
|
||||
requestedFilename: body.requestedFilename,
|
||||
settings: {
|
||||
...((agent.scanDefaults || {}) as Record<string, any>),
|
||||
...(body.settings || {}),
|
||||
},
|
||||
settings,
|
||||
target: body.target || {},
|
||||
})
|
||||
.returning()
|
||||
|
||||
@@ -55,3 +55,30 @@ test("unknown agents cannot receive setup credentials", async (t) => {
|
||||
assert.equal(response.statusCode, 404)
|
||||
assert.equal(f.updates.length, 0)
|
||||
})
|
||||
|
||||
test("OCR and background cleanup require an agent that supports the requested processing", async t => {
|
||||
const app = Fastify()
|
||||
t.after(() => app.close())
|
||||
const jobs: any[] = []
|
||||
let capabilities: Record<string, boolean> = { scan: true }
|
||||
app.addHook("onRequest", async request => { request.user = { is_admin: true, tenant_id: 1 } as any })
|
||||
app.decorate("db", {
|
||||
select: () => ({ from: () => ({ where: () => ({ limit: async () => [{ id, active: true, scanDefaults: {}, capabilities }] }) }) }),
|
||||
insert: () => ({ values: (data: any) => ({ returning: async () => { jobs.push(data); return [{ id: "job", ...data }] } }) }),
|
||||
})
|
||||
await app.register(routes)
|
||||
for (const settings of [{ ocr: true }, { ocr: "true" }, { backgroundCleanup: true }]) {
|
||||
const response = await app.inject({ method: "POST", url: "/scan-jobs", payload: { agentId: id, settings } })
|
||||
assert.equal(response.statusCode, 409)
|
||||
assert.equal(jobs.length, 0)
|
||||
}
|
||||
capabilities = { scan: true, ocr: true, backgroundCleanup: true }
|
||||
const response = await app.inject({
|
||||
method: "POST", url: "/scan-jobs",
|
||||
payload: { agentId: id, settings: { ocr: true, ocrLanguage: "deu+eng", backgroundCleanup: true }, target: { folder: null, type: null } },
|
||||
})
|
||||
assert.equal(response.statusCode, 200)
|
||||
assert.equal(jobs.length, 1)
|
||||
assert.equal(jobs[0].settings.ocr, true)
|
||||
assert.equal(jobs[0].target.type, null)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user