centralized cloud endpoint config

This commit is contained in:
Michal Moskal 2015-04-21 17:03:13 -07:00
Родитель 71d864080c
Коммит cddc7c9c51
5 изменённых файлов: 53 добавлений и 10 удалений

Просмотреть файл

@ -1,6 +1,25 @@
///<reference path='refs.ts'/>
module TDev
{
function fetchConfigAsync()
{
if (Cloud.lite && !Cloud.config.liteVersion) {
var storeCfg = r => Object.keys(r).forEach(k => Cloud.config[k] = r[k]);
var p = Cloud.getPublicApiAsync("clientconfig")
.then(r => {
localStorage['clientconfig'] = JSON.stringify(r)
storeCfg(r)
})
if (localStorage['clientconfig']) {
storeCfg(JSON.parse(localStorage['clientconfig']))
p.done()
return Promise.as()
} else return p;
}
else return Promise.as()
}
function initEditorAsync()
{
SizeMgr.earlyInit();
@ -21,6 +40,7 @@ module TDev
return Promise.as()
.then(() => LocalProxy.updateShellAsync())
.then(() => LocalProxy.loadCachesAsync())
.then(() => fetchConfigAsync())
.then(() => Browser.TheApiCacheMgr.initAsync())
.then(() => {
initScreens();
@ -459,7 +479,7 @@ module TDev
if (mx && mx[1] != "0") {
Cloud.lite = true;
(<any>window).rootUrl = mx[1].length > 2 ? "http://" + mx[1] + ".cloudapp.net" : "https://mbitmain.azurewebsites.net"
Cloud.config.rootUrl = mx[1].length > 2 ? "http://" + mx[1] + ".cloudapp.net" : "https://mbitmain.azurewebsites.net"
TDev.Ticker.disable()
}
@ -467,13 +487,18 @@ module TDev
Cloud.lite = true;
if ((<any>window).tdlite == "url") {
mx = /^(https?:\/\/[^\/]+)/.exec(document.URL);
(<any>window).rootUrl = mx[1]
Cloud.config.rootUrl = mx[1]
} else {
(<any>window).rootUrl = (<any>window).tdlite;
Cloud.config.rootUrl = (<any>window).tdlite;
}
TDev.Ticker.disable()
var cfg = (<any>window).tdConfig
if (cfg) Object.keys(cfg).forEach(k => Cloud.config[k] = cfg[k])
}
if (Cloud.lite) (<any>window).rootUrl = Cloud.config.rootUrl;
if (/httplog=1/.test(document.URL)) {
HttpLog.enabled = true;
}

Просмотреть файл

@ -78,8 +78,8 @@ module TDev.Meta {
if (!terms) return Promise.as([]);
var indexName = "art1";
var apiKey = "E43690E2B2A39FEB68117546BF778DB8"; // touchdevelop web app query key in portal
var serviceUrl = "https://tdsearch.search.windows.net";
var apiKey = Cloud.config.searchApiKey;
var serviceUrl = Cloud.config.searchUrl;
var query = terms.split(' ').map(term => /sound|picture/i.test(term) ? undefined : term + "*").filter(s => !!s).join("+");
var filter = type ? "type eq '" + type + "'" : /sound/i.test(terms) ? "type eq 'sound'" : /picture/i.test(terms) ? "type eq 'picture'" : undefined;
var scoringProfile = "editorpics";

Просмотреть файл

@ -3,6 +3,26 @@ module TDev.Cloud {
export var lite = false;
export var litePermissions:string = null;
export interface ClientConfig {
workspaceUrl: string;
searchUrl: string;
searchApiKey: string;
rootUrl: string;
liteVersion: string;
tdVersion?: string;
releaseid?: string;
releaseLabel?: string;
}
export var config: ClientConfig = {
searchApiKey: "E43690E2B2A39FEB68117546BF778DB8", // touchdevelop web app query key in portal
searchUrl: "https://tdsearch.search.windows.net",
workspaceUrl: null,
rootUrl: "https://www.touchdevelop.com",
liteVersion: null,
}
export function hasPermission(perm:string)
{
@ -15,7 +35,7 @@ module TDev.Cloud {
return !!lite;
}
export function getServiceUrl() { return <string>((<any>window).rootUrl); }
export function getServiceUrl() { return config.rootUrl; }
export function mkLegalDiv() {
var link = (text: string, lnk: string) =>

Просмотреть файл

@ -731,7 +731,7 @@ module TDev {
timestamp: Util.now(),
platform: [],
attachments: [],
tdVersion: (<any>window).tdVersion || "",
tdVersion: Cloud.config.tdVersion || "",
}
if (fillEditorInfoBugReport)

Просмотреть файл

@ -17,7 +17,6 @@ module TDev {
var getIndexTablePromise = () => Storage.getTableAsync("Index");
var getScriptsTablePromise = () => Storage.getTableAsync("Scripts");
var getTracesTablePromise = () => Storage.getTableAsync("Traces");
var blobcontainer = ""
interface SyncData {
indexTable: Storage.Table;
@ -130,7 +129,7 @@ module TDev {
export function getScriptBlobAsync(snapshotId:string)
{
return Util.httpGetJsonAsync(blobcontainer + snapshotId)
return Util.httpGetJsonAsync(Cloud.config.workspaceUrl + snapshotId)
}
// [header] is coming from the cloud; we need to update our local
@ -483,7 +482,6 @@ module TDev {
_askToEnableEmailNotifications = !data.installedHeaders.emailNotifications;
_profileIndex = data.installedHeaders.profileIndex || 0;
_profileCount = data.installedHeaders.profileCount || 0;
blobcontainer = data.installedHeaders.blobcontainer
Random.addCloudEntropy(data.installedHeaders.random)
if (!Cloud.lite && data.installedHeaders.time) {
var now = new Date().getTime();