Fixed Dokubox and Sanitizing for File Uploads Fix #133
This commit is contained in:
@@ -27,6 +27,10 @@ export function syncDokuboxService (server: FastifyInstance) {
|
|||||||
let client: ImapFlow | null = null
|
let client: ImapFlow | null = null
|
||||||
|
|
||||||
async function initDokuboxClient() {
|
async function initDokuboxClient() {
|
||||||
|
if (client?.usable) {
|
||||||
|
return client
|
||||||
|
}
|
||||||
|
|
||||||
client = new ImapFlow({
|
client = new ImapFlow({
|
||||||
host: secrets.DOKUBOX_IMAP_HOST,
|
host: secrets.DOKUBOX_IMAP_HOST,
|
||||||
port: secrets.DOKUBOX_IMAP_PORT,
|
port: secrets.DOKUBOX_IMAP_PORT,
|
||||||
@@ -41,6 +45,7 @@ export function syncDokuboxService (server: FastifyInstance) {
|
|||||||
console.log("Dokubox E-Mail Client Initialized")
|
console.log("Dokubox E-Mail Client Initialized")
|
||||||
|
|
||||||
await client.connect()
|
await client.connect()
|
||||||
|
return client
|
||||||
}
|
}
|
||||||
|
|
||||||
const syncDokubox = async () => {
|
const syncDokubox = async () => {
|
||||||
@@ -92,7 +97,8 @@ export function syncDokuboxService (server: FastifyInstance) {
|
|||||||
if (!badMessageMessageSent) {
|
if (!badMessageMessageSent) {
|
||||||
badMessageMessageSent = true
|
badMessageMessageSent = true
|
||||||
}
|
}
|
||||||
return
|
server.log.warn({ messageId: message.id, subject: message.subject }, "Dokubox message could not be mapped to a tenant")
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message.attachments.length > 0) {
|
if (message.attachments.length > 0) {
|
||||||
@@ -248,7 +254,6 @@ export function syncDokuboxService (server: FastifyInstance) {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
run: async () => {
|
run: async () => {
|
||||||
await initDokuboxClient()
|
|
||||||
await syncDokubox()
|
await syncDokubox()
|
||||||
console.log("Service: Dokubox sync finished")
|
console.log("Service: Dokubox sync finished")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ export default async function fileRoutes(server: FastifyInstance) {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
id: created.id,
|
id: created.id,
|
||||||
filename: data.filename,
|
filename: created.filename,
|
||||||
path: created.key
|
path: created.key
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { files } from "../../db/schema"
|
|||||||
import { eq } from "drizzle-orm"
|
import { eq } from "drizzle-orm"
|
||||||
import { FastifyInstance } from "fastify"
|
import { FastifyInstance } from "fastify"
|
||||||
import { storeExtractedTextForFile } from "./documentText"
|
import { storeExtractedTextForFile } from "./documentText"
|
||||||
|
import { sanitizeFilename } from "./filename"
|
||||||
|
|
||||||
export const saveFile = async (
|
export const saveFile = async (
|
||||||
server: FastifyInstance,
|
server: FastifyInstance,
|
||||||
@@ -46,7 +47,10 @@ export const saveFile = async (
|
|||||||
|
|
||||||
// Name ermitteln (Fallback Logik)
|
// Name ermitteln (Fallback Logik)
|
||||||
// Wenn attachment ein Buffer ist, muss der Name in 'other' stehen oder generiert werden
|
// Wenn attachment ein Buffer ist, muss der Name in 'other' stehen oder generiert werden
|
||||||
const filename = attachment.filename || providedFilename || `${created.id}.pdf`
|
const filename = sanitizeFilename(
|
||||||
|
attachment.filename || providedFilename || `${created.id}.pdf`,
|
||||||
|
`${created.id}.pdf`
|
||||||
|
)
|
||||||
|
|
||||||
// ---------------------------------------------------
|
// ---------------------------------------------------
|
||||||
// 2️⃣ BODY & CONTENT TYPE ERMITTELN
|
// 2️⃣ BODY & CONTENT TYPE ERMITTELN
|
||||||
@@ -108,7 +112,7 @@ export const saveFile = async (
|
|||||||
)
|
)
|
||||||
|
|
||||||
console.log(`File saved: ${key}`)
|
console.log(`File saved: ${key}`)
|
||||||
return { id: created.id, key }
|
return { id: created.id, key, filename }
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("saveFile error:", err)
|
console.error("saveFile error:", err)
|
||||||
return null
|
return null
|
||||||
|
|||||||
Reference in New Issue
Block a user