mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-07-21 15:35:18 +02:00
24 lines
603 B
JavaScript
24 lines
603 B
JavaScript
import { readFileSync } from 'fs';
|
|
|
|
let keys = {};
|
|
try {
|
|
const data = readFileSync('./keys.json', 'utf8');
|
|
keys = JSON.parse(data);
|
|
} catch (err) {
|
|
console.warn('keys.json not found. Defaulting to environment variables.'); // still works with local models
|
|
}
|
|
|
|
export function getKey(name) {
|
|
let key = keys[name];
|
|
if (!key) {
|
|
key = process.env[name];
|
|
}
|
|
if (!key) {
|
|
throw new Error(`API key "${name}" not found in keys.json or environment variables!`);
|
|
}
|
|
return keys[name];
|
|
}
|
|
|
|
export function hasKey(name) {
|
|
return keys[name] || process.env[name];
|
|
}
|