Deleted incoming host logic
This commit is contained in:
@@ -10,4 +10,3 @@ LLM_MAX_MAILS=80
|
||||
LLM_BODY_CHARS=3000
|
||||
|
||||
UPLOAD_DIR=/app/uploads
|
||||
INCOMING_DIR=/app/incoming
|
||||
|
||||
+1
-54
@@ -16,7 +16,7 @@ from fastapi import FastAPI, File, Form, HTTPException, UploadFile
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from config import CORS_ORIGINS, INCOMING_DIR, LLM_MODEL, UPLOAD_DIR
|
||||
from config import CORS_ORIGINS, LLM_MODEL, UPLOAD_DIR
|
||||
from db.pool import close_pool, init_pool, pool_enabled
|
||||
from job_repository import create_job, ensure_tables, get_job, get_report, list_jobs
|
||||
from llm_client import ping_llm
|
||||
@@ -35,7 +35,6 @@ STAGING_DIR = UPLOAD_DIR / "staging"
|
||||
async def lifespan(app: FastAPI):
|
||||
UPLOAD_DIR.mkdir(parents=True, exist_ok=True)
|
||||
STAGING_DIR.mkdir(parents=True, exist_ok=True)
|
||||
INCOMING_DIR.mkdir(parents=True, exist_ok=True)
|
||||
await init_pool()
|
||||
await ensure_tables()
|
||||
yield
|
||||
@@ -69,7 +68,6 @@ class UploadResponse(BaseModel):
|
||||
mailbox: str
|
||||
filename: str
|
||||
size_bytes: int
|
||||
source: str # upload | incoming
|
||||
|
||||
|
||||
def _staging_path(upload_id: str) -> Path:
|
||||
@@ -91,29 +89,6 @@ def _read_staging_meta(upload_id: str) -> dict:
|
||||
return json.loads(meta_path.read_text(encoding="utf-8"))
|
||||
|
||||
|
||||
def _attach_source(src: Path, stage_dir: Path, mailbox: str, filename: str) -> Path:
|
||||
dest = stage_dir / f"{mailbox}_{filename}"
|
||||
if dest.exists() or dest.is_symlink():
|
||||
dest.unlink()
|
||||
try:
|
||||
dest.symlink_to(src)
|
||||
except OSError:
|
||||
shutil.copy2(src, dest)
|
||||
return dest
|
||||
|
||||
|
||||
def _find_incoming_match(filename: str, size_bytes: int) -> Path | None:
|
||||
candidate = INCOMING_DIR / Path(filename).name
|
||||
if not candidate.is_file():
|
||||
return None
|
||||
try:
|
||||
if candidate.stat().st_size != size_bytes:
|
||||
return None
|
||||
except OSError:
|
||||
return None
|
||||
return candidate.resolve()
|
||||
|
||||
|
||||
def _attach_staging_to_job(upload_id: str, job_dir: Path, mailbox: str) -> str:
|
||||
"""Copy/link staged zip into a job dir, keeping staging for re-analysis."""
|
||||
meta = _read_staging_meta(upload_id)
|
||||
@@ -147,33 +122,6 @@ async def health() -> HealthResponse:
|
||||
)
|
||||
|
||||
|
||||
@app.post("/api/uploads/resolve", response_model=UploadResponse)
|
||||
async def api_resolve_upload(
|
||||
mailbox: Mailbox = Form(...),
|
||||
filename: str = Form(...),
|
||||
size_bytes: int = Form(...),
|
||||
) -> UploadResponse:
|
||||
"""If the selected file already exists on the incoming mount, stage it without re-upload."""
|
||||
match = _find_incoming_match(filename, size_bytes)
|
||||
if not match:
|
||||
raise HTTPException(status_code=404, detail="incoming_match_not_found")
|
||||
|
||||
upload_id = uuid.uuid4().hex
|
||||
stage_dir = _staging_path(upload_id)
|
||||
stage_dir.mkdir(parents=True, exist_ok=True)
|
||||
safe_name = Path(filename).name
|
||||
_attach_source(match, stage_dir, mailbox, safe_name)
|
||||
meta = {
|
||||
"upload_id": upload_id,
|
||||
"mailbox": mailbox,
|
||||
"filename": safe_name,
|
||||
"size_bytes": size_bytes,
|
||||
"source": "incoming",
|
||||
}
|
||||
_write_staging_meta(stage_dir, meta)
|
||||
return UploadResponse(**meta)
|
||||
|
||||
|
||||
@app.post("/api/uploads", response_model=UploadResponse)
|
||||
async def api_upload_zip(
|
||||
mailbox: Mailbox = Form(...),
|
||||
@@ -207,7 +155,6 @@ async def api_upload_zip(
|
||||
"mailbox": mailbox,
|
||||
"filename": safe_name,
|
||||
"size_bytes": size,
|
||||
"source": "upload",
|
||||
}
|
||||
_write_staging_meta(stage_dir, meta)
|
||||
return UploadResponse(**meta)
|
||||
|
||||
@@ -34,6 +34,3 @@ LLM_BODY_CHARS = int(os.getenv("LLM_BODY_CHARS", "3000"))
|
||||
|
||||
UPLOAD_DIR = Path(os.getenv("UPLOAD_DIR", str(BASE_DIR / "uploads"))).resolve()
|
||||
UPLOAD_DIR.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
INCOMING_DIR = Path(os.getenv("INCOMING_DIR", str(BASE_DIR.parent / "incoming"))).resolve()
|
||||
INCOMING_DIR.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
Reference in New Issue
Block a user