(feat:drive) oauth for drive.file scope, picker

This commit is contained in:
ManishMadan2882
2025-09-17 19:37:01 +05:30
parent ec0c4c3b84
commit da2f8477e6
8 changed files with 344 additions and 14 deletions

View File

@@ -35,6 +35,7 @@ import {
} from './types/ingestor';
import {FilePicker} from '../components/FilePicker';
import GoogleDrivePicker from '../components/GoogleDrivePicker';
import CrawlerIcon from '../assets/crawler.svg';
import FileUploadIcon from '../assets/file_upload.svg';
@@ -244,6 +245,19 @@ function Upload({
initialSelectedFolders={selectedFolders}
/>
);
case 'google_drive_picker':
return (
<GoogleDrivePicker
key={field.name}
onSelectionChange={(selectedFileIds: string[], selectedFolderIds: string[] = []) => {
setSelectedFiles(selectedFileIds);
setSelectedFolders(selectedFolderIds);
}}
token={token}
initialSelectedFiles={selectedFiles}
initialSelectedFolders={selectedFolders}
/>
);
default:
return null;
}
@@ -384,8 +398,7 @@ function Upload({
data?.find(
(d: Doc) => d.type?.toLowerCase() === 'local',
),
),
);
));
});
setProgress(
(progress) =>
@@ -509,18 +522,19 @@ function Upload({
formData.append('user', 'local');
formData.append('source', ingestor.type as string);
let configData;
let configData: any = {};
const schema: FormField[] = IngestorFormSchemas[ingestor.type as IngestorType];
const hasLocalFilePicker = schema.some((field: FormField) => field.type === 'local_file_picker');
const hasRemoteFilePicker = schema.some((field: FormField) => field.type === 'remote_file_picker');
const hasGoogleDrivePicker = schema.some((field: FormField) => field.type === 'google_drive_picker');
if (hasLocalFilePicker) {
files.forEach((file) => {
formData.append('file', file);
});
configData = { ...ingestor.config };
} else if (hasRemoteFilePicker) {
} else if (hasRemoteFilePicker || hasGoogleDrivePicker) {
const sessionToken = getSessionToken(ingestor.type as string);
configData = {
provider: ingestor.type as string,
@@ -606,12 +620,13 @@ function Upload({
const schema: FormField[] = IngestorFormSchemas[ingestor.type as IngestorType];
const hasLocalFilePicker = schema.some((field: FormField) => field.type === 'local_file_picker');
const hasRemoteFilePicker = schema.some((field: FormField) => field.type === 'remote_file_picker');
const hasGoogleDrivePicker = schema.some((field: FormField) => field.type === 'google_drive_picker');
if (hasLocalFilePicker) {
if (files.length === 0) {
return true;
}
} else if (hasRemoteFilePicker) {
} else if (hasRemoteFilePicker || hasGoogleDrivePicker) {
if (selectedFiles.length === 0 && selectedFolders.length === 0) {
return true;
}

View File

@@ -13,7 +13,7 @@ export type IngestorFormData = {
data: string;
};
export type FieldType = 'string' | 'number' | 'enum' | 'boolean' | 'local_file_picker' | 'remote_file_picker';
export type FieldType = 'string' | 'number' | 'enum' | 'boolean' | 'local_file_picker' | 'remote_file_picker' | 'google_drive_picker';
export interface FormField {
name: string;
@@ -36,7 +36,12 @@ export const IngestorFormSchemas: Record<IngestorType, FormField[]> = {
],
github: [{ name: 'repo_url', label: 'Repository URL', type: 'string', required: true }],
google_drive: [
{ name: 'file_picker', label: 'Select files', type: 'remote_file_picker', required: true },
{
name: 'files',
label: 'Select Files from Google Drive',
type: 'google_drive_picker',
required: true,
},
{ name: 'recursive', label: 'Include subfolders', type: 'boolean', required: false },
],
local_file: [