Serve up a config object containing appstoreOrigin
This also changes the webadmin to pickup the appstoreOrigin from the config object to avoid hardcoding
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
/* global angular:false */
|
||||
|
||||
angular.module('YellowTent')
|
||||
.service('AppStore', function ($http, Config) {
|
||||
.service('AppStore', function ($http, Client) {
|
||||
|
||||
function AppStoreError(statusCode, message) {
|
||||
Error.call(this);
|
||||
@@ -22,14 +22,16 @@ angular.module('YellowTent')
|
||||
|
||||
AppStore.prototype.getApps = function (callback) {
|
||||
if (this._appsCache !== null) return callback(null, this._appsCache);
|
||||
if (Client.getConfig() === null) return callback(new AppStoreError(500, 'Not yet initialized'));
|
||||
|
||||
var that = this;
|
||||
$http.get(Config.APPSTORE_URL + '/api/v1/apps')
|
||||
|
||||
$http.get(Client.getConfig().appstoreOrigin + '/api/v1/apps')
|
||||
.success(function (data, status, headers) {
|
||||
if (status !== 200) return callback(new AppStoreError(status, data));
|
||||
|
||||
var apps = data.apps;
|
||||
apps.forEach(function (app) { app.iconUrl = Config.APPSTORE_URL + "/api/v1/app/" + app.id + "/icon"; });
|
||||
apps.forEach(function (app) { app.iconUrl = Client.getConfig().appstoreOrigin + '/api/v1/app/' + app.id + '/icon'; });
|
||||
that._appsCache = apps;
|
||||
return callback(null, apps);
|
||||
}).error(function (data, status, headers) {
|
||||
|
||||
+23
-1
@@ -22,6 +22,7 @@ angular.module('YellowTent')
|
||||
this._token = null;
|
||||
this._clientId = null;
|
||||
this._clientSecret = null;
|
||||
this._config = null;
|
||||
|
||||
this.setToken(localStorage.token);
|
||||
}
|
||||
@@ -34,6 +35,10 @@ angular.module('YellowTent')
|
||||
return this._userInfo;
|
||||
};
|
||||
|
||||
Client.prototype.getConfig = function () {
|
||||
return this._config;
|
||||
};
|
||||
|
||||
Client.prototype.setToken = function (token) {
|
||||
console.debug('Set client token to ', token);
|
||||
$http.defaults.headers.common.Authorization = 'Token ' + token;
|
||||
@@ -53,6 +58,17 @@ angular.module('YellowTent')
|
||||
/*
|
||||
* Rest API wrappers
|
||||
*/
|
||||
Client.prototype.config = function (callback) {
|
||||
$http.get('/api/v1/config')
|
||||
.success(function(data, status, headers, config) {
|
||||
if (status !== 200) return callback(new ClientError(status, data));
|
||||
callback(null, data);
|
||||
})
|
||||
.error(function(data, status, headers, config) {
|
||||
callback(new ClientError(status, data));
|
||||
});
|
||||
};
|
||||
|
||||
Client.prototype.createVolume = function (name, password, callback) {
|
||||
var data = { password: password, name: name };
|
||||
$http.post('/api/v1/volume/create', data)
|
||||
@@ -271,7 +287,13 @@ angular.module('YellowTent')
|
||||
that._userInfo = data.userInfo;
|
||||
that.setToken(data.token);
|
||||
|
||||
callback(null, data.token);
|
||||
that.config(function (error, result) {
|
||||
if (error) callback(error);
|
||||
|
||||
that._config = result;
|
||||
|
||||
callback(null, data.token);
|
||||
});
|
||||
})
|
||||
.error(function(data, status, headers, config) {
|
||||
that.setToken(null);
|
||||
|
||||
@@ -63,7 +63,3 @@ app.run(function (acuteSelectService) {
|
||||
acuteSelectService.updateSetting('templatePath', '/3rdparty/templates');
|
||||
});
|
||||
|
||||
app.service('Config', function () {
|
||||
this.APPSTORE_URL = 'https://selfhost.io:5050';
|
||||
});
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
var MyAppsController = function ($scope, $http, $location, Config) {
|
||||
var MyAppsController = function ($scope, $http, $location, Client) {
|
||||
$scope.LOADING = 1;
|
||||
$scope.ERROR = 2;
|
||||
$scope.LOADED = 3;
|
||||
@@ -14,7 +14,7 @@ var MyAppsController = function ($scope, $http, $location, Config) {
|
||||
$http.get('/api/v1/apps')
|
||||
.success(function (data, status, headers) {
|
||||
data.apps.forEach(function (app) {
|
||||
app.iconUrl = Config.APPSTORE_URL + "/api/v1/app/" + app.id + "/icon";
|
||||
app.iconUrl = Client.getConfig().appstoreOrigin + '/api/v1/app/' + app.id + '/icon';
|
||||
app.url = 'https://' + app.location + '.' + window.location.hostname;
|
||||
});
|
||||
$scope.apps = data.apps;
|
||||
|
||||
Reference in New Issue
Block a user