Files
openchamber/packages/web/server/lib/quota/utils/auth.js
T
Nelson Pires 243abe9d16 refactor(quota): modularize quota providers and add docs map (#427)
* refactor(quota): migrate server quota providers to modular registry architecture

* docs: add quota module documentation

Explain the quota module purpose and runtime signals.
List entrypoints, provider registry, and response shape.
Outline steps to add a new provider and testing commands.
2026-02-15 16:19:10 +02:00

47 lines
1.1 KiB
JavaScript

import fs from 'fs';
import path from 'path';
import os from 'os';
const OPENCODE_CONFIG_DIR = path.join(os.homedir(), '.config', 'opencode');
const OPENCODE_DATA_DIR = path.join(os.homedir(), '.local', 'share', 'opencode');
export const ANTIGRAVITY_ACCOUNTS_PATHS = [
path.join(OPENCODE_CONFIG_DIR, 'antigravity-accounts.json'),
path.join(OPENCODE_DATA_DIR, 'antigravity-accounts.json')
];
export const readJsonFile = (filePath) => {
if (!fs.existsSync(filePath)) {
return null;
}
try {
const raw = fs.readFileSync(filePath, 'utf8');
const trimmed = raw.trim();
if (!trimmed) return null;
return JSON.parse(trimmed);
} catch (error) {
console.warn(`Failed to read JSON file: ${filePath}`, error);
return null;
}
};
export const getAuthEntry = (auth, aliases) => {
for (const alias of aliases) {
if (auth[alias]) {
return auth[alias];
}
}
return null;
};
export const normalizeAuthEntry = (entry) => {
if (!entry) return null;
if (typeof entry === 'string') {
return { token: entry };
}
if (typeof entry === 'object') {
return entry;
}
return null;
};