|
|
|
@ -1,11 +1,8 @@
|
|
|
|
|
'use strict';
|
|
|
|
|
const React = require('react');
|
|
|
|
|
const ReactDOM = require('react-dom');
|
|
|
|
|
const create = require('create-react-class');
|
|
|
|
|
const Promise = require('bluebird');
|
|
|
|
|
const urllib = require('url');
|
|
|
|
|
const debounce = require('debounce');
|
|
|
|
|
const defaultValue = require('default-value');
|
|
|
|
|
|
|
|
|
|
let login = create({
|
|
|
|
|
displayName: "Login",
|
|
|
|
@ -156,6 +153,7 @@ let login = create({
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
function getApiServer(hostname) {
|
|
|
|
|
/* FIXME: Promise.try */
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
console.log("Checking for api server from mxid", urllib.format(hostname));
|
|
|
|
|
checkApi(hostname).then(() => {
|
|
|
|
@ -167,8 +165,9 @@ function getApiServer(hostname) {
|
|
|
|
|
tryWellKnown(hostname).then((hostname) => {
|
|
|
|
|
console.log("got .well-known host", hostname);
|
|
|
|
|
resolve(hostname);
|
|
|
|
|
}).catch((err) => {
|
|
|
|
|
reject("Fatal error trying to get API host");
|
|
|
|
|
}).catch((_err) => {
|
|
|
|
|
/* FIXME: Error chaining */
|
|
|
|
|
reject(new Error("Fatal error trying to get API host"));
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
@ -180,7 +179,8 @@ function checkApi(host) {
|
|
|
|
|
fetch(versionUrl).then((response) => {
|
|
|
|
|
if (response.status != 200) {
|
|
|
|
|
console.log("Invalid homeserver url", versionUrl);
|
|
|
|
|
return reject();
|
|
|
|
|
/* FIXME: Error types */
|
|
|
|
|
return reject(new Error("Invalid homeserver URL"));
|
|
|
|
|
}
|
|
|
|
|
resolve();
|
|
|
|
|
}).catch((err) => {
|
|
|
|
@ -199,11 +199,12 @@ function tryWellKnown(host) {
|
|
|
|
|
.then((response) => {
|
|
|
|
|
if (response.status != 200) {
|
|
|
|
|
console.log("no well-known in use");
|
|
|
|
|
reject("No homeserver found");
|
|
|
|
|
reject(new Error("No homeserver found"));
|
|
|
|
|
}
|
|
|
|
|
return response;
|
|
|
|
|
}).catch((error) => {
|
|
|
|
|
reject("can't fetch .well-known");
|
|
|
|
|
}).catch((_error) => {
|
|
|
|
|
/* FIXME: Error chaining */
|
|
|
|
|
reject(new Error("can't fetch .well-known"));
|
|
|
|
|
})
|
|
|
|
|
.then((response) => response.json())
|
|
|
|
|
.then((json) => {
|
|
|
|
@ -214,7 +215,8 @@ function tryWellKnown(host) {
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
console.log("Error in json", err);
|
|
|
|
|
reject("Error while parsing .well-known");
|
|
|
|
|
/* FIXME: Error chaining */
|
|
|
|
|
reject(new Error("Error while parsing .well-known"));
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|