mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-28 21:49:40 +02:00
fix: Google Drive folder handling and connector page updates
This commit is contained in:
parent
10c98745cd
commit
27beac4f62
4 changed files with 40 additions and 46 deletions
|
|
@ -543,13 +543,13 @@ async def index_connector_content(
|
||||||
None,
|
None,
|
||||||
description="End date for indexing (YYYY-MM-DD format). If not provided, uses today's date",
|
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,
|
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,
|
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),
|
session: AsyncSession = Depends(get_async_session),
|
||||||
user: User = Depends(current_active_user),
|
user: User = Depends(current_active_user),
|
||||||
|
|
@ -763,15 +763,22 @@ async def index_connector_content(
|
||||||
index_google_drive_files_task,
|
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(
|
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(
|
index_google_drive_files_task.delay(
|
||||||
connector_id,
|
connector_id,
|
||||||
search_space_id,
|
search_space_id,
|
||||||
str(user.id),
|
str(user.id),
|
||||||
folder_id,
|
folder_ids, # Pass as comma-separated string
|
||||||
folder_name,
|
folder_names, # Pass as comma-separated string
|
||||||
)
|
)
|
||||||
response_message = "Google Drive indexing started in the background."
|
response_message = "Google Drive indexing started in the background."
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -511,8 +511,8 @@ async def process_file_in_background(
|
||||||
session, filename, markdown_content, search_space_id, user_id
|
session, filename, markdown_content, search_space_id, user_id
|
||||||
)
|
)
|
||||||
|
|
||||||
# Update from connector if provided
|
if connector:
|
||||||
await _update_document_from_connector(result, connector, session)
|
await _update_document_from_connector(result, connector, session)
|
||||||
|
|
||||||
if result:
|
if result:
|
||||||
await task_logger.log_task_success(
|
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
|
session, filename, transcribed_text, search_space_id, user_id
|
||||||
)
|
)
|
||||||
|
|
||||||
# Update from connector if provided
|
if connector:
|
||||||
await _update_document_from_connector(result, connector, session)
|
await _update_document_from_connector(result, connector, session)
|
||||||
|
|
||||||
if result:
|
if result:
|
||||||
await task_logger.log_task_success(
|
await task_logger.log_task_success(
|
||||||
|
|
@ -778,8 +778,8 @@ async def process_file_in_background(
|
||||||
session, filename, docs, search_space_id, user_id
|
session, filename, docs, search_space_id, user_id
|
||||||
)
|
)
|
||||||
|
|
||||||
# Update from connector if provided
|
if connector:
|
||||||
await _update_document_from_connector(result, connector, session)
|
await _update_document_from_connector(result, connector, session)
|
||||||
|
|
||||||
if result:
|
if result:
|
||||||
# Update page usage after successful processing
|
# Update page usage after successful processing
|
||||||
|
|
@ -925,8 +925,8 @@ async def process_file_in_background(
|
||||||
user_id, final_page_count, allow_exceed=True
|
user_id, final_page_count, allow_exceed=True
|
||||||
)
|
)
|
||||||
|
|
||||||
# Update from connector if provided
|
if connector:
|
||||||
await _update_document_from_connector(last_created_doc, connector, session)
|
await _update_document_from_connector(last_created_doc, connector, session)
|
||||||
|
|
||||||
await task_logger.log_task_success(
|
await task_logger.log_task_success(
|
||||||
log_entry,
|
log_entry,
|
||||||
|
|
@ -1052,8 +1052,8 @@ async def process_file_in_background(
|
||||||
user_id, final_page_count, allow_exceed=True
|
user_id, final_page_count, allow_exceed=True
|
||||||
)
|
)
|
||||||
|
|
||||||
# Update from connector if provided
|
if connector:
|
||||||
await _update_document_from_connector(doc_result, connector, session)
|
await _update_document_from_connector(doc_result, connector, session)
|
||||||
|
|
||||||
await task_logger.log_task_success(
|
await task_logger.log_task_success(
|
||||||
log_entry,
|
log_entry,
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,13 @@
|
||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
|
import { useAtomValue } from "jotai";
|
||||||
import { ArrowLeft, Check, ExternalLink, Loader2 } from "lucide-react";
|
import { ArrowLeft, Check, ExternalLink, Loader2 } from "lucide-react";
|
||||||
import { motion } from "motion/react";
|
import { motion } from "motion/react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { useParams, useRouter, useSearchParams } from "next/navigation";
|
import { useParams, useRouter } from "next/navigation";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
|
import { connectorsAtom } from "@/atoms/connectors/connector-query.atoms";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import {
|
import {
|
||||||
Card,
|
Card,
|
||||||
|
|
@ -17,45 +19,30 @@ import {
|
||||||
} from "@/components/ui/card";
|
} from "@/components/ui/card";
|
||||||
import { EnumConnectorName } from "@/contracts/enums/connector";
|
import { EnumConnectorName } from "@/contracts/enums/connector";
|
||||||
import { getConnectorIcon } from "@/contracts/enums/connectorIcons";
|
import { getConnectorIcon } from "@/contracts/enums/connectorIcons";
|
||||||
import {
|
import type { SearchSourceConnector } from "@/contracts/types/connector.types";
|
||||||
type SearchSourceConnector,
|
|
||||||
useSearchSourceConnectors,
|
|
||||||
} from "@/hooks/use-search-source-connectors";
|
|
||||||
import { authenticatedFetch } from "@/lib/auth-utils";
|
import { authenticatedFetch } from "@/lib/auth-utils";
|
||||||
|
|
||||||
export default function GoogleDriveConnectorPage() {
|
export default function GoogleDriveConnectorPage() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const params = useParams();
|
const params = useParams();
|
||||||
const searchParams = useSearchParams();
|
|
||||||
const searchSpaceId = params.search_space_id as string;
|
const searchSpaceId = params.search_space_id as string;
|
||||||
|
|
||||||
const [isConnecting, setIsConnecting] = useState(false);
|
const [isConnecting, setIsConnecting] = useState(false);
|
||||||
const [doesConnectorExist, setDoesConnectorExist] = 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(() => {
|
useEffect(() => {
|
||||||
const success = searchParams.get("success");
|
fetchConnectors().then((data) => {
|
||||||
|
const connectors = data.data || [];
|
||||||
fetchConnectors(Number.parseInt(searchSpaceId)).then((data) => {
|
const connector = connectors.find(
|
||||||
const driveConnector = data.find(
|
|
||||||
(c: SearchSourceConnector) => c.connector_type === EnumConnectorName.GOOGLE_DRIVE_CONNECTOR
|
(c: SearchSourceConnector) => c.connector_type === EnumConnectorName.GOOGLE_DRIVE_CONNECTOR
|
||||||
);
|
);
|
||||||
|
if (connector) {
|
||||||
if (driveConnector) {
|
|
||||||
setDoesConnectorExist(true);
|
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 () => {
|
const handleConnectGoogle = async () => {
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -268,8 +268,8 @@ export const useSearchSourceConnectors = (lazy: boolean = false, searchSpaceId?:
|
||||||
searchSpaceId: string | number,
|
searchSpaceId: string | number,
|
||||||
startDate?: string,
|
startDate?: string,
|
||||||
endDate?: string,
|
endDate?: string,
|
||||||
folderId?: string,
|
folderIds?: string,
|
||||||
folderName?: string
|
folderNames?: string
|
||||||
) => {
|
) => {
|
||||||
try {
|
try {
|
||||||
// Build query parameters
|
// Build query parameters
|
||||||
|
|
@ -282,11 +282,11 @@ export const useSearchSourceConnectors = (lazy: boolean = false, searchSpaceId?:
|
||||||
if (endDate) {
|
if (endDate) {
|
||||||
params.append("end_date", endDate);
|
params.append("end_date", endDate);
|
||||||
}
|
}
|
||||||
if (folderId) {
|
if (folderIds) {
|
||||||
params.append("folder_id", folderId);
|
params.append("folder_ids", folderIds);
|
||||||
}
|
}
|
||||||
if (folderName) {
|
if (folderNames) {
|
||||||
params.append("folder_name", folderName);
|
params.append("folder_names", folderNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await authenticatedFetch(
|
const response = await authenticatedFetch(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue