diff --git a/surfsense_backend/app/routes/search_source_connectors_routes.py b/surfsense_backend/app/routes/search_source_connectors_routes.py index af1f18513..894be54c4 100644 --- a/surfsense_backend/app/routes/search_source_connectors_routes.py +++ b/surfsense_backend/app/routes/search_source_connectors_routes.py @@ -543,13 +543,13 @@ async def index_connector_content( None, description="End date for indexing (YYYY-MM-DD format). If not provided, uses today's date", ), - folder_id: str = Query( + folder_ids: str = Query( None, - description="[Google Drive only] Folder ID to index. If not provided, uses the connector's saved selected_folder_id", + description="[Google Drive only] Comma-separated folder IDs to index", ), - folder_name: str = Query( + folder_names: str = Query( None, - description="[Google Drive only] Folder name for display purposes", + description="[Google Drive only] Comma-separated folder names for display purposes", ), session: AsyncSession = Depends(get_async_session), user: User = Depends(current_active_user), @@ -763,15 +763,22 @@ async def index_connector_content( index_google_drive_files_task, ) + if not folder_ids or not folder_names: + raise HTTPException( + status_code=400, + detail="Google Drive indexing requires folder_ids and folder_names parameters", + ) + logger.info( - f"Triggering Google Drive indexing for connector {connector_id} into search space {search_space_id}, folder: {folder_name or 'default'}" + f"Triggering Google Drive indexing for connector {connector_id} into search space {search_space_id}, folders: {folder_names}" ) + # Pass comma-separated strings directly to Celery task index_google_drive_files_task.delay( connector_id, search_space_id, str(user.id), - folder_id, - folder_name, + folder_ids, # Pass as comma-separated string + folder_names, # Pass as comma-separated string ) response_message = "Google Drive indexing started in the background." diff --git a/surfsense_backend/app/tasks/document_processors/file_processors.py b/surfsense_backend/app/tasks/document_processors/file_processors.py index 61f484ae1..cda4ec88b 100644 --- a/surfsense_backend/app/tasks/document_processors/file_processors.py +++ b/surfsense_backend/app/tasks/document_processors/file_processors.py @@ -511,8 +511,8 @@ async def process_file_in_background( session, filename, markdown_content, search_space_id, user_id ) - # Update from connector if provided - await _update_document_from_connector(result, connector, session) + if connector: + await _update_document_from_connector(result, connector, session) if result: await task_logger.log_task_success( @@ -630,8 +630,8 @@ async def process_file_in_background( session, filename, transcribed_text, search_space_id, user_id ) - # Update from connector if provided - await _update_document_from_connector(result, connector, session) + if connector: + await _update_document_from_connector(result, connector, session) if result: await task_logger.log_task_success( @@ -778,8 +778,8 @@ async def process_file_in_background( session, filename, docs, search_space_id, user_id ) - # Update from connector if provided - await _update_document_from_connector(result, connector, session) + if connector: + await _update_document_from_connector(result, connector, session) if result: # Update page usage after successful processing @@ -925,8 +925,8 @@ async def process_file_in_background( user_id, final_page_count, allow_exceed=True ) - # Update from connector if provided - await _update_document_from_connector(last_created_doc, connector, session) + if connector: + await _update_document_from_connector(last_created_doc, connector, session) await task_logger.log_task_success( log_entry, @@ -1052,8 +1052,8 @@ async def process_file_in_background( user_id, final_page_count, allow_exceed=True ) - # Update from connector if provided - await _update_document_from_connector(doc_result, connector, session) + if connector: + await _update_document_from_connector(doc_result, connector, session) await task_logger.log_task_success( log_entry, diff --git a/surfsense_web/app/dashboard/[search_space_id]/connectors/add/google-drive-connector/page.tsx b/surfsense_web/app/dashboard/[search_space_id]/connectors/add/google-drive-connector/page.tsx index b9fb8d953..4f0c2b23f 100644 --- a/surfsense_web/app/dashboard/[search_space_id]/connectors/add/google-drive-connector/page.tsx +++ b/surfsense_web/app/dashboard/[search_space_id]/connectors/add/google-drive-connector/page.tsx @@ -1,11 +1,13 @@ "use client"; +import { useAtomValue } from "jotai"; import { ArrowLeft, Check, ExternalLink, Loader2 } from "lucide-react"; import { motion } from "motion/react"; import Link from "next/link"; -import { useParams, useRouter, useSearchParams } from "next/navigation"; +import { useParams, useRouter } from "next/navigation"; import { useEffect, useState } from "react"; import { toast } from "sonner"; +import { connectorsAtom } from "@/atoms/connectors/connector-query.atoms"; import { Button } from "@/components/ui/button"; import { Card, @@ -17,45 +19,30 @@ import { } from "@/components/ui/card"; import { EnumConnectorName } from "@/contracts/enums/connector"; import { getConnectorIcon } from "@/contracts/enums/connectorIcons"; -import { - type SearchSourceConnector, - useSearchSourceConnectors, -} from "@/hooks/use-search-source-connectors"; +import type { SearchSourceConnector } from "@/contracts/types/connector.types"; import { authenticatedFetch } from "@/lib/auth-utils"; export default function GoogleDriveConnectorPage() { const router = useRouter(); const params = useParams(); - const searchParams = useSearchParams(); const searchSpaceId = params.search_space_id as string; const [isConnecting, setIsConnecting] = useState(false); const [doesConnectorExist, setDoesConnectorExist] = useState(false); - const { fetchConnectors } = useSearchSourceConnectors(true, Number.parseInt(searchSpaceId)); + const { refetch: fetchConnectors } = useAtomValue(connectorsAtom); - // Check if connector exists and handle OAuth success useEffect(() => { - const success = searchParams.get("success"); - - fetchConnectors(Number.parseInt(searchSpaceId)).then((data) => { - const driveConnector = data.find( + fetchConnectors().then((data) => { + const connectors = data.data || []; + const connector = connectors.find( (c: SearchSourceConnector) => c.connector_type === EnumConnectorName.GOOGLE_DRIVE_CONNECTOR ); - - if (driveConnector) { + if (connector) { setDoesConnectorExist(true); - - // If just connected, show success and redirect - if (success === "true") { - toast.success("Google Drive connected successfully!"); - setTimeout(() => { - router.push(`/dashboard/${searchSpaceId}/connectors`); - }, 1500); - } } }); - }, [searchParams, fetchConnectors, searchSpaceId, router]); + }, []); const handleConnectGoogle = async () => { try { diff --git a/surfsense_web/hooks/use-search-source-connectors.ts b/surfsense_web/hooks/use-search-source-connectors.ts index ee8ce5518..14c21831b 100644 --- a/surfsense_web/hooks/use-search-source-connectors.ts +++ b/surfsense_web/hooks/use-search-source-connectors.ts @@ -268,8 +268,8 @@ export const useSearchSourceConnectors = (lazy: boolean = false, searchSpaceId?: searchSpaceId: string | number, startDate?: string, endDate?: string, - folderId?: string, - folderName?: string + folderIds?: string, + folderNames?: string ) => { try { // Build query parameters @@ -282,11 +282,11 @@ export const useSearchSourceConnectors = (lazy: boolean = false, searchSpaceId?: if (endDate) { params.append("end_date", endDate); } - if (folderId) { - params.append("folder_id", folderId); + if (folderIds) { + params.append("folder_ids", folderIds); } - if (folderName) { - params.append("folder_name", folderName); + if (folderNames) { + params.append("folder_names", folderNames); } const response = await authenticatedFetch(