Add APIs to upload to various destinations - dummy code first
This commit is contained in:
@@ -6,7 +6,7 @@ from app.config import settings
|
|||||||
from app.celery_app import celery
|
from app.celery_app import celery
|
||||||
|
|
||||||
# Ensure tasks are loaded
|
# Ensure tasks are loaded
|
||||||
from app import tasks # <— This imports app/tasks.py so Celery can register 'process_document'
|
from app import tasks # <— This imports app/tasks.py so Celery can register tasks
|
||||||
|
|
||||||
# **Ensure all tasks are imported before Celery starts**
|
# **Ensure all tasks are imported before Celery starts**
|
||||||
from app.tasks.upload_to_s3 import upload_to_s3
|
from app.tasks.upload_to_s3 import upload_to_s3
|
||||||
@@ -15,7 +15,10 @@ from app.tasks.refine_text_with_gpt import refine_text_with_gpt
|
|||||||
from app.tasks.extract_metadata_with_gpt import extract_metadata_with_gpt
|
from app.tasks.extract_metadata_with_gpt import extract_metadata_with_gpt
|
||||||
from app.tasks.embed_metadata_into_pdf import embed_metadata_into_pdf
|
from app.tasks.embed_metadata_into_pdf import embed_metadata_into_pdf
|
||||||
|
|
||||||
|
# Import new send tasks
|
||||||
|
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
|
||||||
|
|
||||||
celery.conf.task_routes = {
|
celery.conf.task_routes = {
|
||||||
"app.tasks.*": {"queue": "default"},
|
"app.tasks.*": {"queue": "default"},
|
||||||
@@ -24,4 +27,3 @@ celery.conf.task_routes = {
|
|||||||
@celery.task
|
@celery.task
|
||||||
def test_task():
|
def test_task():
|
||||||
return "Celery is working!"
|
return "Celery is working!"
|
||||||
|
|
||||||
|
|||||||
+31
-1
@@ -4,6 +4,9 @@ import os
|
|||||||
from fastapi import FastAPI, HTTPException
|
from fastapi import FastAPI, HTTPException
|
||||||
from app.config import settings
|
from app.config import settings
|
||||||
from app.tasks.upload_to_s3 import upload_to_s3
|
from app.tasks.upload_to_s3 import upload_to_s3
|
||||||
|
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
|
||||||
|
|
||||||
app = FastAPI(title="Document Processing API")
|
app = FastAPI(title="Document Processing API")
|
||||||
|
|
||||||
@@ -20,10 +23,37 @@ def process(file_path: str):
|
|||||||
|
|
||||||
# If file_path is not absolute, treat it as relative to settings.workdir.
|
# If file_path is not absolute, treat it as relative to settings.workdir.
|
||||||
if not os.path.isabs(file_path):
|
if not os.path.isabs(file_path):
|
||||||
file_path = os.path.join(settings.workdir, file_path)
|
file_path = os.path.join(settings.workdir, 'processed', file_path)
|
||||||
|
|
||||||
if not os.path.exists(file_path):
|
if not os.path.exists(file_path):
|
||||||
raise HTTPException(status_code=400, detail=f"File {file_path} not found.")
|
raise HTTPException(status_code=400, detail=f"File {file_path} not found.")
|
||||||
|
|
||||||
task = upload_to_s3.delay(file_path)
|
task = upload_to_s3.delay(file_path)
|
||||||
return {"task_id": task.id, "status": "queued"}
|
return {"task_id": task.id, "status": "queued"}
|
||||||
|
|
||||||
|
@app.post("/send_to_dropbox/")
|
||||||
|
def send_to_dropbox(file_path: str):
|
||||||
|
if not os.path.isabs(file_path):
|
||||||
|
file_path = os.path.join(settings.workdir, 'processed', file_path)
|
||||||
|
if not os.path.exists(file_path):
|
||||||
|
raise HTTPException(status_code=400, detail=f"File {file_path} not found.")
|
||||||
|
task = upload_to_dropbox.delay(file_path)
|
||||||
|
return {"task_id": task.id, "status": "queued"}
|
||||||
|
|
||||||
|
@app.post("/send_to_paperless/")
|
||||||
|
def send_to_paperless(file_path: str):
|
||||||
|
if not os.path.isabs(file_path):
|
||||||
|
file_path = os.path.join(settings.workdir, 'processed', file_path)
|
||||||
|
if not os.path.exists(file_path):
|
||||||
|
raise HTTPException(status_code=400, detail=f"File {file_path} not found.")
|
||||||
|
task = upload_to_paperless.delay(file_path)
|
||||||
|
return {"task_id": task.id, "status": "queued"}
|
||||||
|
|
||||||
|
@app.post("/send_to_nextcloud/")
|
||||||
|
def send_to_nextcloud(file_path: str):
|
||||||
|
if not os.path.isabs(file_path):
|
||||||
|
file_path = os.path.join(settings.workdir, 'processed', file_path)
|
||||||
|
if not os.path.exists(file_path):
|
||||||
|
raise HTTPException(status_code=400, detail=f"File {file_path} not found.")
|
||||||
|
task = upload_to_nextcloud.delay(file_path)
|
||||||
|
return {"task_id": task.id, "status": "queued"}
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
from app.config import settings
|
||||||
|
from app.tasks.retry_config import BaseTaskWithRetry
|
||||||
|
from app.celery_app import celery
|
||||||
|
|
||||||
|
@celery.task(base=BaseTaskWithRetry)
|
||||||
|
def upload_to_dropbox(file_path: str):
|
||||||
|
"""Simulate uploading a file to Dropbox."""
|
||||||
|
print(f"[INFO] Simulating upload to Dropbox: {file_path}")
|
||||||
|
return {"status": "Completed", "file": file_path}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
from app.config import settings
|
||||||
|
from app.tasks.retry_config import BaseTaskWithRetry
|
||||||
|
from app.celery_app import celery
|
||||||
|
|
||||||
|
@celery.task(base=BaseTaskWithRetry)
|
||||||
|
def upload_to_nextcloud(file_path: str):
|
||||||
|
"""Simulate uploading a file to Nextcloud."""
|
||||||
|
print(f"[INFO] Simulating upload to Nextcloud: {file_path}")
|
||||||
|
return {"status": "Completed", "file": file_path}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
from app.config import settings
|
||||||
|
from app.tasks.retry_config import BaseTaskWithRetry
|
||||||
|
from app.celery_app import celery
|
||||||
|
|
||||||
|
@celery.task(base=BaseTaskWithRetry)
|
||||||
|
def upload_to_paperless(file_path: str):
|
||||||
|
"""Simulate uploading a file to Paperless."""
|
||||||
|
print(f"[INFO] Simulating upload to Paperless: {file_path}")
|
||||||
|
return {"status": "Completed", "file": file_path}
|
||||||
Reference in New Issue
Block a user