Support unstable app listing setting in appstore view

This commit is contained in:
Johannes Zellner
2019-04-29 14:58:42 +02:00
parent 0226a5603d
commit 01f59d39e0
2 changed files with 32 additions and 71 deletions

View File

@@ -19,12 +19,12 @@ angular.module('Application').service('AppStore', ['$http', '$base64', 'Client',
this._appsCache = [];
}
AppStore.prototype.getApps = function (callback) {
AppStore.prototype.getApps = function (unstable, callback) {
if (Client.getConfig().apiServerOrigin === null) return callback(new AppStoreError(420, 'Enhance Your Calm'));
var that = this;
$http.get(Client.getConfig().apiServerOrigin + '/api/v1/apps', { params: { boxVersion: Client.getConfig().version, unstable: true } }).success(function (data, status) {
$http.get(Client.getConfig().apiServerOrigin + '/api/v1/apps', { params: { boxVersion: Client.getConfig().version, unstable: unstable } }).success(function (data, status) {
if (status !== 200) return callback(new AppStoreError(status, data));
angular.copy(data.apps, that._appsCache);
@@ -35,56 +35,21 @@ angular.module('Application').service('AppStore', ['$http', '$base64', 'Client',
});
};
AppStore.prototype.getAppsFast = function (callback) {
AppStore.prototype.getAppsFast = function (unstable, callback) {
if (Client.getConfig().apiServerOrigin === null) return callback(new AppStoreError(420, 'Enhance Your Calm'));
if (this._appsCache.length !== 0) return callback(null, this._appsCache);
this.getApps(callback);
};
AppStore.prototype.getAppById = function (appId, callback) {
var that = this;
// check cache
for (var app in this._appsCache) {
if (this._appsCache[app].id === appId) return callback(null, this._appsCache[app]);
}
this.getApps(function (error) {
if (error) return callback(error);
// recheck cache
for (var app in that._appsCache) {
if (that._appsCache[app].id === appId) return callback(null, that._appsCache[app]);
}
callback(new AppStoreError(404, 'Not found'));
});
this.getApps(unstable, callback);
};
AppStore.prototype.getAppByIdAndVersion = function (appId, version, callback) {
if (Client.getConfig().apiServerOrigin === null) return callback(new AppStoreError(420, 'Enhance Your Calm'));
// check cache
for (var app in this._appsCache) {
if (this._appsCache[app].id === appId && this._appsCache[app].manifest.version === version) return callback(null, this._appsCache[app]);
}
var url = Client.getConfig().apiServerOrigin + '/api/v1/apps/' + appId;
if (version && version !== 'latest') url += '/versions/' + version;
$http.get(Client.getConfig().apiServerOrigin + '/api/v1/apps/' + appId + '/versions/' + version).success(function (data, status) {
if (status !== 200) return callback(new AppStoreError(status, data));
return callback(null, data);
}).error(function (data, status) {
return callback(new AppStoreError(status, data));
});
};
AppStore.prototype.getAppById = function (appId, callback) {
if (Client.getConfig().apiServerOrigin === null) return callback(new AppStoreError(420, 'Enhance Your Calm'));
// do not check cache, always get the latest
$http.get(Client.getConfig().apiServerOrigin + '/api/v1/apps/' + appId).success(function (data, status) {
$http.get(url).success(function (data, status) {
if (status !== 200) return callback(new AppStoreError(status, data));
return callback(null, data);
}).error(function (data, status) {