feat: prefer workspace key path for google maps

This commit is contained in:
Stefano Fiorini
2026-03-10 00:35:25 -05:00
parent 7361b31c7c
commit d3a2b9faae
4 changed files with 142 additions and 7 deletions

View File

@@ -2,7 +2,11 @@
const fs = require('fs');
const path = require('path');
const DEFAULT_KEY_PATH = path.join(process.env.HOME || '', '.openclaw/credentials/google-maps/apikey.txt');
const DEFAULT_KEY_PATH = path.join(process.env.HOME || '', '.openclaw/workspace/.clawdbot/credentials/google-maps/apikey.txt');
const FALLBACK_KEY_PATHS = [
DEFAULT_KEY_PATH,
path.join(process.env.HOME || '', '.openclaw/credentials/google-maps/apikey.txt'),
];
function parseArgs(argv) {
const out = { _: [] };
@@ -44,11 +48,14 @@ function must(opts, keys) {
function readApiKey(opts) {
if (process.env.GOOGLE_MAPS_API_KEY) return process.env.GOOGLE_MAPS_API_KEY.trim();
const p = opts.keyPath || DEFAULT_KEY_PATH;
if (!fs.existsSync(p)) throw new Error(`API key file not found: ${p}`);
const key = fs.readFileSync(p, 'utf8').trim();
if (!key) throw new Error(`API key file is empty: ${p}`);
return key;
const candidates = opts.keyPath ? [opts.keyPath] : FALLBACK_KEY_PATHS;
for (const p of candidates) {
if (!fs.existsSync(p)) continue;
const key = fs.readFileSync(p, 'utf8').trim();
if (!key) throw new Error(`API key file is empty: ${p}`);
return key;
}
throw new Error(`API key file not found. Checked: ${candidates.join(', ')}`);
}
async function geocode(address, key) {