KI-AGENT: Terminpicker und Dokumentaufruf verbessert

This commit is contained in:
2026-09-08 22:49:17 +02:00
parent 358e40d749
commit 15e21a97e2
10 changed files with 135 additions and 85 deletions

View File

@@ -84,10 +84,12 @@ export default fp(async (server: FastifyInstance) => {
const urlPath = req.url.split("?")[0]
const queryToken = (req.query as any)?.downloadToken
const isDownloadTokenRoute =
(urlPath.startsWith("/api/email/attachments/") && urlPath.endsWith("/download"))
|| urlPath.startsWith("/api/files/content/")
const downloadToken =
typeof queryToken === "string"
&& urlPath.startsWith("/api/email/attachments/")
&& urlPath.endsWith("/download")
&& isDownloadTokenRoute
? queryToken
: null

View File

@@ -5,6 +5,7 @@ import {
GetObjectCommand
} from "@aws-sdk/client-s3"
import archiver from "archiver"
import jwt from "jsonwebtoken"
import { secrets } from "../utils/secrets"
import { saveFile } from "../utils/files"
@@ -19,6 +20,17 @@ import {
export default async function fileRoutes(server: FastifyInstance) {
const createDownloadUrl = (req: any, fileId: string) => {
const downloadToken = jwt.sign({
user_id: req.user.user_id,
email: req.user.email,
tenant_id: req.user.tenant_id,
is_admin: Boolean(req.user.is_admin),
}, secrets.JWT_SECRET!, { expiresIn: "15m" })
return `/api/files/content/${fileId}?downloadToken=${encodeURIComponent(downloadToken)}`
}
const getPortalCustomerId = async (req: any) => {
const tenantId = req.user?.tenant_id
const userId = req.user?.user_id
@@ -282,7 +294,7 @@ export default async function fileRoutes(server: FastifyInstance) {
const file = await loadSingleFileForRequest(req, id)
if (!file) return reply.code(404).send({ error: "Not found" })
return { ...file, url: `/api/files/content/${file.id}` }
return { ...file, url: createDownloadUrl(req, file.id) }
} else {
// -------------------------------------------------
// MULTIPLE PRESIGNED URLs
@@ -300,7 +312,7 @@ export default async function fileRoutes(server: FastifyInstance) {
const output = selected.map(file => ({
...file,
url: `/api/files/content/${file.id}`
url: createDownloadUrl(req, file.id)
}))
return { files: output }