fix(drive): ensure list tool only shows files from selected folder (#142)

Previously, the list tool was showing files from outside the selected folder.
Modified the query parameters to properly filter files by the selected folder ID.
Also added 'trashed = false' condition to exclude deleted items from results.

Fixes #139

Co-authored-by: Salif Tankoano <tanksalif@gmail.com>
This commit is contained in:
Emir Karabeg
2025-03-21 20:38:32 -07:00
committed by GitHub
co-authored by Salif Tankoano
parent 017de23b5a
commit 0b2eccc660
2 changed files with 14 additions and 17 deletions
+6 -15
View File
@@ -89,7 +89,7 @@ export const GoogleDriveBlock: BlockConfig<GoogleDriveResponse> = {
},
// List Fields - Folder Selector
{
id: 'folderSelector',
id: 'folderId',
title: 'Select Folder',
type: 'file-selector',
layout: 'full',
@@ -110,7 +110,7 @@ export const GoogleDriveBlock: BlockConfig<GoogleDriveResponse> = {
condition: {
field: 'operation',
value: 'list',
and: { field: 'folderSelector', value: '' },
and: { field: 'folderId', value: '' },
},
},
{
@@ -146,21 +146,13 @@ export const GoogleDriveBlock: BlockConfig<GoogleDriveResponse> = {
}
},
params: (params) => {
const { credential, folderSelector, folderId, ...rest } = params
// Convert pageSize to number if it exists
const pageSize = rest.pageSize ? parseInt(rest.pageSize as string, 10) : undefined
// Use the selected folder ID or the manually entered one
// If folderSelector is provided, it's from the file selector and contains the folder ID
// If not, fall back to manually entered ID
const effectiveFolderId = (folderSelector || folderId || '').trim()
const { credential, folderId, ...rest } = params
return {
accessToken: credential,
folderId: folderId?.trim() || '',
pageSize: rest.pageSize ? parseInt(rest.pageSize as string, 10) : undefined,
...rest,
folderId: effectiveFolderId,
pageSize,
credential,
}
},
},
@@ -175,7 +167,6 @@ export const GoogleDriveBlock: BlockConfig<GoogleDriveResponse> = {
// Download operation inputs
fileId: { type: 'string', required: false },
// List operation inputs
folderSelector: { type: 'string', required: false },
folderId: { type: 'string', required: false },
query: { type: 'string', required: false },
pageSize: { type: 'number', required: false },
+8 -2
View File
@@ -26,13 +26,19 @@ export const listTool: ToolConfig<GoogleDriveToolParams, GoogleDriveListResponse
'files(id,name,mimeType,webViewLink,webContentLink,size,createdTime,modifiedTime,parents),nextPageToken'
)
// Build the query conditions
const conditions = ['trashed = false'] // Always exclude trashed files
if (params.folderId) {
url.searchParams.append('q', `'${params.folderId}' in parents`)
conditions.push(`'${params.folderId}' in parents`)
}
// Combine all conditions with AND
url.searchParams.append('q', conditions.join(' and '))
if (params.query) {
const existingQ = url.searchParams.get('q')
const queryPart = `name contains '${params.query}'`
url.searchParams.set('q', existingQ ? `${existingQ} and ${queryPart}` : queryPart)
url.searchParams.set('q', `${existingQ} and ${queryPart}`)
}
if (params.pageSize) {
url.searchParams.append('pageSize', params.pageSize.toString())