fix(auth): support ${ENV_VAR} syntax expansion and prioritize CCLOAD_API_KEY in image provider
This commit is contained in:
1 parent
723882b974
commit
7472270e1f
4 files changed
+28
-8
No files matched your search
Vendored
+8
-3
@@ -27,7 +27,12 @@ const SUPPORTED_ASPECT_RATIOS = [
|
||||
];
|
||||
export function resolvePluginApiKey(rawKey) {
|
||||
if (typeof rawKey === "string") {
|
||||
return normalizeOptionalString(rawKey);
|
||||
const trimmed = rawKey.trim();
|
||||
const envMatch = trimmed.match(/^\$\{([A-Za-z0-9_]+)\}$/);
|
||||
if (envMatch) {
|
||||
return normalizeOptionalString(process.env[envMatch[1]]);
|
||||
}
|
||||
return normalizeOptionalString(trimmed);
|
||||
}
|
||||
if (rawKey && typeof rawKey === "object" && typeof rawKey.id === "string") {
|
||||
return normalizeOptionalString(process.env[rawKey.id]);
|
||||
@@ -82,8 +87,8 @@ export function buildOpenAIImageGenerationProvider({ isProviderApiKeyConfigured,
|
||||
if (resolvePluginApiKey(pluginCfg?.apiKey) ||
|
||||
Boolean(pluginCfg?.apiKey) ||
|
||||
normalizeOptionalString(process.env.OPENAI_IMAGE_API_KEY) ||
|
||||
normalizeOptionalString(process.env.BIFROST_API_KEY) ||
|
||||
normalizeOptionalString(process.env.CCLOAD_API_KEY) ||
|
||||
normalizeOptionalString(process.env.BIFROST_API_KEY) ||
|
||||
normalizeOptionalString(process.env.OPENAI_API_KEY)) {
|
||||
return true;
|
||||
}
|
||||
@@ -122,8 +127,8 @@ export function buildOpenAIImageGenerationProvider({ isProviderApiKeyConfigured,
|
||||
const pluginCfg = resolveImageConfig(req.cfg, getPluginConfig?.());
|
||||
const explicitApiKey = resolvePluginApiKey(pluginCfg?.apiKey) ??
|
||||
normalizeOptionalString(process.env.OPENAI_IMAGE_API_KEY) ??
|
||||
normalizeOptionalString(process.env.BIFROST_API_KEY) ??
|
||||
normalizeOptionalString(process.env.CCLOAD_API_KEY) ??
|
||||
normalizeOptionalString(process.env.BIFROST_API_KEY) ??
|
||||
normalizeOptionalString(process.env.OPENAI_API_KEY);
|
||||
let apiKey = explicitApiKey;
|
||||
if (!apiKey) {
|
||||
|
||||
Vendored
+6
-1
@@ -10,7 +10,12 @@ const OPENAI_VIDEO_SECONDS = [4, 8, 12];
|
||||
const OPENAI_VIDEO_SIZES = ["720x1280", "1280x720", "1024x1792", "1792x1024"];
|
||||
export function resolvePluginApiKey(rawKey) {
|
||||
if (typeof rawKey === "string") {
|
||||
return normalizeOptionalString(rawKey);
|
||||
const trimmed = rawKey.trim();
|
||||
const envMatch = trimmed.match(/^\$\{([A-Za-z0-9_]+)\}$/);
|
||||
if (envMatch) {
|
||||
return normalizeOptionalString(process.env[envMatch[1]]);
|
||||
}
|
||||
return normalizeOptionalString(trimmed);
|
||||
}
|
||||
if (rawKey && typeof rawKey === "object" && typeof rawKey.id === "string") {
|
||||
return normalizeOptionalString(process.env[rawKey.id]);
|
||||
|
||||
+8
-3
@@ -52,7 +52,12 @@ export interface ImagePluginConfig {
|
||||
|
||||
export function resolvePluginApiKey(rawKey: string | SecretRefObject | undefined): string | undefined {
|
||||
if (typeof rawKey === "string") {
|
||||
return normalizeOptionalString(rawKey);
|
||||
const trimmed = rawKey.trim();
|
||||
const envMatch = trimmed.match(/^\$\{([A-Za-z0-9_]+)\}$/);
|
||||
if (envMatch) {
|
||||
return normalizeOptionalString(process.env[envMatch[1]]);
|
||||
}
|
||||
return normalizeOptionalString(trimmed);
|
||||
}
|
||||
if (rawKey && typeof rawKey === "object" && typeof rawKey.id === "string") {
|
||||
return normalizeOptionalString(process.env[rawKey.id]);
|
||||
@@ -133,8 +138,8 @@ export function buildOpenAIImageGenerationProvider({
|
||||
resolvePluginApiKey(pluginCfg?.apiKey) ||
|
||||
Boolean(pluginCfg?.apiKey) ||
|
||||
normalizeOptionalString(process.env.OPENAI_IMAGE_API_KEY) ||
|
||||
normalizeOptionalString(process.env.BIFROST_API_KEY) ||
|
||||
normalizeOptionalString(process.env.CCLOAD_API_KEY) ||
|
||||
normalizeOptionalString(process.env.BIFROST_API_KEY) ||
|
||||
normalizeOptionalString(process.env.OPENAI_API_KEY)
|
||||
) {
|
||||
return true;
|
||||
@@ -175,8 +180,8 @@ export function buildOpenAIImageGenerationProvider({
|
||||
const explicitApiKey =
|
||||
resolvePluginApiKey(pluginCfg?.apiKey) ??
|
||||
normalizeOptionalString(process.env.OPENAI_IMAGE_API_KEY) ??
|
||||
normalizeOptionalString(process.env.BIFROST_API_KEY) ??
|
||||
normalizeOptionalString(process.env.CCLOAD_API_KEY) ??
|
||||
normalizeOptionalString(process.env.BIFROST_API_KEY) ??
|
||||
normalizeOptionalString(process.env.OPENAI_API_KEY);
|
||||
|
||||
let apiKey = explicitApiKey;
|
||||
|
||||
+6
-1
@@ -63,7 +63,12 @@ export interface VideoPluginConfig {
|
||||
|
||||
export function resolvePluginApiKey(rawKey: string | SecretRefObject | undefined): string | undefined {
|
||||
if (typeof rawKey === "string") {
|
||||
return normalizeOptionalString(rawKey);
|
||||
const trimmed = rawKey.trim();
|
||||
const envMatch = trimmed.match(/^\$\{([A-Za-z0-9_]+)\}$/);
|
||||
if (envMatch) {
|
||||
return normalizeOptionalString(process.env[envMatch[1]]);
|
||||
}
|
||||
return normalizeOptionalString(trimmed);
|
||||
}
|
||||
if (rawKey && typeof rawKey === "object" && typeof rawKey.id === "string") {
|
||||
return normalizeOptionalString(process.env[rawKey.id]);
|
||||
|
||||
Reference in new issue
Block a user