31 lines
1.4 KiB
JavaScript
31 lines
1.4 KiB
JavaScript
// Copy deployment-only client config from the live web app into the bundled
|
|||
|
|
// cinny/config.json before a desktop build.
|
||
|
|
//
|
||
|
|
// The web deploy serves a config.json kept on the server (not in git), so
|
||
|
|
// values such as the Giphy key exist only there; the desktop app bundles the
|
||
|
|
// repo's config.json, where they are empty. Without this the GIF picker can be
|
||
|
|
// switched on in Settings and still never show a button on desktop.
|
||
|
|
//
|
||
|
|
// Only an allow-list of keys is copied, and a failure to fetch is a warning:
|
||
|
|
// the build still succeeds, just without those values.
|
||
|
|
import { readFileSync, writeFileSync } from 'node:fs';
|
||
|
|
|
||
|
|
const SOURCE = process.env.WEB_CONFIG_URL || 'https://chat.lotusguild.org/config.json';
|
||
|
|
const TARGET = 'cinny/config.json';
|
||
|
|
const KEYS = ['gifApiKey'];
|
||
|
|
|
||
|
|
try {
|
||
|
|
const res = await fetch(SOURCE, { signal: AbortSignal.timeout(15000) });
|
||
|
|
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
||
|
|
const web = await res.json();
|
||
|
|
const local = JSON.parse(readFileSync(TARGET, 'utf8'));
|
||
|
|
const copied = KEYS.filter((k) => typeof web[k] === 'string' && web[k] && local[k] !== web[k]);
|
||
|
|
copied.forEach((k) => {
|
||
|
|
local[k] = web[k];
|
||
|
|
});
|
||
|
|
writeFileSync(TARGET, `${JSON.stringify(local, null, 2)}\n`);
|
||
|
|
console.log(`sync-web-config: ${copied.length ? `set ${copied.join(', ')}` : 'nothing to change'}`);
|
||
|
|
} catch (e) {
|
||
|
|
console.warn(`sync-web-config: skipped (${e.message}); building with the repo config`);
|
||
|
|
}
|