chore: sync submodule state (parent ref update)
Made-with: Cursor
This commit is contained in:
46
index.js
46
index.js
@@ -9,29 +9,43 @@ import crypto from 'crypto';
|
|||||||
import { readFileSync } from 'fs';
|
import { readFileSync } from 'fs';
|
||||||
import { join, dirname } from 'path';
|
import { join, dirname } from 'path';
|
||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
|
import { homedir } from 'os';
|
||||||
|
|
||||||
// Load environment variables from .env file
|
// Load environment variables from ~/.env file (standardized location)
|
||||||
|
const envPath = join(homedir(), '.env');
|
||||||
|
|
||||||
|
// Also try relative path as fallback for backwards compatibility
|
||||||
const __filename = fileURLToPath(import.meta.url);
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
const __dirname = dirname(__filename);
|
const __dirname = dirname(__filename);
|
||||||
const envPath = join(__dirname, '../.env');
|
const envPathFallback = join(__dirname, '../.env');
|
||||||
|
|
||||||
try {
|
function loadEnvFile(filePath) {
|
||||||
const envFile = readFileSync(envPath, 'utf8');
|
try {
|
||||||
const envVars = envFile.split('\n').filter(line => line.includes('=') && !line.trim().startsWith('#'));
|
const envFile = readFileSync(filePath, 'utf8');
|
||||||
for (const line of envVars) {
|
const envVars = envFile.split('\n').filter(line => line.includes('=') && !line.trim().startsWith('#'));
|
||||||
const [key, ...values] = line.split('=');
|
for (const line of envVars) {
|
||||||
// Validate key is a valid environment variable name (alphanumeric and underscore only)
|
const [key, ...values] = line.split('=');
|
||||||
if (key && values.length > 0 && /^[A-Z_][A-Z0-9_]*$/.test(key.trim())) {
|
// Validate key is a valid environment variable name (alphanumeric and underscore only)
|
||||||
// Remove surrounding quotes if present and trim
|
if (key && values.length > 0 && /^[A-Z_][A-Z0-9_]*$/.test(key.trim())) {
|
||||||
let value = values.join('=').trim();
|
// Remove surrounding quotes if present and trim
|
||||||
if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
|
let value = values.join('=').trim();
|
||||||
value = value.slice(1, -1);
|
if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
|
||||||
|
value = value.slice(1, -1);
|
||||||
|
}
|
||||||
|
process.env[key.trim()] = value;
|
||||||
}
|
}
|
||||||
process.env[key.trim()] = value;
|
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
|
} catch (error) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try ~/.env first, then fallback to relative path
|
||||||
|
if (!loadEnvFile(envPath)) {
|
||||||
|
if (!loadEnvFile(envPathFallback)) {
|
||||||
|
console.error('Warning: Could not load .env file from ~/.env or ../.env');
|
||||||
}
|
}
|
||||||
} catch (error) {
|
|
||||||
console.error('Warning: Could not load .env file:', error.message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class ProxmoxServer {
|
class ProxmoxServer {
|
||||||
|
|||||||
Reference in New Issue
Block a user