mirror of
https://github.com/open-webui/open-webui
synced 2025-01-01 08:42:14 +00:00
feat: Implement dynamic Google Drive credentials fetching from backend config
This commit is contained in:
parent
e4b2d29cba
commit
4528770a0e
@ -1,6 +1,17 @@
|
|||||||
// Google Drive Picker API configuration
|
// Google Drive Picker API configuration
|
||||||
const API_KEY = import.meta.env.VITE_GOOGLE_API_KEY;
|
let API_KEY = '';
|
||||||
const CLIENT_ID = import.meta.env.VITE_GOOGLE_CLIENT_ID;
|
let CLIENT_ID = '';
|
||||||
|
|
||||||
|
// Function to fetch credentials from backend config
|
||||||
|
async function getCredentials() {
|
||||||
|
const response = await fetch('/api/retrieval/config');
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error('Failed to fetch Google Drive credentials');
|
||||||
|
}
|
||||||
|
const config = await response.json();
|
||||||
|
API_KEY = config.google_drive?.api_key;
|
||||||
|
CLIENT_ID = config.google_drive?.client_id;
|
||||||
|
}
|
||||||
const SCOPE = [
|
const SCOPE = [
|
||||||
'https://www.googleapis.com/auth/drive.readonly',
|
'https://www.googleapis.com/auth/drive.readonly',
|
||||||
'https://www.googleapis.com/auth/drive.file'
|
'https://www.googleapis.com/auth/drive.file'
|
||||||
@ -11,7 +22,7 @@ const validateCredentials = () => {
|
|||||||
if (!API_KEY || !CLIENT_ID) {
|
if (!API_KEY || !CLIENT_ID) {
|
||||||
throw new Error('Google Drive API credentials not configured');
|
throw new Error('Google Drive API credentials not configured');
|
||||||
}
|
}
|
||||||
if (API_KEY === 'your-api-key' || CLIENT_ID === 'your-client-id') {
|
if (API_KEY === '' || CLIENT_ID === '') {
|
||||||
throw new Error('Please configure valid Google Drive API credentials');
|
throw new Error('Please configure valid Google Drive API credentials');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -82,6 +93,7 @@ export const getAuthToken = async () => {
|
|||||||
|
|
||||||
const initialize = async () => {
|
const initialize = async () => {
|
||||||
if (!initialized) {
|
if (!initialized) {
|
||||||
|
await getCredentials();
|
||||||
validateCredentials();
|
validateCredentials();
|
||||||
await Promise.all([loadGoogleDriveApi(), loadGoogleAuthApi()]);
|
await Promise.all([loadGoogleDriveApi(), loadGoogleAuthApi()]);
|
||||||
initialized = true;
|
initialized = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user