fix: Resolve Google Drive picker API loading and token handling

This commit is contained in:
Taylor Wilsdon (aider) 2024-12-15 18:45:40 -05:00
parent 3378f35296
commit aaacd28131
2 changed files with 15 additions and 15 deletions

View File

@ -501,15 +501,9 @@
try {
const fileData = await createPicker();
if (fileData) {
// Pass the OAuth token along with the file data
dispatch('upload', {
type: 'google-drive',
data: {
name: fileData.name,
url: fileData.url,
id: fileData.id,
token: await getAuthToken() // Include OAuth token for download
}
data: fileData // fileData now includes token
});
}
} catch (error) {

View File

@ -23,20 +23,24 @@ export const loadGoogleDriveApi = () => {
const script = document.createElement('script');
script.src = 'https://apis.google.com/js/api.js';
script.onload = () => {
gapi.load('picker', {
gapi.load('client:picker', {
callback: () => {
pickerApiLoaded = true;
resolve(true);
gapi.client.load('picker', 'v1').then(() => {
pickerApiLoaded = true;
resolve(true);
});
}
});
};
script.onerror = reject;
document.body.appendChild(script);
} else {
gapi.load('picker', {
gapi.load('client:picker', {
callback: () => {
pickerApiLoaded = true;
resolve(true);
gapi.client.load('picker', 'v1').then(() => {
pickerApiLoaded = true;
resolve(true);
});
}
});
}
@ -112,11 +116,13 @@ export const createPicker = () => {
const fileUrl = doc[google.picker.Document.URL];
// Get the downloadUrl using the alt=media parameter
const downloadUrl = `https://www.googleapis.com/drive/v3/files/${fileId}?alt=media`;
// Construct download URL with access token
const downloadUrl = `https://www.googleapis.com/drive/v3/files/${fileId}?alt=media&access_token=${oauthToken}`;
resolve({
id: fileId,
name: fileName,
url: downloadUrl
url: downloadUrl,
token: oauthToken // Include token for future use
});
} else if (data[google.picker.Response.ACTION] === google.picker.Action.CANCEL) {
resolve(null);