Try to find out the Matrix homeserver version and include in rageshakes (#11212)
parent
689089d9e6
commit
42d8e4f1a8
|
@ -15,6 +15,7 @@ limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React, { useContext } from "react";
|
import React, { useContext } from "react";
|
||||||
|
import { MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||||
|
|
||||||
import BaseTool, { IDevtoolsProps } from "./BaseTool";
|
import BaseTool, { IDevtoolsProps } from "./BaseTool";
|
||||||
import { _t } from "../../../../languageHandler";
|
import { _t } from "../../../../languageHandler";
|
||||||
|
@ -33,28 +34,32 @@ interface IServerWellKnown {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getServerVersionFromFederationApi(client: MatrixClient): Promise<IServerWellKnown> {
|
||||||
|
let baseUrl = client.getHomeserverUrl();
|
||||||
|
|
||||||
|
try {
|
||||||
|
const hsName = MatrixClientPeg.getHomeserverName();
|
||||||
|
// We don't use the js-sdk Autodiscovery module here as it only support client well-known, not server ones.
|
||||||
|
const response = await fetch(`https://${hsName}/.well-known/matrix/server`);
|
||||||
|
const json = await response.json();
|
||||||
|
if (json["m.server"]) {
|
||||||
|
baseUrl = `https://${json["m.server"]}`;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.warn(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await fetch(`${baseUrl}/_matrix/federation/v1/version`);
|
||||||
|
return response.json();
|
||||||
|
}
|
||||||
|
|
||||||
const ServerInfo: React.FC<IDevtoolsProps> = ({ onBack }) => {
|
const ServerInfo: React.FC<IDevtoolsProps> = ({ onBack }) => {
|
||||||
const cli = useContext(MatrixClientContext);
|
const cli = useContext(MatrixClientContext);
|
||||||
const capabilities = useAsyncMemo(() => cli.getCapabilities(true).catch(() => FAILED_TO_LOAD), [cli]);
|
const capabilities = useAsyncMemo(() => cli.getCapabilities(true).catch(() => FAILED_TO_LOAD), [cli]);
|
||||||
const clientVersions = useAsyncMemo(() => cli.getVersions().catch(() => FAILED_TO_LOAD), [cli]);
|
const clientVersions = useAsyncMemo(() => cli.getVersions().catch(() => FAILED_TO_LOAD), [cli]);
|
||||||
const serverVersions = useAsyncMemo(async (): Promise<IServerWellKnown | symbol> => {
|
const serverVersions = useAsyncMemo(async (): Promise<IServerWellKnown | symbol> => {
|
||||||
let baseUrl = cli.getHomeserverUrl();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const hsName = MatrixClientPeg.getHomeserverName();
|
return await getServerVersionFromFederationApi(cli);
|
||||||
// We don't use the js-sdk Autodiscovery module here as it only support client well-known, not server ones.
|
|
||||||
const response = await fetch(`https://${hsName}/.well-known/matrix/server`);
|
|
||||||
const json = await response.json();
|
|
||||||
if (json["m.server"]) {
|
|
||||||
baseUrl = `https://${json["m.server"]}`;
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.warn(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await fetch(`${baseUrl}/_matrix/federation/v1/version`);
|
|
||||||
return response.json();
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn(e);
|
console.warn(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { logger } from "matrix-js-sdk/src/logger";
|
import { logger } from "matrix-js-sdk/src/logger";
|
||||||
|
import { Method } from "matrix-js-sdk/src/http-api";
|
||||||
|
|
||||||
import type * as Pako from "pako";
|
import type * as Pako from "pako";
|
||||||
import { MatrixClientPeg } from "../MatrixClientPeg";
|
import { MatrixClientPeg } from "../MatrixClientPeg";
|
||||||
|
@ -25,6 +26,7 @@ import { _t } from "../languageHandler";
|
||||||
import * as rageshake from "./rageshake";
|
import * as rageshake from "./rageshake";
|
||||||
import SettingsStore from "../settings/SettingsStore";
|
import SettingsStore from "../settings/SettingsStore";
|
||||||
import SdkConfig from "../SdkConfig";
|
import SdkConfig from "../SdkConfig";
|
||||||
|
import { getServerVersionFromFederationApi } from "../components/views/dialogs/devtools/ServerInfo";
|
||||||
|
|
||||||
interface IOpts {
|
interface IOpts {
|
||||||
labels?: string[];
|
labels?: string[];
|
||||||
|
@ -122,6 +124,43 @@ async function collectBugReport(opts: IOpts = {}, gzipLogs = true): Promise<Form
|
||||||
body.append("session_backup_key_cached", String(!!sessionBackupKeyFromCache));
|
body.append("session_backup_key_cached", String(!!sessionBackupKeyFromCache));
|
||||||
body.append("session_backup_key_well_formed", String(sessionBackupKeyFromCache instanceof Uint8Array));
|
body.append("session_backup_key_well_formed", String(sessionBackupKeyFromCache instanceof Uint8Array));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// XXX: This is synapse-specific but better than nothing until MSC support for a server version endpoint
|
||||||
|
const data = await client.http.request<Record<string, any>>(
|
||||||
|
Method.Get,
|
||||||
|
"/server_version",
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
{
|
||||||
|
prefix: "/_synapse/admin/v1",
|
||||||
|
},
|
||||||
|
);
|
||||||
|
Object.keys(data).forEach((key) => {
|
||||||
|
body.append(`matrix_hs_${key}`, data[key]);
|
||||||
|
});
|
||||||
|
} catch {
|
||||||
|
try {
|
||||||
|
// XXX: This relies on the federation listener being delegated via well-known
|
||||||
|
// or at the same place as the client server endpoint
|
||||||
|
const data = await getServerVersionFromFederationApi(client);
|
||||||
|
body.append("matrix_hs_name", data.server.name);
|
||||||
|
body.append("matrix_hs_version", data.server.version);
|
||||||
|
} catch {
|
||||||
|
try {
|
||||||
|
// If that fails we'll hit any endpoint and look at the server response header
|
||||||
|
const res = await window.fetch(client.http.getUrl("/login"), {
|
||||||
|
method: "GET",
|
||||||
|
mode: "cors",
|
||||||
|
});
|
||||||
|
if (res.headers.has("server")) {
|
||||||
|
body.append("matrix_hs_server", res.headers.get("server")!);
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// Could not determine server version
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opts.labels) {
|
if (opts.labels) {
|
||||||
|
|
Loading…
Reference in New Issue