fixed linting

This commit is contained in:
zrguo
2025-01-31 23:35:42 +08:00
parent 58a9ae2f83
commit e59cb7493c
2 changed files with 22 additions and 13 deletions

View File

@@ -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)
# Add this to store progress globally
from typing import Dict
@@ -1012,45 +1021,45 @@ def create_app(args):
async def scan_for_new_documents(background_tasks: BackgroundTasks):
"""Trigger the scanning process"""
global scan_progress
with progress_lock:
if scan_progress["is_scanning"]:
return {"status": "already_scanning"}
scan_progress["is_scanning"] = True
scan_progress["indexed_count"] = 0
scan_progress["progress"] = 0
# Start the scanning process in the background
background_tasks.add_task(run_scanning_process)
return {"status": "scanning_started"}
async def run_scanning_process():
"""Background task to scan and index documents"""
global scan_progress
try:
new_files = doc_manager.scan_directory_for_new_files()
scan_progress["total_files"] = len(new_files)
for file_path in new_files:
try:
with progress_lock:
scan_progress["current_file"] = os.path.basename(file_path)
await index_file(file_path)
with progress_lock:
scan_progress["indexed_count"] += 1
scan_progress["progress"] = (
scan_progress["indexed_count"]
/ scan_progress["total_files"]
) * 100
except Exception as e:
logging.error(f"Error indexing file {file_path}: {str(e)}")
except Exception as e:
logging.error(f"Error during scanning process: {str(e)}")
finally:

View File

@@ -57,7 +57,7 @@ const pages = {
</svg>
Rescan Files
</button>
<button id="uploadBtn" class="bg-blue-600 text-white px-4 py-2 rounded-lg hover:bg-blue-700 transition-colors">
Upload & Index Files
</button>