added first draft of upload interface
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
# app/frontend.py (new file or inline in main.py)
|
||||
from fastapi import APIRouter
|
||||
from fastapi.responses import FileResponse
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
import os
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
# 1) Serve the folder that contains index.html, etc.
|
||||
# e.g. "frontend" is relative to your project root
|
||||
frontend_folder = os.path.join(os.path.dirname(__file__), "..", "frontend")
|
||||
|
||||
# If you just want to serve the entire folder as static:
|
||||
router.mount("/static", StaticFiles(directory=frontend_folder), name="static")
|
||||
|
||||
# 2) For the root route ("/"), return the index.html
|
||||
@router.get("/ui", response_class=FileResponse)
|
||||
def serve_ui():
|
||||
return os.path.join(frontend_folder, "index.html")
|
||||
@@ -8,6 +8,7 @@ from app.tasks.upload_to_dropbox import upload_to_dropbox
|
||||
from app.tasks.upload_to_paperless import upload_to_paperless
|
||||
from app.tasks.upload_to_nextcloud import upload_to_nextcloud
|
||||
from app.tasks.send_to_all import send_to_all_destinations
|
||||
from app.frontend import router as frontend_router
|
||||
|
||||
app = FastAPI(title="Document Processing API")
|
||||
|
||||
@@ -111,3 +112,5 @@ def process_all_pdfs_in_workdir():
|
||||
"pdf_files": pdf_files,
|
||||
"task_ids": task_ids
|
||||
}
|
||||
|
||||
app.include_router(frontend_router)
|
||||
@@ -0,0 +1,26 @@
|
||||
# In main.py or a new dedicated file, e.g. app/routes_ui.py
|
||||
from fastapi import APIRouter, UploadFile, File, HTTPException
|
||||
from app.tasks.upload_to_s3 import upload_to_s3
|
||||
import os
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@router.post("/ui-upload")
|
||||
async def ui_upload(file: UploadFile = File(...)):
|
||||
# You can store this file in your 'workdir' (like how /process does) or a tmp dir
|
||||
workdir = "/workdir"
|
||||
target_path = os.path.join(workdir, file.filename)
|
||||
|
||||
try:
|
||||
with open(target_path, "wb") as f:
|
||||
content = await file.read()
|
||||
f.write(content)
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=f"Failed to save file: {e}")
|
||||
|
||||
# Now you can call your existing Celery flow:
|
||||
task = upload_to_s3.delay(target_path)
|
||||
return {"task_id": task.id, "status": "queued"}
|
||||
|
||||
# Then include this in your main app as well:
|
||||
# app.include_router(router)
|
||||
Reference in New Issue
Block a user