Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 42 additions & 5 deletions plugins/workbench-resources/src/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -164,7 +201,7 @@ export async function connect (title: string): Promise<Client | undefined> {
showPopup(
ServerManager,
{
endpoint: ep,
endpoint: serverEndpoint,
token
},
'content'
Expand Down
9 changes: 9 additions & 0 deletions server/ws/src/server_http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down