mirror of
https://github.com/open-webui/open-webui
synced 2025-06-23 02:16:52 +00:00
fix: Improve Google Drive picker initialization and error handling
This commit is contained in:
parent
eed7cfd2a2
commit
85508106a8
@ -498,11 +498,15 @@
|
|||||||
}}
|
}}
|
||||||
uploadGoogleDriveHandler={async () => {
|
uploadGoogleDriveHandler={async () => {
|
||||||
try {
|
try {
|
||||||
|
if (!import.meta.env.VITE_GOOGLE_API_KEY || !import.meta.env.VITE_GOOGLE_CLIENT_ID) {
|
||||||
|
throw new Error('Google Drive API credentials not configured');
|
||||||
|
}
|
||||||
const fileData = await createPicker();
|
const fileData = await createPicker();
|
||||||
if (fileData) {
|
if (fileData) {
|
||||||
dispatch('upload', { type: 'google-drive', data: fileData });
|
dispatch('upload', { type: 'google-drive', data: fileData });
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.error('Google Drive Error:', error);
|
||||||
toast.error('Error accessing Google Drive: ' + error.message);
|
toast.error('Error accessing Google Drive: ' + error.message);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
@ -5,6 +5,7 @@ const SCOPE = ['https://www.googleapis.com/auth/drive.readonly'];
|
|||||||
|
|
||||||
let pickerApiLoaded = false;
|
let pickerApiLoaded = false;
|
||||||
let oauthToken: string | null = null;
|
let oauthToken: string | null = null;
|
||||||
|
let initialized = false;
|
||||||
|
|
||||||
export const loadGoogleDriveApi = () => {
|
export const loadGoogleDriveApi = () => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
@ -62,13 +63,17 @@ export const getAuthToken = async () => {
|
|||||||
return oauthToken;
|
return oauthToken;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const initialize = async () => {
|
||||||
|
if (!initialized) {
|
||||||
|
await Promise.all([loadGoogleDriveApi(), loadGoogleAuthApi()]);
|
||||||
|
initialized = true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export const createPicker = () => {
|
export const createPicker = () => {
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
if (!pickerApiLoaded) {
|
await initialize();
|
||||||
await loadGoogleDriveApi();
|
|
||||||
}
|
|
||||||
|
|
||||||
const token = await getAuthToken();
|
const token = await getAuthToken();
|
||||||
if (!token) {
|
if (!token) {
|
||||||
throw new Error('Unable to get OAuth token');
|
throw new Error('Unable to get OAuth token');
|
||||||
|
Loading…
Reference in New Issue
Block a user