fix: Update Google Drive file download URL generation to handle different file types

This commit is contained in:
Taylor Wilsdon (aider) 2024-12-16 10:32:01 -05:00
parent ae589bf604
commit cc9b7a1f1a

View File

@ -130,9 +130,22 @@ export const createPicker = () => {
throw new Error('Required file details missing');
}
// Construct download URL using usercontent format
// Construct download URL based on MIME type
console.log('Constructing download URL for fileId:', fileId);
const downloadUrl = `https://drive.usercontent.google.com/u/0/uc?id=${fileId}&export=download`;
const mimeType = doc[google.picker.Document.MIME_TYPE];
console.log('File MIME type:', mimeType);
let downloadUrl;
if (mimeType.includes('google-apps')) {
// Google Docs/Sheets/etc need export URL
const exportFormat = mimeType.includes('document') ? 'docx' :
mimeType.includes('spreadsheet') ? 'xlsx' :
mimeType.includes('presentation') ? 'pptx' : 'pdf';
downloadUrl = `https://www.googleapis.com/drive/v3/files/${fileId}/export?mimeType=application/${exportFormat}`;
} else {
// Regular files use direct download URL
downloadUrl = `https://www.googleapis.com/drive/v3/files/${fileId}?alt=media`;
}
console.log('Download URL constructed:', downloadUrl);
console.log('Current token value:', token ? 'Token exists' : 'No token');