reorder functions for no-use-before-define
This commit is contained in:
+33
-35
@@ -23,10 +23,6 @@ import volumes from './volumes.js';
|
||||
|
||||
const debug = debugModule('box:appstore');
|
||||
|
||||
const _setApiServerOrigin = setApiServerOrigin;
|
||||
const _unregister = unregister;
|
||||
|
||||
|
||||
// These are the default options and will be adjusted once a subscription state is obtained
|
||||
// Keep in sync with appstore/routes/cloudrons.js
|
||||
const DEFAULT_FEATURES = {
|
||||
@@ -241,6 +237,31 @@ async function getAppUpdate(app, options) {
|
||||
return updateInfo;
|
||||
}
|
||||
|
||||
async function updateCloudron(data) {
|
||||
assert.strictEqual(typeof data, 'object');
|
||||
|
||||
const { domain, version } = data;
|
||||
|
||||
const token = await settings.get(settings.APPSTORE_API_TOKEN_KEY);
|
||||
if (!token) throw new BoxError(BoxError.LICENSE_ERROR, 'Missing token');
|
||||
|
||||
const query = {
|
||||
accessToken: token
|
||||
};
|
||||
|
||||
const [error, response] = await safe(superagent.post(`${await getApiServerOrigin()}/api/v1/update_cloudron`)
|
||||
.query(query)
|
||||
.send({ domain, version })
|
||||
.timeout(60 * 1000)
|
||||
.ok(() => true));
|
||||
|
||||
if (error) throw new BoxError(BoxError.NETWORK_ERROR, error);
|
||||
if (response.status === 401) throw new BoxError(BoxError.LICENSE_ERROR, 'Invalid appstore token');
|
||||
if (response.status !== 200) throw new BoxError(BoxError.EXTERNAL_ERROR, `Bad response: ${response.status} ${response.text}`);
|
||||
|
||||
debug(`updateCloudron: Cloudron updated with data ${JSON.stringify(data)}`);
|
||||
}
|
||||
|
||||
async function registerCloudron3() {
|
||||
const { domain } = await dashboard.getLocation();
|
||||
const version = constants.VERSION;
|
||||
@@ -271,6 +292,11 @@ async function registerCloudron3() {
|
||||
await getSubscription();
|
||||
}
|
||||
|
||||
async function unregister() {
|
||||
await settings.set(settings.CLOUDRON_ID_KEY, '');
|
||||
await settings.set(settings.APPSTORE_API_TOKEN_KEY, '');
|
||||
}
|
||||
|
||||
async function unlinkAccount() {
|
||||
debug('unlinkAccount: Unlinking existing account.');
|
||||
|
||||
@@ -280,36 +306,6 @@ async function unlinkAccount() {
|
||||
return await registerCloudron3();
|
||||
}
|
||||
|
||||
async function updateCloudron(data) {
|
||||
assert.strictEqual(typeof data, 'object');
|
||||
|
||||
const { domain, version } = data;
|
||||
|
||||
const token = await settings.get(settings.APPSTORE_API_TOKEN_KEY);
|
||||
if (!token) throw new BoxError(BoxError.LICENSE_ERROR, 'Missing token');
|
||||
|
||||
const query = {
|
||||
accessToken: token
|
||||
};
|
||||
|
||||
const [error, response] = await safe(superagent.post(`${await getApiServerOrigin()}/api/v1/update_cloudron`)
|
||||
.query(query)
|
||||
.send({ domain, version })
|
||||
.timeout(60 * 1000)
|
||||
.ok(() => true));
|
||||
|
||||
if (error) throw new BoxError(BoxError.NETWORK_ERROR, error);
|
||||
if (response.status === 401) throw new BoxError(BoxError.LICENSE_ERROR, 'Invalid appstore token');
|
||||
if (response.status !== 200) throw new BoxError(BoxError.EXTERNAL_ERROR, `Bad response: ${response.status} ${response.text}`);
|
||||
|
||||
debug(`updateCloudron: Cloudron updated with data ${JSON.stringify(data)}`);
|
||||
}
|
||||
|
||||
async function unregister() {
|
||||
await settings.set(settings.CLOUDRON_ID_KEY, '');
|
||||
await settings.set(settings.APPSTORE_API_TOKEN_KEY, '');
|
||||
}
|
||||
|
||||
async function downloadManifest(appStoreId, manifest) {
|
||||
if (!appStoreId && !manifest) throw new BoxError(BoxError.BAD_FIELD, 'Neither manifest nor appStoreId provided');
|
||||
|
||||
@@ -398,6 +394,8 @@ async function downloadIcon(appStoreId, version) {
|
||||
});
|
||||
}
|
||||
|
||||
const _setApiServerOrigin = setApiServerOrigin;
|
||||
|
||||
export default {
|
||||
getFeatures,
|
||||
getApiServerOrigin,
|
||||
@@ -417,5 +415,5 @@ export default {
|
||||
getAppUpdate,
|
||||
getBoxUpdate,
|
||||
_setApiServerOrigin,
|
||||
_unregister,
|
||||
_unregister: unregister,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user