appstore and support: async'ify
This commit is contained in:
+33
-80
@@ -384,7 +384,7 @@ function setDynamicDnsConfig(enabled, callback) {
|
||||
|
||||
async function getUnstableAppsConfig() {
|
||||
const result = await get(exports.UNSTABLE_APPS_KEY);
|
||||
if (result === null) gDefaults[exports.UNSTABLE_APPS_KEY];
|
||||
if (result === null) return gDefaults[exports.UNSTABLE_APPS_KEY];
|
||||
return !!result; // db holds string values only
|
||||
}
|
||||
|
||||
@@ -650,28 +650,18 @@ async function setDirectoryConfig(directoryConfig) {
|
||||
notifyChange(exports.DIRECTORY_CONFIG_KEY, directoryConfig);
|
||||
}
|
||||
|
||||
function getAppstoreListingConfig(callback) {
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
async function getAppstoreListingConfig() {
|
||||
const value = await get(exports.APPSTORE_LISTING_CONFIG_KEY);
|
||||
if (value === null) return gDefaults[exports.APPSTORE_LISTING_CONFIG_KEY];
|
||||
|
||||
settingsdb.get(exports.APPSTORE_LISTING_CONFIG_KEY, function (error, value) {
|
||||
if (error && error.reason === BoxError.NOT_FOUND) return callback(null, gDefaults[exports.APPSTORE_LISTING_CONFIG_KEY]);
|
||||
if (error) return callback(error);
|
||||
|
||||
callback(null, JSON.parse(value));
|
||||
});
|
||||
return JSON.parse(value);
|
||||
}
|
||||
|
||||
function setAppstoreListingConfig(listingConfig, callback) {
|
||||
async function setAppstoreListingConfig(listingConfig) {
|
||||
assert.strictEqual(typeof listingConfig, 'object');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
settingsdb.set(exports.APPSTORE_LISTING_CONFIG_KEY, JSON.stringify(listingConfig), function (error) {
|
||||
if (error) return callback(error);
|
||||
|
||||
notifyChange(exports.APPSTORE_LISTING_CONFIG_KEY, listingConfig);
|
||||
|
||||
callback(null);
|
||||
});
|
||||
await set(exports.APPSTORE_LISTING_CONFIG_KEY, JSON.stringify(listingConfig));
|
||||
notifyChange(exports.APPSTORE_LISTING_CONFIG_KEY, listingConfig);
|
||||
}
|
||||
|
||||
async function getFirewallBlocklist() {
|
||||
@@ -688,39 +678,24 @@ async function setFirewallBlocklist(blocklist) {
|
||||
await setBlob(exports.FIREWALL_BLOCKLIST_KEY, Buffer.from(blocklist));
|
||||
}
|
||||
|
||||
function getSupportConfig(callback) {
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
async function getSupportConfig() {
|
||||
const value = await get(exports.SUPPORT_CONFIG_KEY);
|
||||
if (value === null) return gDefaults[exports.SUPPORT_CONFIG_KEY];
|
||||
|
||||
settingsdb.get(exports.SUPPORT_CONFIG_KEY, function (error, value) {
|
||||
if (error && error.reason === BoxError.NOT_FOUND) return callback(null, gDefaults[exports.SUPPORT_CONFIG_KEY]);
|
||||
if (error) return callback(error);
|
||||
|
||||
callback(null, JSON.parse(value));
|
||||
});
|
||||
return JSON.parse(value);
|
||||
}
|
||||
|
||||
function getLicenseKey(callback) {
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
settingsdb.get(exports.LICENSE_KEY, function (error, value) {
|
||||
if (error && error.reason === BoxError.NOT_FOUND) return callback(null, gDefaults[exports.LICENSE_KEY]);
|
||||
if (error) return callback(error);
|
||||
|
||||
callback(null, value);
|
||||
});
|
||||
async function getLicenseKey() {
|
||||
const value = get(exports.LICENSE_KEY);
|
||||
if (value === null) return gDefaults[exports.LICENSE_KEY];
|
||||
return value;
|
||||
}
|
||||
|
||||
function setLicenseKey(licenseKey, callback) {
|
||||
async function setLicenseKey(licenseKey) {
|
||||
assert.strictEqual(typeof licenseKey, 'string');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
settingsdb.set(exports.LICENSE_KEY, licenseKey, function (error) {
|
||||
if (error) return callback(error);
|
||||
|
||||
notifyChange(exports.LICENSE_KEY, licenseKey);
|
||||
|
||||
callback(null);
|
||||
});
|
||||
await set(exports.LICENSE_KEY, licenseKey);
|
||||
notifyChange(exports.LICENSE_KEY, licenseKey);
|
||||
}
|
||||
|
||||
function getLanguage(callback) {
|
||||
@@ -753,52 +728,30 @@ function setLanguage(language, callback) {
|
||||
});
|
||||
}
|
||||
|
||||
function getCloudronId(callback) {
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
settingsdb.get(exports.CLOUDRON_ID_KEY, function (error, value) {
|
||||
if (error && error.reason === BoxError.NOT_FOUND) return callback(null, gDefaults[exports.CLOUDRON_ID_KEY]);
|
||||
if (error) return callback(error);
|
||||
|
||||
callback(null, value);
|
||||
});
|
||||
async function getCloudronId() {
|
||||
const value = await get(exports.CLOUDRON_ID_KEY);
|
||||
if (value === null) return gDefaults[exports.CLOUDRON_ID_KEY];
|
||||
return value;
|
||||
}
|
||||
|
||||
function setCloudronId(cid, callback) {
|
||||
async function setCloudronId(cid) {
|
||||
assert.strictEqual(typeof cid, 'string');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
settingsdb.set(exports.CLOUDRON_ID_KEY, cid, function (error) {
|
||||
if (error) return callback(error);
|
||||
|
||||
notifyChange(exports.CLOUDRON_ID_KEY, cid);
|
||||
|
||||
callback(null);
|
||||
});
|
||||
await set(exports.CLOUDRON_ID_KEY, cid);
|
||||
notifyChange(exports.CLOUDRON_ID_KEY, cid);
|
||||
}
|
||||
|
||||
function getCloudronToken(callback) {
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
settingsdb.get(exports.CLOUDRON_TOKEN_KEY, function (error, value) {
|
||||
if (error && error.reason === BoxError.NOT_FOUND) return callback(null, gDefaults[exports.CLOUDRON_TOKEN_KEY]);
|
||||
if (error) return callback(error);
|
||||
|
||||
callback(null, value);
|
||||
});
|
||||
async function getCloudronToken() {
|
||||
const value = await get(exports.CLOUDRON_TOKEN_KEY);
|
||||
if (value === null) return gDefaults[exports.CLOUDRON_TOKEN_KEY];
|
||||
return value;
|
||||
}
|
||||
|
||||
function setCloudronToken(token, callback) {
|
||||
async function setCloudronToken(token) {
|
||||
assert.strictEqual(typeof token, 'string');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
settingsdb.set(exports.CLOUDRON_TOKEN_KEY, token, function (error) {
|
||||
if (error) return callback(error);
|
||||
|
||||
notifyChange(exports.CLOUDRON_TOKEN_KEY, token);
|
||||
|
||||
callback(null);
|
||||
});
|
||||
await set(exports.CLOUDRON_TOKEN_KEY, token);
|
||||
notifyChange(exports.CLOUDRON_TOKEN_KEY, token);
|
||||
}
|
||||
|
||||
async function list() {
|
||||
|
||||
Reference in New Issue
Block a user