import * as fs from 'fs/promises'; import path from 'path'; export class Keys { private keys: Record = {}; async load(): Promise { const file = path.join(__dirname, '..', 'keys.json'); let content = '{}'; try { content = await fs.readFile(file, { encoding: 'utf-8' }); } catch (e) { if (e.message.includes('ENOENT')) { fs.writeFile(file, '{}'); } else { throw e; } } this.keys = JSON.parse(content); } getDomain(key: string): string | undefined { return this.keys[key]; } getKey(domain: string): string | undefined { return Object.keys(this.keys).find((key) => this.keys[key] === domain); } }