web interfaces: don't include version number in html, only return it after authentication

second round for issue #322
This commit is contained in:
Mechiel Lukkien
2025-03-29 20:46:53 +01:00
parent eeeabdc6de
commit 3a3a11560e
18 changed files with 217 additions and 35 deletions

View File

@ -18,6 +18,7 @@ import (
"net/textproto"
"os"
"regexp"
"runtime"
"runtime/debug"
"slices"
"sort"
@ -130,6 +131,11 @@ func (w Webmail) Logout(ctx context.Context) {
xcheckf(ctx, err, "logout")
}
// Version returns the version, goos and goarch.
func (w Webmail) Version(ctx context.Context) (version, goos, goarch string) {
return moxvar.Version, runtime.GOOS, runtime.GOARCH
}
// Token returns a single-use token to use for an SSE connection. A token can only
// be used for a single SSE connection. Tokens are stored in memory for a maximum
// of 1 minute, with at most 10 unused tokens (the most recently created) per

View File

@ -53,6 +53,31 @@
"Params": [],
"Returns": []
},
{
"Name": "Version",
"Docs": "Version returns the version, goos and goarch.",
"Params": [],
"Returns": [
{
"Name": "version",
"Typewords": [
"string"
]
},
{
"Name": "goos",
"Typewords": [
"string"
]
},
{
"Name": "goarch",
"Typewords": [
"string"
]
}
]
},
{
"Name": "Token",
"Docs": "Token returns a single-use token to use for an SSE connection. A token can only\nbe used for a single SSE connection. Tokens are stored in memory for a maximum\nof 1 minute, with at most 10 unused tokens (the most recently created) per\naccount.",

View File

@ -765,6 +765,15 @@ export class Client {
return await _sherpaCall(this.baseURL, this.authState, { ...this.options }, paramTypes, returnTypes, fn, params) as void
}
// Version returns the version, goos and goarch.
async Version(): Promise<[string, string, string]> {
const fn: string = "Version"
const paramTypes: string[][] = []
const returnTypes: string[][] = [["string"],["string"],["string"]]
const params: any[] = []
return await _sherpaCall(this.baseURL, this.authState, { ...this.options }, paramTypes, returnTypes, fn, params) as [string, string, string]
}
// Token returns a single-use token to use for an SSE connection. A token can only
// be used for a single SSE connection. Tokens are stored in memory for a maximum
// of 1 minute, with at most 10 unused tokens (the most recently created) per

View File

@ -448,6 +448,14 @@ var api;
const params = [];
return await _sherpaCall(this.baseURL, this.authState, { ...this.options }, paramTypes, returnTypes, fn, params);
}
// Version returns the version, goos and goarch.
async Version() {
const fn = "Version";
const paramTypes = [];
const returnTypes = [["string"], ["string"], ["string"]];
const params = [];
return await _sherpaCall(this.baseURL, this.authState, { ...this.options }, paramTypes, returnTypes, fn, params);
}
// Token returns a single-use token to use for an SSE connection. A token can only
// be used for a single SSE connection. Tokens are stored in memory for a maximum
// of 1 minute, with at most 10 unused tokens (the most recently created) per

View File

@ -448,6 +448,14 @@ var api;
const params = [];
return await _sherpaCall(this.baseURL, this.authState, { ...this.options }, paramTypes, returnTypes, fn, params);
}
// Version returns the version, goos and goarch.
async Version() {
const fn = "Version";
const paramTypes = [];
const returnTypes = [["string"], ["string"], ["string"]];
const params = [];
return await _sherpaCall(this.baseURL, this.authState, { ...this.options }, paramTypes, returnTypes, fn, params);
}
// Token returns a single-use token to use for an SSE connection. A token can only
// be used for a single SSE connection. Tokens are stored in memory for a maximum
// of 1 minute, with at most 10 unused tokens (the most recently created) per

View File

@ -448,6 +448,14 @@ var api;
const params = [];
return await _sherpaCall(this.baseURL, this.authState, { ...this.options }, paramTypes, returnTypes, fn, params);
}
// Version returns the version, goos and goarch.
async Version() {
const fn = "Version";
const paramTypes = [];
const returnTypes = [["string"], ["string"], ["string"]];
const params = [];
return await _sherpaCall(this.baseURL, this.authState, { ...this.options }, paramTypes, returnTypes, fn, params);
}
// Token returns a single-use token to use for an SSE connection. A token can only
// be used for a single SSE connection. Tokens are stored in memory for a maximum
// of 1 minute, with at most 10 unused tokens (the most recently created) per
@ -1571,6 +1579,9 @@ const yscrollAutoStyle = css('yscrollAuto', { overflowY: 'auto', position: 'abso
const autosizeStyle = css('autosize', { display: 'inline-grid', maxWidth: '90vw' });
ensureCSS('.autosize.input', { gridArea: '1 / 2' });
ensureCSS('.autosize::after', { content: 'attr(data-value)', marginRight: '1em', lineHeight: 0, visibility: 'hidden', whiteSpace: 'pre-wrap', overflowX: 'hidden' });
let moxversion;
let moxgoos;
let moxgoarch;
// All logging goes through log() instead of console.log, except "should not happen" logging.
let log = () => { };
try {
@ -6329,7 +6340,9 @@ const init = async () => {
let requestViewEnd = false; // If true, there is no more data to fetch, no more page needed for this view.
let requestFilter = newFilter();
let requestNotFilter = newNotFilter();
let requestMsgID = 0; // If > 0, we are still expecting a parsed message for the view, coming from the query. Either we get it and set msgitemViewActive and clear this, or we get to the end of the data and clear it.
let requestMsgID = 0 // If > 0, we are still expecting a parsed message for the view, coming from the query. Either we get it and set msgitemViewActive and clear this, or we get to the end of the data and clear it.
;
[moxversion, moxgoos, moxgoarch] = await client.Version();
const updatePageTitle = () => {
const mb = mailboxlistView && mailboxlistView.activeMailbox();
const addr = loginAddress ? loginAddress.User + '@' + formatDomain(loginAddress.Domain) : '';

View File

@ -127,12 +127,13 @@ ensureCSS('.autosize::after', {content: 'attr(data-value)', marginRight: '1em',
// From HTML.
declare let page: HTMLElement
declare let moxversion: string
declare let moxgoos: string
declare let moxgoarch: string
// From customization script.
declare let moxBeforeDisplay: (root: HTMLElement) => void
let moxversion: string
let moxgoos: string
let moxgoarch: string
// All logging goes through log() instead of console.log, except "should not happen" logging.
let log: (...args: any[]) => void = () => {}
try {
@ -6342,6 +6343,8 @@ const init = async () => {
let requestNotFilter = newNotFilter()
let requestMsgID = 0 // If > 0, we are still expecting a parsed message for the view, coming from the query. Either we get it and set msgitemViewActive and clear this, or we get to the end of the data and clear it.
;[moxversion, moxgoos, moxgoarch] = await client.Version()
const updatePageTitle = () => {
const mb = mailboxlistView && mailboxlistView.activeMailbox()
const addr = loginAddress ? loginAddress.User+'@'+formatDomain(loginAddress.Domain) : ''