-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdrive.ts
More file actions
143 lines (123 loc) · 5.83 KB
/
drive.ts
File metadata and controls
143 lines (123 loc) · 5.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/env tsx
import { DriveSearch, ListDriveFiles } from '../packages/google/dist/packages/google/src/index.js';
import type { GoogleServiceConfig } from '../packages/google/dist/packages/google/src/types.js';
/**
* Test script to debug Google Drive description field issue
*
* Usage:
* 1. Set your environment variables:
* export GOOGLE_ACCESS_TOKEN="your_access_token"
* export GOOGLE_REFRESH_TOKEN="your_refresh_token"
* export GOOGLE_SERVICE_API_URL="your_api_url"
*
* 2. Run the script:
* npx tsx examples/drive.ts
*/
async function testDriveDescriptions() {
// Configuration from environment variables
const config: GoogleServiceConfig = {
accessToken: process.env.GOOGLE_ACCESS_TOKEN || '',
refreshToken: process.env.GOOGLE_REFRESH_TOKEN || '',
googleServiceApiUrl: process.env.GOOGLE_SERVICE_API_URL || 'http://localhost:8080'
};
// Validate configuration
if (!config.accessToken) {
console.error('❌ GOOGLE_ACCESS_TOKEN environment variable is required');
process.exit(1);
}
if (!config.googleServiceApiUrl) {
console.error('❌ GOOGLE_SERVICE_API_URL environment variable is required');
process.exit(1);
}
console.log('🔧 Configuration:');
console.log(` Access Token: ${config.accessToken.substring(0, 20)}...`);
console.log(` API URL: ${config.googleServiceApiUrl}`);
console.log('');
// Test 1: DriveSearch
console.log('🔍 Testing DriveSearch...');
try {
const driveSearch = new DriveSearch(config);
const searchFunction = driveSearch.toFunction();
// Search for all files (no filter) to get a broad sample
const searchResult = await searchFunction.func({ query: '' }) as any;
console.log(`✅ DriveSearch Success: ${searchResult.success}`);
if (searchResult.success && searchResult.files && searchResult.files.length > 0) {
console.log(`📁 Found ${searchResult.files.length} files`);
// Show the first file with all its fields
const firstFile = searchResult.files[0];
console.log('📄 First file details:');
console.log(` Available fields: [${Object.keys(firstFile).join(', ')}]`);
console.log(` ID: ${firstFile.id}`);
console.log(` Name: ${firstFile.name}`);
console.log(` Description: ${firstFile.description || '[NO DESCRIPTION FIELD]'}`);
console.log(` MimeType: ${firstFile.mimeType}`);
console.log(` Modified: ${firstFile.modifiedTime}`);
console.log(` Size: ${firstFile.size || '[NO SIZE FIELD]'}`);
console.log(` WebViewLink: ${firstFile.webViewLink}`);
// Check if any files have descriptions
const filesWithDescriptions = searchResult.files.filter((file: any) =>
file.description && file.description.trim() !== ''
);
console.log(`📝 Files with descriptions: ${filesWithDescriptions.length}/${searchResult.files.length}`);
if (filesWithDescriptions.length > 0) {
console.log('📝 Sample file with description:');
const sampleFile = filesWithDescriptions[0];
console.log(` Name: ${sampleFile.name}`);
console.log(` Description: "${sampleFile.description}"`);
}
} else {
console.log('❌ Search failed or returned no files');
console.log('Error:', searchResult.error);
}
} catch (error) {
console.error('❌ DriveSearch Error:', error);
}
console.log('\n' + '='.repeat(60) + '\n');
// Test 2: ListDriveFiles
console.log('📋 Testing ListDriveFiles...');
try {
const listFiles = new ListDriveFiles(config);
const listFunction = listFiles.toFunction();
const listResult = await listFunction.func({ pageSize: '10' }) as any;
console.log(`✅ ListDriveFiles Success: ${listResult.success}`);
if (listResult.success && listResult.files && listResult.files.length > 0) {
console.log(`📁 Found ${listResult.files.length} files`);
// Show the first file with all its fields
const firstFile = listResult.files[0];
console.log('📄 First file details:');
console.log(` Available fields: [${Object.keys(firstFile).join(', ')}]`);
console.log(` ID: ${firstFile.id}`);
console.log(` Name: ${firstFile.name}`);
console.log(` Description: ${firstFile.description || '[NO DESCRIPTION FIELD]'}`);
console.log(` MimeType: ${firstFile.mimeType}`);
console.log(` Modified: ${firstFile.modifiedTime}`);
console.log(` Size: ${firstFile.size || '[NO SIZE FIELD]'}`);
console.log(` WebViewLink: ${firstFile.webViewLink}`);
// Check if any files have descriptions
const filesWithDescriptions = listResult.files.filter((file: any) =>
file.description && file.description.trim() !== ''
);
console.log(`📝 Files with descriptions: ${filesWithDescriptions.length}/${listResult.files.length}`);
if (filesWithDescriptions.length > 0) {
console.log('📝 Sample file with description:');
const sampleFile = filesWithDescriptions[0];
console.log(` Name: ${sampleFile.name}`);
console.log(` Description: "${sampleFile.description}"`);
}
} else {
console.log('❌ List failed or returned no files');
console.log('Error:', listResult.error);
}
} catch (error) {
console.error('❌ ListDriveFiles Error:', error);
}
console.log('\n' + '='.repeat(60) + '\n');
console.log('🔍 Debug Summary:');
console.log('If descriptions are showing as "[NO DESCRIPTION FIELD]", the issue is likely:');
console.log('1. 📡 API not returning description field (check scopes/permissions)');
console.log('2. 🔧 Backend service filtering out descriptions');
console.log('3. 📝 Files genuinely don\'t have descriptions set');
console.log('4. 🔑 Insufficient OAuth scopes for metadata access');
}
// Run the test
testDriveDescriptions().catch(console.error);