mirror of
https://github.com/open-webui/open-webui
synced 2025-04-06 21:54:55 +00:00
fix: Resolve Google Drive picker API loading and token handling
This commit is contained in:
parent
3378f35296
commit
aaacd28131
@ -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) {
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user