mirror of
https://github.com/hcengineering/platform.git
synced 2024-11-26 13:47:26 +03:00
UBERF-7595: Do not use /api/v1/version on connect (#6075)
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
parent
d6eaaa9f01
commit
2b3caf6283
@ -269,6 +269,10 @@ export async function createClient (
|
||||
const oldOnConnect: ((event: ClientConnectEvent) => Promise<void>) | undefined = conn.onConnect
|
||||
conn.onConnect = async (event) => {
|
||||
console.log('Client: onConnect', event)
|
||||
if (event === ClientConnectEvent.Maintenance) {
|
||||
await oldOnConnect?.(ClientConnectEvent.Maintenance)
|
||||
return
|
||||
}
|
||||
// Find all new transactions and apply
|
||||
const loadModelResponse = await ctx.with(
|
||||
'connect',
|
||||
|
@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
import notification, { type DocNotifyContext } from '@hcengineering/notification'
|
||||
import notification, { type DocNotifyContext, type InboxNotification } from '@hcengineering/notification'
|
||||
import {
|
||||
generateId,
|
||||
type Ref,
|
||||
@ -409,7 +409,7 @@ export async function removeActivityChannels (contexts: DocNotifyContext[]): Pro
|
||||
const notifications = notificationsByContext.get(context._id) ?? []
|
||||
await client.archiveNotifications(
|
||||
ops,
|
||||
notifications.map(({ _id }) => _id)
|
||||
notifications.map(({ _id }: InboxNotification) => _id)
|
||||
)
|
||||
await ops.remove(context)
|
||||
}
|
||||
|
@ -55,10 +55,6 @@ export async function connect (title: string): Promise<Client | undefined> {
|
||||
_token = token
|
||||
|
||||
let version: Version | undefined
|
||||
let serverEndpoint = endpoint.replace(/^ws/g, 'http')
|
||||
if (serverEndpoint.endsWith('/')) {
|
||||
serverEndpoint = serverEndpoint.substring(0, serverEndpoint.length - 1)
|
||||
}
|
||||
const clientFactory = await getResource(client.function.GetClient)
|
||||
_client = await clientFactory(
|
||||
token,
|
||||
@ -98,21 +94,15 @@ export async function connect (title: string): Promise<Client | undefined> {
|
||||
location.reload()
|
||||
versionError.set(`${currentVersionStr} != ${reconnectVersionStr}`)
|
||||
}
|
||||
const serverVersion: { version: string } = await (
|
||||
await fetch(serverEndpoint + '/api/v1/version', {})
|
||||
).json()
|
||||
|
||||
console.log('Server version', serverVersion.version)
|
||||
if (serverVersion.version !== '' && serverVersion.version !== currentVersionStr) {
|
||||
console.log('Server version', reconnectVersionStr)
|
||||
if (reconnectVersionStr !== '' && reconnectVersionStr !== currentVersionStr) {
|
||||
if (typeof sessionStorage !== 'undefined') {
|
||||
if (sessionStorage.getItem(versionStorageKey) !== serverVersion.version) {
|
||||
sessionStorage.setItem(versionStorageKey, serverVersion.version)
|
||||
if (sessionStorage.getItem(versionStorageKey) !== reconnectVersionStr) {
|
||||
sessionStorage.setItem(versionStorageKey, reconnectVersionStr)
|
||||
location.reload()
|
||||
}
|
||||
} else {
|
||||
location.reload()
|
||||
}
|
||||
versionError.set(`${currentVersionStr} => ${serverVersion.version}`)
|
||||
versionError.set(`${currentVersionStr} => ${reconnectVersionStr}`)
|
||||
}
|
||||
}
|
||||
})()
|
||||
@ -146,23 +136,6 @@ export async function connect (title: string): Promise<Client | undefined> {
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const serverVersion: { version: string } = await (await fetch(serverEndpoint + '/api/v1/version', {})).json()
|
||||
|
||||
console.log('Server version', serverVersion.version, version !== undefined ? versionToString(version) : '')
|
||||
if (
|
||||
serverVersion.version !== '' &&
|
||||
(version === undefined || serverVersion.version !== versionToString(version))
|
||||
) {
|
||||
const versionStr = version !== undefined ? versionToString(version) : 'unknown'
|
||||
versionError.set(`${versionStr} => ${serverVersion.version}`)
|
||||
return
|
||||
}
|
||||
} catch (err: any) {
|
||||
versionError.set('server version not available')
|
||||
return
|
||||
}
|
||||
} catch (err: any) {
|
||||
Analytics.handleError(err)
|
||||
console.error(err)
|
||||
|
@ -132,12 +132,8 @@ export async function connect (title: string): Promise<Client | undefined> {
|
||||
}
|
||||
_token = token
|
||||
|
||||
let version: Version | undefined
|
||||
let serverEndpoint = endpoint.replace(/^ws/g, 'http')
|
||||
if (serverEndpoint.endsWith('/')) {
|
||||
serverEndpoint = serverEndpoint.substring(0, serverEndpoint.length - 1)
|
||||
}
|
||||
const clientFactory = await getResource(client.function.GetClient)
|
||||
let version: Version | undefined
|
||||
const newClient = await ctx.with(
|
||||
'create-client',
|
||||
{},
|
||||
@ -195,29 +191,21 @@ export async function connect (title: string): Promise<Client | undefined> {
|
||||
location.reload()
|
||||
versionError.set(`${currentVersionStr} != ${reconnectVersionStr}`)
|
||||
}
|
||||
const serverVersion: { version: string } = await ctx.with(
|
||||
'fetch-server-version',
|
||||
{},
|
||||
async () => await (await fetch(serverEndpoint + '/api/v1/version', {})).json()
|
||||
)
|
||||
|
||||
console.log(
|
||||
'Server version',
|
||||
serverVersion.version,
|
||||
reconnectVersionStr,
|
||||
version !== undefined ? versionToString(version) : ''
|
||||
)
|
||||
if (serverVersion.version !== '' && serverVersion.version !== currentVersionStr) {
|
||||
|
||||
if (reconnectVersionStr !== '' && currentVersionStr !== reconnectVersionStr) {
|
||||
if (typeof sessionStorage !== 'undefined') {
|
||||
if (sessionStorage.getItem(versionStorageKey) !== serverVersion.version) {
|
||||
sessionStorage.setItem(versionStorageKey, serverVersion.version)
|
||||
if (sessionStorage.getItem(versionStorageKey) !== reconnectVersionStr) {
|
||||
sessionStorage.setItem(versionStorageKey, reconnectVersionStr)
|
||||
location.reload()
|
||||
}
|
||||
} else {
|
||||
location.reload()
|
||||
}
|
||||
versionError.set(`${currentVersionStr} => ${serverVersion.version}`)
|
||||
} else {
|
||||
versionError.set(undefined)
|
||||
versionError.set(`${currentVersionStr} != ${reconnectVersionStr}`)
|
||||
}
|
||||
}
|
||||
})()
|
||||
@ -276,27 +264,6 @@ export async function connect (title: string): Promise<Client | undefined> {
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const serverVersion: { version: string } = await ctx.with(
|
||||
'find-server-version',
|
||||
{},
|
||||
async () => await (await fetch(serverEndpoint + '/api/v1/version', {})).json()
|
||||
)
|
||||
|
||||
console.log('Server version', serverVersion.version, version !== undefined ? versionToString(version) : '')
|
||||
if (
|
||||
serverVersion.version !== '' &&
|
||||
(version === undefined || serverVersion.version !== versionToString(version))
|
||||
) {
|
||||
const versionStr = version !== undefined ? versionToString(version) : 'unknown'
|
||||
versionError.set(`${versionStr} => ${serverVersion.version}`)
|
||||
return
|
||||
}
|
||||
} catch (err: any) {
|
||||
versionError.set('server version not available')
|
||||
return
|
||||
}
|
||||
} catch (err: any) {
|
||||
console.error(err)
|
||||
Analytics.handleError(err)
|
||||
|
@ -221,25 +221,35 @@ class TSessionManager implements SessionManager {
|
||||
|
||||
@withContext('get-workspace-info')
|
||||
async getWorkspaceInfo (ctx: MeasureContext, accounts: string, token: string): Promise<WorkspaceLoginInfo> {
|
||||
const userInfo = await (
|
||||
await fetch(accounts, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Authorization: 'Bearer ' + token,
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
method: 'getWorkspaceInfo',
|
||||
params: [true]
|
||||
})
|
||||
})
|
||||
).json()
|
||||
if (userInfo.error !== undefined) {
|
||||
ctx.error('Error response from account service', { error: JSON.stringify(userInfo) })
|
||||
throw new Error(JSON.stringify(userInfo.error))
|
||||
}
|
||||
for (let i = 0; i < 10; i++) {
|
||||
try {
|
||||
const userInfo = await (
|
||||
await fetch(accounts, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Authorization: 'Bearer ' + token,
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
method: 'getWorkspaceInfo',
|
||||
params: [true]
|
||||
})
|
||||
})
|
||||
).json()
|
||||
|
||||
return { ...userInfo.result, upgrade: userInfo.upgrade }
|
||||
if (userInfo.error !== undefined) {
|
||||
ctx.error('Error response from account service', { error: JSON.stringify(userInfo) })
|
||||
throw new Error(JSON.stringify(userInfo.error))
|
||||
}
|
||||
return { ...userInfo.result, upgrade: userInfo.upgrade }
|
||||
} catch (err: any) {
|
||||
if (i === 9) {
|
||||
throw err
|
||||
}
|
||||
await new Promise<void>((resolve) => setTimeout(resolve, 100))
|
||||
}
|
||||
}
|
||||
throw new Error('')
|
||||
}
|
||||
|
||||
@withContext('📲 add-session')
|
||||
|
Loading…
Reference in New Issue
Block a user