mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 17:00:15 +01:00
🔑 feat: Set Google Service Key File Path (#8130)
This commit is contained in:
parent
3f3cfefc52
commit
20100e120b
3 changed files with 47 additions and 14 deletions
|
|
@ -1,3 +1,5 @@
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
const { EModelEndpoint } = require('librechat-data-provider');
|
const { EModelEndpoint } = require('librechat-data-provider');
|
||||||
const { isUserProvided } = require('~/server/utils');
|
const { isUserProvided } = require('~/server/utils');
|
||||||
const { config } = require('./EndpointService');
|
const { config } = require('./EndpointService');
|
||||||
|
|
@ -11,9 +13,21 @@ const { openAIApiKey, azureOpenAIApiKey, useAzurePlugins, userProvidedOpenAI, go
|
||||||
async function loadAsyncEndpoints(req) {
|
async function loadAsyncEndpoints(req) {
|
||||||
let i = 0;
|
let i = 0;
|
||||||
let serviceKey, googleUserProvides;
|
let serviceKey, googleUserProvides;
|
||||||
|
const serviceKeyPath =
|
||||||
|
process.env.GOOGLE_SERVICE_KEY_FILE_PATH ||
|
||||||
|
path.join(__dirname, '../../..', 'data', 'auth.json');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (process.env.GOOGLE_SERVICE_KEY_FILE_PATH) {
|
||||||
|
const absolutePath = path.isAbsolute(serviceKeyPath)
|
||||||
|
? serviceKeyPath
|
||||||
|
: path.resolve(serviceKeyPath);
|
||||||
|
const fileContent = fs.readFileSync(absolutePath, 'utf8');
|
||||||
|
serviceKey = JSON.parse(fileContent);
|
||||||
|
} else {
|
||||||
serviceKey = require('~/data/auth.json');
|
serviceKey = require('~/data/auth.json');
|
||||||
} catch (e) {
|
}
|
||||||
|
} catch {
|
||||||
if (i === 0) {
|
if (i === 0) {
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
const { getGoogleConfig, isEnabled } = require('@librechat/api');
|
const { getGoogleConfig, isEnabled } = require('@librechat/api');
|
||||||
const { EModelEndpoint, AuthKeys } = require('librechat-data-provider');
|
const { EModelEndpoint, AuthKeys } = require('librechat-data-provider');
|
||||||
const { getUserKey, checkUserKeyExpiry } = require('~/server/services/UserService');
|
const { getUserKey, checkUserKeyExpiry } = require('~/server/services/UserService');
|
||||||
|
|
@ -15,8 +17,20 @@ const initializeClient = async ({ req, res, endpointOption, overrideModel, optio
|
||||||
}
|
}
|
||||||
|
|
||||||
let serviceKey = {};
|
let serviceKey = {};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (process.env.GOOGLE_SERVICE_KEY_FILE_PATH) {
|
||||||
|
const serviceKeyPath =
|
||||||
|
process.env.GOOGLE_SERVICE_KEY_FILE_PATH ||
|
||||||
|
path.join(__dirname, '../../../../..', 'data', 'auth.json');
|
||||||
|
const absolutePath = path.isAbsolute(serviceKeyPath)
|
||||||
|
? serviceKeyPath
|
||||||
|
: path.resolve(serviceKeyPath);
|
||||||
|
const fileContent = fs.readFileSync(absolutePath, 'utf8');
|
||||||
|
serviceKey = JSON.parse(fileContent);
|
||||||
|
} else {
|
||||||
serviceKey = require('~/data/auth.json');
|
serviceKey = require('~/data/auth.json');
|
||||||
|
}
|
||||||
} catch (_e) {
|
} catch (_e) {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -439,15 +439,20 @@ async function loadGoogleAuthConfig(): Promise<{
|
||||||
serviceAccount: GoogleServiceAccount;
|
serviceAccount: GoogleServiceAccount;
|
||||||
accessToken: string;
|
accessToken: string;
|
||||||
}> {
|
}> {
|
||||||
/** Path from current file to project root auth.json */
|
/** Path from environment variable or default location */
|
||||||
const authJsonPath = path.join(__dirname, '..', '..', '..', 'api', 'data', 'auth.json');
|
const serviceKeyPath =
|
||||||
|
process.env.GOOGLE_SERVICE_KEY_FILE_PATH ||
|
||||||
|
path.join(__dirname, '..', '..', '..', 'api', 'data', 'auth.json');
|
||||||
|
const absolutePath = path.isAbsolute(serviceKeyPath)
|
||||||
|
? serviceKeyPath
|
||||||
|
: path.resolve(serviceKeyPath);
|
||||||
|
|
||||||
let serviceKey: GoogleServiceAccount;
|
let serviceKey: GoogleServiceAccount;
|
||||||
try {
|
try {
|
||||||
const authJsonContent = fs.readFileSync(authJsonPath, 'utf8');
|
const authJsonContent = fs.readFileSync(absolutePath, 'utf8');
|
||||||
serviceKey = JSON.parse(authJsonContent) as GoogleServiceAccount;
|
serviceKey = JSON.parse(authJsonContent) as GoogleServiceAccount;
|
||||||
} catch {
|
} catch {
|
||||||
throw new Error(`Google service account not found at ${authJsonPath}`);
|
throw new Error(`Google service account not found at ${absolutePath}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!serviceKey.client_email || !serviceKey.private_key || !serviceKey.project_id) {
|
if (!serviceKey.client_email || !serviceKey.private_key || !serviceKey.project_id) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue