configuration

This commit is contained in:
Reto Brunner 2024-02-29 07:53:23 +01:00
parent 7bc184b252
commit 8e6920af1d
7 changed files with 111 additions and 119 deletions

View file

@ -3,7 +3,8 @@ import socket from "../socket";
import {cleanIrcMessage} from "../../../shared/irc";
import {store} from "../store";
import {switchToChannel} from "../router";
import {ClientChan, ClientMention, ClientMessage, NetChan} from "../types";
import {ClientChan, NetChan} from "../types";
import {ClientMessage} from "../../../shared/types/msg";
let pop;

View file

@ -3,19 +3,13 @@
import {ActionContext, createStore, Store, useStore as baseUseStore} from "vuex";
import {createSettingsStore} from "./store-settings";
import storage from "./localStorage";
import type {
ClientChan,
ClientConfiguration,
ClientNetwork,
InitClientChan,
NetChan,
ClientMessage,
ClientMention,
} from "./types";
import type {ClientChan, ClientNetwork, InitClientChan, NetChan, ClientMention} from "./types";
import type {InjectionKey} from "vue";
import {SettingsState} from "./settings";
import {SearchQuery} from "../../shared/types/storage";
import {ClientMessage} from "../../shared/types/msg";
import {SharedConfiguration, LockedSharedConfiguration} from "../../shared/types/config";
const appName = document.title;
@ -59,7 +53,7 @@ export type State = {
mentions: ClientMention[];
hasServiceWorker: boolean;
pushNotificationState: string;
serverConfiguration: ClientConfiguration | null;
serverConfiguration: SharedConfiguration | LockedSharedConfiguration | null;
sessions: ClientSession[];
sidebarOpen: boolean;
sidebarDragging: boolean;

View file

@ -4,7 +4,7 @@ import {SharedChan} from "../../shared/types/chan";
import {SharedNetwork} from "../../shared/types/network";
import {SharedUser} from "../../shared/models/user";
import {SharedMention} from "../../shared/models/mention";
import {ClientConfiguration} from "../../server/server";
import {SharedConfiguration, LockedSharedConfiguration} from "../../shared/types/config";
import {LinkPreview} from "../../server/plugins/irc-events/link";
interface LoungeWindow extends Window {
@ -51,7 +51,6 @@ type NetChan = {
network: ClientNetwork;
};
type ClientConfiguration = ClientConfiguration;
type ClientMention = SharedMention & {
localetime: string;
channel: NetChan | null;

View file

@ -44,7 +44,7 @@ export type Defaults = Pick<
| "saslAccount"
| "saslPassword"
> & {
join?: string;
join: string;
};
type Identd = {

View file

@ -32,6 +32,12 @@ import type {
SocketData,
} from "../shared/types/socket-events";
import {ChanType} from "../shared/types/chan";
import {
LockedSharedConfiguration,
SharedConfiguration,
ConfigNetDefaults,
LockedConfigNetDefaults,
} from "../shared/types/config";
type ServerOptions = {
dev: boolean;
@ -45,22 +51,6 @@ type IndexTemplateConfiguration = ServerConfiguration & {
cacheBust: string;
};
export type ClientConfiguration = Pick<
ConfigType,
"public" | "lockNetwork" | "useHexIp" | "prefetch" | "defaults"
> & {
fileUpload: boolean;
ldapEnabled: boolean;
isUpdateAvailable: boolean;
applicationServerKey: string;
version: string;
gitCommit: string | null;
defaultTheme: string;
themes: ThemeForClient[];
defaults: Defaults;
fileUploadMaxFileSize?: number;
};
// A random number that will force clients to reload the page if it differs
const serverHash = Math.floor(Date.now() * Math.random());
@ -857,47 +847,58 @@ function initializeClient(
}
}
function getClientConfiguration(): ClientConfiguration {
const config = _.pick(Config.values, [
"public",
"lockNetwork",
"useHexIp",
"prefetch",
]) as ClientConfiguration;
function getClientConfiguration(): SharedConfiguration | LockedSharedConfiguration {
const common = {
fileUpload: Config.values.fileUpload.enable,
ldapEnabled: Config.values.ldap.enable,
isUpdateAvailable: changelog.isUpdateAvailable,
applicationServerKey: manager!.webPush.vapidKeys!.publicKey,
version: Helper.getVersionNumber(),
gitCommit: Helper.getGitCommit(),
themes: themes.getAll(),
defaultTheme: Config.values.theme,
public: Config.values.public,
useHexIp: Config.values.useHexIp,
prefetch: Config.values.prefetch,
fileUploadMaxFileSize: Uploader ? Uploader.getMaxFileSize() : undefined, // TODO can't be undefined?
};
config.fileUpload = Config.values.fileUpload.enable;
config.ldapEnabled = Config.values.ldap.enable;
const defaultsOverride = {
nick: Config.getDefaultNick(), // expand the number part
if (!config.lockNetwork) {
config.defaults = _.clone(Config.values.defaults);
} else {
// Only send defaults that are visible on the client
config.defaults = _.pick(Config.values.defaults, [
"name",
"nick",
"username",
"password",
"realname",
"join",
]) as Defaults;
// TODO: this doesn't seem right, if the client needs this as a buffer
// the client ought to add it on its own
sasl: "",
saslAccount: "",
saslPassword: "",
};
if (!Config.values.lockNetwork) {
const defaults: ConfigNetDefaults = {
..._.clone(Config.values.defaults),
...defaultsOverride,
};
const result: SharedConfiguration = {
...common,
defaults: defaults,
lockNetwork: Config.values.lockNetwork,
};
return result;
}
config.isUpdateAvailable = changelog.isUpdateAvailable;
config.applicationServerKey = manager!.webPush.vapidKeys!.publicKey;
config.version = Helper.getVersionNumber();
config.gitCommit = Helper.getGitCommit();
config.themes = themes.getAll();
config.defaultTheme = Config.values.theme;
config.defaults.nick = Config.getDefaultNick();
config.defaults.sasl = "";
config.defaults.saslAccount = "";
config.defaults.saslPassword = "";
// Only send defaults that are visible on the client
const defaults: LockedConfigNetDefaults = {
..._.pick(Config.values.defaults, ["name", "username", "password", "realname", "join"]),
...defaultsOverride,
};
if (Uploader) {
config.fileUploadMaxFileSize = Uploader.getMaxFileSize();
}
const result: LockedSharedConfiguration = {
...common,
lockNetwork: Config.values.lockNetwork,
defaults: defaults,
};
return config;
return result;
}
function getServerConfiguration(): ServerConfiguration {

View file

@ -1,53 +1,50 @@
const config_example = {
public: false,
lockNetwork: false,
useHexIp: false,
prefetch: true,
fileUpload: true,
ldapEnabled: false,
defaults: {
name: "test",
host: "irc.libera.chat",
port: 6697,
password: "",
tls: true,
rejectUnauthorized: true,
nick: "butler",
username: "",
realname: "",
join: "#thelounge-test",
leaveMessage: "",
sasl: "",
saslAccount: "",
saslPassword: "",
},
isUpdateAvailable: false,
applicationServerKey:
"BHcIWSuK8Yt_1nkWqKFcSdLQtuLuZyfegdugXQa_UBv02dOZtDhwEJocb1h8bxOSzLgkNRAAArw8BC126rTuc5Q",
version: "4.4.2-rc.1",
gitCommit: "1f66dd2af",
themes: [
{
displayName: "Default",
name: "default",
themeColor: null,
},
{
displayName: "Gruvbox",
name: "thelounge-theme-gruvbox",
themeColor: "#282828",
},
{
displayName: "Morning",
name: "morning",
themeColor: null,
},
{
displayName: "Solarized",
name: "thelounge-theme-solarized",
themeColor: "#002b36",
},
],
defaultTheme: "default",
fileUploadMaxFileSize: 10485760,
export type ConfigTheme = {
displayName: string;
name: string;
themeColor: string | null;
};
type SharedConfigurationBase = {
public: boolean;
useHexIp: boolean;
prefetch: boolean;
fileUpload: boolean;
ldapEnabled: boolean;
isUpdateAvailable: boolean;
applicationServerKey: string;
version: string;
gitCommit: string | null;
themes: ConfigTheme[];
defaultTheme: string;
fileUploadMaxFileSize?: number;
};
export type ConfigNetDefaults = {
name: string;
host: string;
port: number;
password: string;
tls: boolean;
rejectUnauthorized: boolean;
nick: string;
username: string;
realname: string;
join: string;
leaveMessage: string;
sasl: string;
saslAccount: string;
saslPassword: string;
};
export type LockedConfigNetDefaults = Pick<
ConfigNetDefaults,
"name" | "nick" | "username" | "password" | "realname" | "join"
>;
export type LockedSharedConfiguration = SharedConfigurationBase & {
lockNetwork: true;
defaults: LockedConfigNetDefaults;
};
export type SharedConfiguration = SharedConfigurationBase & {
lockNetwork: false;
defaults: ConfigNetDefaults;
};

View file

@ -5,7 +5,7 @@ import {SharedMsg, ClientMessage} from "../../shared/types/msg";
import {SharedUser} from "../../shared/types/user";
import {SharedChangelogData} from "../../shared/types/changelog";
import {LinkPreview} from "../plugins/irc-events/link";
import {ClientConfiguration} from "../server";
import {SharedConfiguration, LockedSharedConfiguration} from "../../shared/types/config";
type Session = {
current: boolean;
@ -32,7 +32,7 @@ interface ServerToClientEvents {
commands: (data: string[]) => void;
configuration: (config: ClientConfiguration) => void;
configuration: (config: SharedConfiguration | LockedSharedConfiguration) => void;
"push:issubscribed": (isSubscribed: boolean) => void;
"push:unregister": () => void;