fixed linting
This commit is contained in:
@@ -1,4 +1,13 @@
|
|||||||
from fastapi import FastAPI, HTTPException, File, UploadFile, Form, Request, BackgroundTasks
|
from fastapi import (
|
||||||
|
FastAPI,
|
||||||
|
HTTPException,
|
||||||
|
File,
|
||||||
|
UploadFile,
|
||||||
|
Form,
|
||||||
|
Request,
|
||||||
|
BackgroundTasks,
|
||||||
|
)
|
||||||
|
|
||||||
# Backend (Python)
|
# Backend (Python)
|
||||||
# Add this to store progress globally
|
# Add this to store progress globally
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
@@ -1012,45 +1021,45 @@ def create_app(args):
|
|||||||
async def scan_for_new_documents(background_tasks: BackgroundTasks):
|
async def scan_for_new_documents(background_tasks: BackgroundTasks):
|
||||||
"""Trigger the scanning process"""
|
"""Trigger the scanning process"""
|
||||||
global scan_progress
|
global scan_progress
|
||||||
|
|
||||||
with progress_lock:
|
with progress_lock:
|
||||||
if scan_progress["is_scanning"]:
|
if scan_progress["is_scanning"]:
|
||||||
return {"status": "already_scanning"}
|
return {"status": "already_scanning"}
|
||||||
|
|
||||||
scan_progress["is_scanning"] = True
|
scan_progress["is_scanning"] = True
|
||||||
scan_progress["indexed_count"] = 0
|
scan_progress["indexed_count"] = 0
|
||||||
scan_progress["progress"] = 0
|
scan_progress["progress"] = 0
|
||||||
|
|
||||||
# Start the scanning process in the background
|
# Start the scanning process in the background
|
||||||
background_tasks.add_task(run_scanning_process)
|
background_tasks.add_task(run_scanning_process)
|
||||||
|
|
||||||
return {"status": "scanning_started"}
|
return {"status": "scanning_started"}
|
||||||
|
|
||||||
async def run_scanning_process():
|
async def run_scanning_process():
|
||||||
"""Background task to scan and index documents"""
|
"""Background task to scan and index documents"""
|
||||||
global scan_progress
|
global scan_progress
|
||||||
|
|
||||||
try:
|
try:
|
||||||
new_files = doc_manager.scan_directory_for_new_files()
|
new_files = doc_manager.scan_directory_for_new_files()
|
||||||
scan_progress["total_files"] = len(new_files)
|
scan_progress["total_files"] = len(new_files)
|
||||||
|
|
||||||
for file_path in new_files:
|
for file_path in new_files:
|
||||||
try:
|
try:
|
||||||
with progress_lock:
|
with progress_lock:
|
||||||
scan_progress["current_file"] = os.path.basename(file_path)
|
scan_progress["current_file"] = os.path.basename(file_path)
|
||||||
|
|
||||||
await index_file(file_path)
|
await index_file(file_path)
|
||||||
|
|
||||||
with progress_lock:
|
with progress_lock:
|
||||||
scan_progress["indexed_count"] += 1
|
scan_progress["indexed_count"] += 1
|
||||||
scan_progress["progress"] = (
|
scan_progress["progress"] = (
|
||||||
scan_progress["indexed_count"]
|
scan_progress["indexed_count"]
|
||||||
/ scan_progress["total_files"]
|
/ scan_progress["total_files"]
|
||||||
) * 100
|
) * 100
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"Error indexing file {file_path}: {str(e)}")
|
logging.error(f"Error indexing file {file_path}: {str(e)}")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"Error during scanning process: {str(e)}")
|
logging.error(f"Error during scanning process: {str(e)}")
|
||||||
finally:
|
finally:
|
||||||
|
@@ -57,7 +57,7 @@ const pages = {
|
|||||||
</svg>
|
</svg>
|
||||||
Rescan Files
|
Rescan Files
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<button id="uploadBtn" class="bg-blue-600 text-white px-4 py-2 rounded-lg hover:bg-blue-700 transition-colors">
|
<button id="uploadBtn" class="bg-blue-600 text-white px-4 py-2 rounded-lg hover:bg-blue-700 transition-colors">
|
||||||
Upload & Index Files
|
Upload & Index Files
|
||||||
</button>
|
</button>
|
||||||
|
Reference in New Issue
Block a user