keanu-weblite/src/services/config.service.js
N-Pex d10e075721 Build 47
Fix error introduced by merge.
2025-05-19 17:04:25 +02:00

76 lines
3 KiB
JavaScript

import * as defaultConfig from "@/assets/config.json";
export default {
install(app, defaultServerFromLocation, onloaded) {
var config = defaultConfig.default;
config["loaded"] = false;
const getRuntimeConfig = () => {
return fetch('./config.json?ms=' + Date.now()).then((res) => res.json()).catch(err => {
console.error("Failed to get config:", err);
return {};
});
}
config.promise = getRuntimeConfig().then((json) => {
// Reactively use all the config values
for (const key of Object.keys(json)) {
config[key] = json[key];
}
// If default server is not set, default to current server address
if (!json.defaultBaseUrl) {
if (json.defaultServer) {
// TODO - Only to migrate old values (defaultServer was renamed defaultBaseUrl), can be removed later...
config["defaultBaseUrl"] = defaultServerFromLocation;
} else {
config["defaultBaseUrl"] = json.defaultServer;
}
}
if (json.useFullyQualifiedDMLinks == undefined) {
config["useFullyQualifiedDMLinks"] = true; // Default to true
}
if (json.disableMediaSharing == undefined) {
config["disableMediaSharing"] = false;
}
if (!json.maxSizeAutoDownloads) {
config["maxSizeAutoDownloads"] = 10 * 1024 * 1024;
}
if (!json.roomTypes) {
let roomTypes = ["group_chat", "channel"];
const fileDropEnabled = (json.experimental_file_mode === undefined) ? true : !!json.experimental_file_mode;
if (fileDropEnabled) {
roomTypes.push("file_drop");
}
config["roomTypes"] = roomTypes;
}
config["loaded"] = true;
document.title = config.appName || "";
// Tell callback we are done loading runtime config
if (onloaded) {
onloaded(config);
}
return config;
});
/**
* If there is an explicit mapping for this MX domain in the config file, return the endpoint URL that it maps to.
* @param {*} domain
* @returns
*/
config.getMatrixDomainPartMapping = (domain) => {
console.log("Get domain endpoint mapping for", domain);
if (config.matrixDomainPartMapping && config.matrixDomainPartMapping[domain]) {
const mapping = config.matrixDomainPartMapping[domain];
if (Array.isArray(mapping)) {
return mapping[0]; //TODO - Use the first one for now, but maybe rotate somehow?
}
return mapping;
}
return undefined;
}
app.$config = config;
app.config.globalProperties.$config = config;
}
}