mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-19 09:50:15 +01:00
🗝️ refactor: loadServiceKey to Support Stringified JSON and Env Var Renaming (#8317)
* feat: Enhance loadServiceKey to support stringified JSON input * chore: Update GOOGLE_SERVICE_KEY_FILE_PATH to GOOGLE_SERVICE_KEY_FILE for consistency
This commit is contained in:
parent
e57fc83d40
commit
7e37211458
5 changed files with 112 additions and 7 deletions
|
|
@ -18,8 +18,8 @@ export interface GoogleServiceKey {
|
|||
}
|
||||
|
||||
/**
|
||||
* Load Google service key from file path or URL
|
||||
* @param keyPath - The path or URL to the service key file
|
||||
* Load Google service key from file path, URL, or stringified JSON
|
||||
* @param keyPath - The path to the service key file, URL to fetch it from, or stringified JSON
|
||||
* @returns The parsed service key object or null if failed
|
||||
*/
|
||||
export async function loadServiceKey(keyPath: string): Promise<GoogleServiceKey | null> {
|
||||
|
|
@ -29,8 +29,17 @@ export async function loadServiceKey(keyPath: string): Promise<GoogleServiceKey
|
|||
|
||||
let serviceKey: unknown;
|
||||
|
||||
// Check if it's a stringified JSON (starts with '{')
|
||||
if (keyPath.trim().startsWith('{')) {
|
||||
try {
|
||||
serviceKey = JSON.parse(keyPath);
|
||||
} catch (error) {
|
||||
logger.error('Failed to parse service key from stringified JSON', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
// Check if it's a URL
|
||||
if (/^https?:\/\//.test(keyPath)) {
|
||||
else if (/^https?:\/\//.test(keyPath)) {
|
||||
try {
|
||||
const response = await axios.get(keyPath);
|
||||
serviceKey = response.data;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue