Factorize duplicated configUrl code

Change-type: patch
This commit is contained in:
Alexis Svinartchouk 2020-04-29 17:52:45 +02:00
parent ffe281f25d
commit 44fc429f64
3 changed files with 7 additions and 9 deletions

View File

@ -55,10 +55,7 @@ async function initConfig() {
await installCorvus();
let validatedConfig = null;
try {
const configUrl =
(await settings.get('configUrl')) ||
'https://balena.io/etcher/static/config.json';
const config = await getConfig(configUrl);
const config = await getConfig();
const mixpanel = _.get(config, ['analytics', 'mixpanel'], {});
mixpanelSample = mixpanel.probability || DEFAULT_PROBABILITY;
if (isClientEligible(mixpanelSample)) {

View File

@ -114,10 +114,7 @@ async function createMainWindow() {
});
if (packageUpdatable) {
try {
const configUrl =
(await settings.get('configUrl')) ||
'https://balena.io/etcher/static/config.json';
const onlineConfig = await getConfig(configUrl);
const onlineConfig = await getConfig();
const autoUpdaterConfig = _.get(
onlineConfig,
['autoUpdates', 'autoUpdaterConfig'],

View File

@ -21,6 +21,7 @@ import * as tmp from 'tmp';
import { promisify } from 'util';
import * as errors from './errors';
import * as settings from '../gui/app/models/settings';
const getAsync = promisify(request.get);
@ -50,7 +51,10 @@ export function hasProps(obj: any, props: string[]): boolean {
* @summary Get etcher configs stored online
* @param {String} - url where config.json is stored
*/
export async function getConfig(configUrl: string): Promise<any> {
export async function getConfig(): Promise<_.Dictionary<any>> {
const configUrl =
(await settings.get('configUrl')) ||
'https://balena.io/etcher/static/config.json';
return (await getAsync({ url: configUrl, json: true })).body;
}