Merge branch 'czat/zalaczniki' into pokazowka/2026-11-17
This commit is contained in:
@@ -6,6 +6,7 @@ audit row names the file and its size, never its content.
|
||||
from __future__ import annotations
|
||||
|
||||
from fastapi import APIRouter, Depends, Query, Request
|
||||
from starlette.concurrency import run_in_threadpool
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from ..db import get_db
|
||||
@@ -24,7 +25,9 @@ async def extract(request: Request, name: str = Query(min_length=1, max_length=2
|
||||
data += chunk
|
||||
if len(data) > attachments.MAX_BYTES:
|
||||
break # extract() refuses it; nothing past the limit is read
|
||||
out = attachments.extract(name, bytes(data))
|
||||
# A 300-page PDF parses for seconds: off the event loop, or every other request waits for it.
|
||||
# ponytail: no time budget per document; a subprocess with a timeout if a crafted PDF ever stalls a worker.
|
||||
out = await run_in_threadpool(attachments.extract, name, bytes(data))
|
||||
audit.record(db, action="chat.attachment", entity_type="attachment", actor_id=user.id, detail=name[:200],
|
||||
ip=client_ip(request), diff={"kind": out["kind"], "bytes": len(data), "pages": out["pages"],
|
||||
"chars": out["chars"]})
|
||||
|
||||
Reference in New Issue
Block a user