'use server'; /** * Server-side API validation utilities. * These functions check which API keys are present and valid. */ import { type ImageProvider, PROVIDER_CONFIGS } from './api-config'; /** * Check if a specific provider's API key is present and non-empty. */ export async function isProviderAvailable(provider: ImageProvider): Promise { const config = PROVIDER_CONFIGS[provider]; const apiKey = process.env[config.envKey]; // Check if the API key exists and is not a placeholder if (!apiKey || apiKey.trim() === '') { return false; } // Check if it's a placeholder value (common patterns) const placeholderPatterns = [ 'your-', 'YOUR_', 'xxx', 'placeholder', 'insert-', 'api-key-here', ]; const lowerKey = apiKey.toLowerCase(); for (const pattern of placeholderPatterns) { if (lowerKey.includes(pattern.toLowerCase())) { return false; } } return true; } /** * Get all available providers that have valid API keys configured. */ export async function getAvailableProviders(): Promise { const providers: ImageProvider[] = ['openai', 'google', 'qwen']; const availableProviders: ImageProvider[] = []; for (const provider of providers) { if (await isProviderAvailable(provider)) { availableProviders.push(provider); } } return availableProviders; } /** * Get detailed information about provider availability. */ export async function getProviderStatus(): Promise> { return { openai: await isProviderAvailable('openai'), google: await isProviderAvailable('google'), qwen: await isProviderAvailable('qwen'), }; }