UBER-854: More proper upgrade notification (#3694)

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev 2023-09-14 23:24:15 +07:00 committed by GitHub
parent 61cc74d7a0
commit c7fe158dfd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 5 deletions

View File

@ -97,6 +97,15 @@ export async function connect (title: string): Promise<Client | undefined> {
// It seems upgrade happened
location.reload()
}
const serverVersion: { version: string } = await (await fetch(serverEndpoint + '/api/v1/version', {})).json()
console.log('Server version', serverVersion.version)
if (serverVersion.version !== '' && serverVersion.version !== currentVersionStr) {
versionError = `${currentVersionStr} => ${serverVersion.version}`
setTimeout(() => {
window.location.reload()
}, 5000)
}
})()
} catch (err) {
console.error(err)
@ -123,6 +132,11 @@ export async function connect (title: string): Promise<Client | undefined> {
return
}
let serverEndpoint = endpoint.replace(/^ws/g, 'http')
if (serverEndpoint.endsWith('/')) {
serverEndpoint = serverEndpoint.substring(0, serverEndpoint.length - 1)
}
try {
version = await _client.findOne<Version>(core.class.Version, {})
console.log('Model version', version)
@ -134,9 +148,36 @@ export async function connect (title: string): Promise<Client | undefined> {
if (version === undefined || requiredVersion !== versionStr) {
versionError = `${versionStr} => ${requiredVersion}`
setTimeout(() => {
window.location.reload()
}, 5000)
return undefined
}
}
try {
const serverVersion: { version: string } = await (await fetch(serverEndpoint + '/api/v1/version', {})).json()
console.log('Server version', serverVersion.version)
if (
serverVersion.version !== '' &&
(version === undefined || serverVersion.version !== versionToString(version))
) {
const versionStr = version !== undefined ? versionToString(version) : 'unknown'
versionError = `${versionStr} => ${serverVersion.version}`
setTimeout(() => {
window.location.reload()
}, 5000)
return
}
} catch (err: any) {
versionError = 'server version not available'
setTimeout(() => {
window.location.reload()
}, 5000)
return
}
} catch (err: any) {
console.log(err)
const requirdVersion = getMetadata(presentation.metadata.RequiredVersion)
@ -152,10 +193,6 @@ export async function connect (title: string): Promise<Client | undefined> {
await setClient(_client)
if (me.role === AccountRole.Owner) {
let ep = endpoint.replace(/^ws/g, 'http')
if (ep.endsWith('/')) {
ep = ep.substring(0, ep.length - 1)
}
setMetadata(ui.metadata.ShowNetwork, (evt: MouseEvent) => {
if (getMetadata(presentation.metadata.Token) == null) {
return
@ -164,7 +201,7 @@ export async function connect (title: string): Promise<Client | undefined> {
showPopup(
ServerManager,
{
endpoint: ep,
endpoint: serverEndpoint,
token
},
'content'

View File

@ -61,6 +61,15 @@ export function startHttpServer (
const getUsers = (): any => Array.from(sessions.sessions.entries()).map(([k, v]) => v.session.getUser())
app.get('/api/v1/version', (req, res) => {
res.writeHead(200, { 'Content-Type': 'application/json' })
res.end(
JSON.stringify({
version: process.env.MODEL_VERSION
})
)
})
app.get('/api/v1/statistics', (req, res) => {
try {
const token = req.query.token as string