mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-21 07:46:24 +00:00
Fix services connectivity (#6193)
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
parent
3969fb0dd8
commit
824defc6e3
@ -19,6 +19,7 @@
|
|||||||
"_phase:docker-staging": "rushx docker:staging",
|
"_phase:docker-staging": "rushx docker:staging",
|
||||||
"bundle": "mkdir -p bundle && esbuild src/index.ts --bundle --platform=node > bundle/bundle.js",
|
"bundle": "mkdir -p bundle && esbuild src/index.ts --bundle --platform=node > bundle/bundle.js",
|
||||||
"docker:build": "../../../common/scripts/docker_build.sh hardcoreeng/calendar",
|
"docker:build": "../../../common/scripts/docker_build.sh hardcoreeng/calendar",
|
||||||
|
"docker:tbuild": "docker build -t hardcoreeng/calendar . --platform=linux/amd64 && ../../../common/scripts/docker_tag_push.sh hardcoreeng/calendar",
|
||||||
"docker:staging": "../../../common/scripts/docker_tag.sh hardcoreeng/calendar staging",
|
"docker:staging": "../../../common/scripts/docker_tag.sh hardcoreeng/calendar staging",
|
||||||
"docker:push": "../../../common/scripts/docker_tag.sh hardcoreeng/calendar",
|
"docker:push": "../../../common/scripts/docker_tag.sh hardcoreeng/calendar",
|
||||||
"run-local": "cross-env ts-node src/index.ts",
|
"run-local": "cross-env ts-node src/index.ts",
|
||||||
@ -63,6 +64,7 @@
|
|||||||
"@hcengineering/setting": "^0.6.17",
|
"@hcengineering/setting": "^0.6.17",
|
||||||
"@hcengineering/text": "^0.6.5",
|
"@hcengineering/text": "^0.6.5",
|
||||||
"@hcengineering/server-client": "^0.6.0",
|
"@hcengineering/server-client": "^0.6.0",
|
||||||
|
"@hcengineering/server-token": "^0.6.11",
|
||||||
"dotenv": "~16.0.0",
|
"dotenv": "~16.0.0",
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"express": "^4.19.2",
|
"express": "^4.19.2",
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
//
|
|
||||||
// Copyright © 2023 Hardcore Engineering Inc.
|
|
||||||
//
|
|
||||||
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License. You may
|
|
||||||
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
//
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
//
|
|
||||||
|
|
||||||
import { encode as jwtEncode, decode as jwtDecode } from 'jwt-simple'
|
|
||||||
|
|
||||||
import config from './config'
|
|
||||||
|
|
||||||
export const encode = (data: any): string => jwtEncode(data, config.Secret)
|
|
||||||
export const decode = (data: string): any => jwtDecode(data, config.Secret)
|
|
@ -18,12 +18,12 @@ import { decode64 } from './base64'
|
|||||||
import { CalendarClient } from './calendar'
|
import { CalendarClient } from './calendar'
|
||||||
import { CalendarController } from './calendarController'
|
import { CalendarController } from './calendarController'
|
||||||
import config from './config'
|
import config from './config'
|
||||||
import { decode } from './jwt'
|
|
||||||
import { createServer, listen } from './server'
|
import { createServer, listen } from './server'
|
||||||
import { closeDB, getDB } from './storage'
|
import { closeDB, getDB } from './storage'
|
||||||
import { type Endpoint, type State } from './types'
|
import { type Endpoint, type State } from './types'
|
||||||
import { setMetadata } from '@hcengineering/platform'
|
import { setMetadata } from '@hcengineering/platform'
|
||||||
import serverClient from '@hcengineering/server-client'
|
import serverClient from '@hcengineering/server-client'
|
||||||
|
import serverToken, { decodeToken } from '@hcengineering/server-token'
|
||||||
|
|
||||||
const extractToken = (header: IncomingHttpHeaders): any => {
|
const extractToken = (header: IncomingHttpHeaders): any => {
|
||||||
try {
|
try {
|
||||||
@ -36,6 +36,7 @@ const extractToken = (header: IncomingHttpHeaders): any => {
|
|||||||
export const main = async (): Promise<void> => {
|
export const main = async (): Promise<void> => {
|
||||||
setMetadata(serverClient.metadata.Endpoint, config.AccountsURL)
|
setMetadata(serverClient.metadata.Endpoint, config.AccountsURL)
|
||||||
setMetadata(serverClient.metadata.UserAgent, config.ServiceID)
|
setMetadata(serverClient.metadata.UserAgent, config.ServiceID)
|
||||||
|
setMetadata(serverToken.metadata.Secret, config.Secret)
|
||||||
|
|
||||||
const db = await getDB()
|
const db = await getDB()
|
||||||
const calendarController = CalendarController.getCalendarController(db)
|
const calendarController = CalendarController.getCalendarController(db)
|
||||||
@ -54,9 +55,9 @@ export const main = async (): Promise<void> => {
|
|||||||
}
|
}
|
||||||
const redirectURL = req.query.redirectURL as string
|
const redirectURL = req.query.redirectURL as string
|
||||||
|
|
||||||
const { email, workspace } = decode(token)
|
const { email, workspace } = decodeToken(token)
|
||||||
const userId = await calendarController.getUserId(email, workspace)
|
const userId = await calendarController.getUserId(email, workspace.name)
|
||||||
const url = CalendarClient.getAutUrl(redirectURL, workspace, userId, token)
|
const url = CalendarClient.getAutUrl(redirectURL, workspace.name, userId, token)
|
||||||
res.send(url)
|
res.send(url)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log('signin error', err)
|
console.log('signin error', err)
|
||||||
@ -93,8 +94,8 @@ export const main = async (): Promise<void> => {
|
|||||||
|
|
||||||
const value = req.query.value as string
|
const value = req.query.value as string
|
||||||
|
|
||||||
const { workspace } = decode(token)
|
const { workspace } = decodeToken(token)
|
||||||
await calendarController.signout(workspace, value)
|
await calendarController.signout(workspace.name, value)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log('signout error', err)
|
console.log('signout error', err)
|
||||||
}
|
}
|
||||||
|
@ -33,9 +33,9 @@ import { Collection, type Db } from 'mongodb'
|
|||||||
import { CalendarClient } from './calendar'
|
import { CalendarClient } from './calendar'
|
||||||
import { getClient } from './client'
|
import { getClient } from './client'
|
||||||
import config from './config'
|
import config from './config'
|
||||||
import { encode } from './jwt'
|
|
||||||
import { SyncHistory, type ProjectCredentials, type User } from './types'
|
import { SyncHistory, type ProjectCredentials, type User } from './types'
|
||||||
import { CalendarController } from './calendarController'
|
import { CalendarController } from './calendarController'
|
||||||
|
import { generateToken } from '@hcengineering/server-token'
|
||||||
|
|
||||||
export class WorkspaceClient {
|
export class WorkspaceClient {
|
||||||
private readonly txHandlers: ((...tx: Tx[]) => Promise<void>)[] = []
|
private readonly txHandlers: ((...tx: Tx[]) => Promise<void>)[] = []
|
||||||
@ -157,10 +157,7 @@ export class WorkspaceClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async initClient (workspace: string): Promise<Client> {
|
private async initClient (workspace: string): Promise<Client> {
|
||||||
const token = encode({
|
const token = generateToken(config.SystemEmail, { name: workspace, productId: '' })
|
||||||
email: config.SystemEmail,
|
|
||||||
workspace
|
|
||||||
})
|
|
||||||
const client = await getClient(token)
|
const client = await getClient(token)
|
||||||
client.notify = (...tx: Tx[]) => {
|
client.notify = (...tx: Tx[]) => {
|
||||||
void this.txHandler(...tx)
|
void this.txHandler(...tx)
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
"_phase:docker-staging": "rushx docker:staging",
|
"_phase:docker-staging": "rushx docker:staging",
|
||||||
"bundle": "mkdir -p bundle && esbuild src/index.ts --bundle --platform=node > bundle/bundle.js",
|
"bundle": "mkdir -p bundle && esbuild src/index.ts --bundle --platform=node > bundle/bundle.js",
|
||||||
"docker:build": "../../../common/scripts/docker_build.sh hardcoreeng/gmail",
|
"docker:build": "../../../common/scripts/docker_build.sh hardcoreeng/gmail",
|
||||||
|
"docker:tbuild": "docker build -t hardcoreeng/gmail . --platform=linux/amd64 && ../../../common/scripts/docker_tag_push.sh hardcoreeng/gmail",
|
||||||
"docker:staging": "../../../common/scripts/docker_tag.sh hardcoreeng/gmail staging",
|
"docker:staging": "../../../common/scripts/docker_tag.sh hardcoreeng/gmail staging",
|
||||||
"docker:push": "../../../common/scripts/docker_tag.sh hardcoreeng/gmail",
|
"docker:push": "../../../common/scripts/docker_tag.sh hardcoreeng/gmail",
|
||||||
"run-local": "cross-env ts-node src/index.ts",
|
"run-local": "cross-env ts-node src/index.ts",
|
||||||
@ -59,6 +60,7 @@
|
|||||||
"@hcengineering/contact": "^0.6.24",
|
"@hcengineering/contact": "^0.6.24",
|
||||||
"@hcengineering/core": "^0.6.32",
|
"@hcengineering/core": "^0.6.32",
|
||||||
"@hcengineering/gmail": "^0.6.22",
|
"@hcengineering/gmail": "^0.6.22",
|
||||||
|
"@hcengineering/server-token": "^0.6.11",
|
||||||
"@hcengineering/platform": "^0.6.11",
|
"@hcengineering/platform": "^0.6.11",
|
||||||
"@hcengineering/setting": "^0.6.17",
|
"@hcengineering/setting": "^0.6.17",
|
||||||
"@hcengineering/server-client": "^0.6.0",
|
"@hcengineering/server-client": "^0.6.0",
|
||||||
|
@ -19,5 +19,6 @@ import { createClient, getTransactorEndpoint } from '@hcengineering/server-clien
|
|||||||
|
|
||||||
export async function getClient (token: string): Promise<Client> {
|
export async function getClient (token: string): Promise<Client> {
|
||||||
const endpoint = await getTransactorEndpoint(token)
|
const endpoint = await getTransactorEndpoint(token)
|
||||||
return await createClient(token, endpoint)
|
console.log('connecting to', endpoint)
|
||||||
|
return await createClient(endpoint, token)
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,7 @@ export class GmailController {
|
|||||||
res = await WorkspaceClient.create(this.credentials, this.mongo, workspace)
|
res = await WorkspaceClient.create(this.credentials, this.mongo, workspace)
|
||||||
this.workspaces.set(workspace, res)
|
this.workspaces.set(workspace, res)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(`Couldn't create workspace worker for ${workspace}, reason: ${JSON.stringify(err)}`)
|
console.error(`Couldn't create workspace worker for ${workspace}, reason: `, err)
|
||||||
throw err
|
throw err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,22 +0,0 @@
|
|||||||
//
|
|
||||||
// Copyright © 2020, 2021 Anticrm Platform Contributors.
|
|
||||||
// Copyright © 2021 Hardcore Engineering Inc.
|
|
||||||
//
|
|
||||||
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License. You may
|
|
||||||
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
//
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
//
|
|
||||||
|
|
||||||
import { encode as jwtEncode, decode as jwtDecode } from 'jwt-simple'
|
|
||||||
|
|
||||||
import config from './config'
|
|
||||||
|
|
||||||
export const encode = (data: any): string => jwtEncode(data, config.Secret)
|
|
||||||
export const decode = (data: string): any => jwtDecode(data, config.Secret)
|
|
@ -16,11 +16,11 @@
|
|||||||
|
|
||||||
import { setMetadata } from '@hcengineering/platform'
|
import { setMetadata } from '@hcengineering/platform'
|
||||||
import serverClient from '@hcengineering/server-client'
|
import serverClient from '@hcengineering/server-client'
|
||||||
|
import serverToken, { decodeToken } from '@hcengineering/server-token'
|
||||||
import { type IncomingHttpHeaders } from 'http'
|
import { type IncomingHttpHeaders } from 'http'
|
||||||
import { decode64 } from './base64'
|
import { decode64 } from './base64'
|
||||||
import config from './config'
|
import config from './config'
|
||||||
import { GmailController } from './gmailController'
|
import { GmailController } from './gmailController'
|
||||||
import { decode } from './jwt'
|
|
||||||
import { createServer, listen } from './server'
|
import { createServer, listen } from './server'
|
||||||
import { closeDB, getDB } from './storage'
|
import { closeDB, getDB } from './storage'
|
||||||
import { type Endpoint, type State } from './types'
|
import { type Endpoint, type State } from './types'
|
||||||
@ -36,6 +36,7 @@ const extractToken = (header: IncomingHttpHeaders): any => {
|
|||||||
export const main = async (): Promise<void> => {
|
export const main = async (): Promise<void> => {
|
||||||
setMetadata(serverClient.metadata.Endpoint, config.AccountsURL)
|
setMetadata(serverClient.metadata.Endpoint, config.AccountsURL)
|
||||||
setMetadata(serverClient.metadata.UserAgent, config.ServiceID)
|
setMetadata(serverClient.metadata.UserAgent, config.ServiceID)
|
||||||
|
setMetadata(serverToken.metadata.Secret, config.Secret)
|
||||||
const db = await getDB()
|
const db = await getDB()
|
||||||
const gmailController = GmailController.getGmailController(db)
|
const gmailController = GmailController.getGmailController(db)
|
||||||
await gmailController.startAll()
|
await gmailController.startAll()
|
||||||
@ -53,8 +54,8 @@ export const main = async (): Promise<void> => {
|
|||||||
}
|
}
|
||||||
const redirectURL = req.query.redirectURL as string
|
const redirectURL = req.query.redirectURL as string
|
||||||
|
|
||||||
const { email, workspace } = decode(token)
|
const { email, workspace } = decodeToken(token)
|
||||||
const gmail = await gmailController.getGmailClient(email, workspace, token)
|
const gmail = await gmailController.getGmailClient(email, workspace.name, token)
|
||||||
const url = gmail.getAutUrl(redirectURL)
|
const url = gmail.getAutUrl(redirectURL)
|
||||||
res.send(url)
|
res.send(url)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@ -86,8 +87,8 @@ export const main = async (): Promise<void> => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const { email, workspace } = decode(token)
|
const { email, workspace } = decodeToken(token)
|
||||||
await gmailController.signout(workspace, email)
|
await gmailController.signout(workspace.name, email)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log('signout error', JSON.stringify(err))
|
console.log('signout error', JSON.stringify(err))
|
||||||
}
|
}
|
||||||
|
@ -28,12 +28,12 @@ import core, {
|
|||||||
type TxUpdateDoc
|
type TxUpdateDoc
|
||||||
} from '@hcengineering/core'
|
} from '@hcengineering/core'
|
||||||
import gmailP, { type NewMessage } from '@hcengineering/gmail'
|
import gmailP, { type NewMessage } from '@hcengineering/gmail'
|
||||||
|
import { generateToken } from '@hcengineering/server-token'
|
||||||
import { type Db } from 'mongodb'
|
import { type Db } from 'mongodb'
|
||||||
import { getClient } from './client'
|
import { getClient } from './client'
|
||||||
import config from './config'
|
import config from './config'
|
||||||
import { GmailClient } from './gmail'
|
import { GmailClient } from './gmail'
|
||||||
import { encode } from './jwt'
|
import { type Channel, type ProjectCredentials, type User } from './types'
|
||||||
import { type ProjectCredentials, type User, type Channel } from './types'
|
|
||||||
|
|
||||||
export class WorkspaceClient {
|
export class WorkspaceClient {
|
||||||
private messageSubscribed: boolean = false
|
private messageSubscribed: boolean = false
|
||||||
@ -106,10 +106,8 @@ export class WorkspaceClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async initClient (workspace: string): Promise<Client> {
|
private async initClient (workspace: string): Promise<Client> {
|
||||||
const token = encode({
|
const token = generateToken(config.SystemEmail, { name: workspace, productId: '' })
|
||||||
email: config.SystemEmail,
|
console.log('token', token, workspace)
|
||||||
workspace
|
|
||||||
})
|
|
||||||
const client = await getClient(token)
|
const client = await getClient(token)
|
||||||
client.notify = (...tx: Tx[]) => {
|
client.notify = (...tx: Tx[]) => {
|
||||||
void this.txHandler(...tx)
|
void this.txHandler(...tx)
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
"_phase:docker-staging": "rushx docker:staging",
|
"_phase:docker-staging": "rushx docker:staging",
|
||||||
"bundle": "mkdir -p bundle && esbuild src/index.ts --bundle --platform=node > bundle/bundle.js",
|
"bundle": "mkdir -p bundle && esbuild src/index.ts --bundle --platform=node > bundle/bundle.js",
|
||||||
"docker:build": "../../common/scripts/docker_build.sh hardcoreeng/love .",
|
"docker:build": "../../common/scripts/docker_build.sh hardcoreeng/love .",
|
||||||
|
"docker:tbuild": "docker build -t hardcoreeng/love . --platform=linux/amd64 && ../../common/scripts/docker_tag_push.sh hardcoreeng/love",
|
||||||
"docker:staging": "../../common/scripts/docker_tag.sh hardcoreeng/love staging",
|
"docker:staging": "../../common/scripts/docker_tag.sh hardcoreeng/love staging",
|
||||||
"docker:push": "../../common/scripts/docker_tag.sh hardcoreeng/love",
|
"docker:push": "../../common/scripts/docker_tag.sh hardcoreeng/love",
|
||||||
"run-local": "cross-env ts-node src/index.ts",
|
"run-local": "cross-env ts-node src/index.ts",
|
||||||
@ -62,6 +63,7 @@
|
|||||||
"@hcengineering/client-resources": "^0.6.27",
|
"@hcengineering/client-resources": "^0.6.27",
|
||||||
"@hcengineering/platform": "^0.6.11",
|
"@hcengineering/platform": "^0.6.11",
|
||||||
"@hcengineering/server-client": "^0.6.0",
|
"@hcengineering/server-client": "^0.6.0",
|
||||||
|
"@hcengineering/server-token": "^0.6.11",
|
||||||
"ws": "^8.18.0",
|
"ws": "^8.18.0",
|
||||||
"livekit-server-sdk": "^2.0.10",
|
"livekit-server-sdk": "^2.0.10",
|
||||||
"jwt-simple": "^0.5.6",
|
"jwt-simple": "^0.5.6",
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
//
|
|
||||||
// Copyright © 2023 Hardcore Engineering Inc.
|
|
||||||
//
|
|
||||||
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License. You may
|
|
||||||
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
//
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
//
|
|
||||||
|
|
||||||
import { encode as jwtEncode, decode as jwtDecode } from 'jwt-simple'
|
|
||||||
|
|
||||||
import config from './config'
|
|
||||||
|
|
||||||
export const encode = (data: any): string => jwtEncode(data, config.Secret)
|
|
||||||
export const decode = (data: string): any => jwtDecode(data, config.Secret)
|
|
@ -13,11 +13,12 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
//
|
//
|
||||||
|
|
||||||
import { MeasureMetricsContext, WorkspaceId, getWorkspaceId, newMetrics, toWorkspaceString } from '@hcengineering/core'
|
import { MeasureMetricsContext, WorkspaceId, newMetrics, toWorkspaceString } from '@hcengineering/core'
|
||||||
import { setMetadata } from '@hcengineering/platform'
|
import { setMetadata } from '@hcengineering/platform'
|
||||||
import serverClient from '@hcengineering/server-client'
|
import serverClient from '@hcengineering/server-client'
|
||||||
import { StorageConfig, StorageConfiguration } from '@hcengineering/server-core'
|
import { StorageConfig, StorageConfiguration } from '@hcengineering/server-core'
|
||||||
import { buildStorageFromConfig, storageConfigFromEnv } from '@hcengineering/server-storage'
|
import { buildStorageFromConfig, storageConfigFromEnv } from '@hcengineering/server-storage'
|
||||||
|
import serverToken, { decodeToken } from '@hcengineering/server-token'
|
||||||
import cors from 'cors'
|
import cors from 'cors'
|
||||||
import express from 'express'
|
import express from 'express'
|
||||||
import { IncomingHttpHeaders } from 'http'
|
import { IncomingHttpHeaders } from 'http'
|
||||||
@ -32,7 +33,6 @@ import {
|
|||||||
} from 'livekit-server-sdk'
|
} from 'livekit-server-sdk'
|
||||||
import { v4 as uuid } from 'uuid'
|
import { v4 as uuid } from 'uuid'
|
||||||
import config from './config'
|
import config from './config'
|
||||||
import { decode } from './jwt'
|
|
||||||
import { WorkspaceClient } from './workspaceClient'
|
import { WorkspaceClient } from './workspaceClient'
|
||||||
|
|
||||||
const extractToken = (header: IncomingHttpHeaders): any => {
|
const extractToken = (header: IncomingHttpHeaders): any => {
|
||||||
@ -46,6 +46,7 @@ const extractToken = (header: IncomingHttpHeaders): any => {
|
|||||||
export const main = async (): Promise<void> => {
|
export const main = async (): Promise<void> => {
|
||||||
setMetadata(serverClient.metadata.Endpoint, config.AccountsURL)
|
setMetadata(serverClient.metadata.Endpoint, config.AccountsURL)
|
||||||
setMetadata(serverClient.metadata.UserAgent, config.ServiceID)
|
setMetadata(serverClient.metadata.UserAgent, config.ServiceID)
|
||||||
|
setMetadata(serverToken.metadata.Secret, config.Secret)
|
||||||
|
|
||||||
const storageConfigs: StorageConfiguration = storageConfigFromEnv()
|
const storageConfigs: StorageConfiguration = storageConfigFromEnv()
|
||||||
const ctx = new MeasureMetricsContext('love', {}, {}, newMetrics())
|
const ctx = new MeasureMetricsContext('love', {}, {}, newMetrics())
|
||||||
@ -120,14 +121,13 @@ export const main = async (): Promise<void> => {
|
|||||||
|
|
||||||
const roomName = req.body.roomName
|
const roomName = req.body.roomName
|
||||||
const room = req.body.room
|
const room = req.body.room
|
||||||
const { workspace, productId } = decode(token)
|
const { workspace } = decodeToken(token)
|
||||||
const workspaceId = getWorkspaceId(workspace, productId)
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const dateStr = new Date().toISOString().replace('T', '_').slice(0, 19)
|
const dateStr = new Date().toISOString().replace('T', '_').slice(0, 19)
|
||||||
const name = `${room}_${dateStr}.mp4`
|
const name = `${room}_${dateStr}.mp4`
|
||||||
const id = await startRecord(storageConfig, egressClient, roomClient, roomName, workspaceId)
|
const id = await startRecord(storageConfig, egressClient, roomClient, roomName, workspace)
|
||||||
dataByUUID.set(id, { name, workspace, workspaceId })
|
dataByUUID.set(id, { name, workspace: workspace.name, workspaceId: workspace })
|
||||||
res.send()
|
res.send()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
@ -144,7 +144,7 @@ export const main = async (): Promise<void> => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
// just check token
|
// just check token
|
||||||
decode(token)
|
decodeToken(token)
|
||||||
await roomClient.updateRoomMetadata(req.body.roomName, JSON.stringify({ recording: false }))
|
await roomClient.updateRoomMetadata(req.body.roomName, JSON.stringify({ recording: false }))
|
||||||
void stopEgress(egressClient, req.body.roomName)
|
void stopEgress(egressClient, req.body.roomName)
|
||||||
res.send()
|
res.send()
|
||||||
|
@ -15,9 +15,9 @@
|
|||||||
import core, { Client, Ref, TxOperations, type Blob } from '@hcengineering/core'
|
import core, { Client, Ref, TxOperations, type Blob } from '@hcengineering/core'
|
||||||
import drive, { createFile } from '@hcengineering/drive'
|
import drive, { createFile } from '@hcengineering/drive'
|
||||||
import love from '@hcengineering/love'
|
import love from '@hcengineering/love'
|
||||||
|
import { generateToken } from '@hcengineering/server-token'
|
||||||
import { getClient } from './client'
|
import { getClient } from './client'
|
||||||
import config from './config'
|
import config from './config'
|
||||||
import { encode } from './jwt'
|
|
||||||
|
|
||||||
export class WorkspaceClient {
|
export class WorkspaceClient {
|
||||||
private client!: TxOperations
|
private client!: TxOperations
|
||||||
@ -35,10 +35,7 @@ export class WorkspaceClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async initClient (workspace: string): Promise<Client> {
|
private async initClient (workspace: string): Promise<Client> {
|
||||||
const token = encode({
|
const token = generateToken(config.SystemEmail, { name: workspace, productId: '' })
|
||||||
email: config.SystemEmail,
|
|
||||||
workspace
|
|
||||||
})
|
|
||||||
const client = await getClient(token)
|
const client = await getClient(token)
|
||||||
this.client = new TxOperations(client, core.account.System)
|
this.client = new TxOperations(client, core.account.System)
|
||||||
return this.client
|
return this.client
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
"_phase:docker-staging": "rushx docker:staging",
|
"_phase:docker-staging": "rushx docker:staging",
|
||||||
"bundle": "mkdir -p bundle && esbuild src/index.ts --bundle --platform=node --keep-names > bundle/bundle.js",
|
"bundle": "mkdir -p bundle && esbuild src/index.ts --bundle --platform=node --keep-names > bundle/bundle.js",
|
||||||
"docker:build": "cross-env DOCKER_EXTRA=--platform=linux/amd64 ../../../common/scripts/docker_build.sh hardcoreeng/sign",
|
"docker:build": "cross-env DOCKER_EXTRA=--platform=linux/amd64 ../../../common/scripts/docker_build.sh hardcoreeng/sign",
|
||||||
|
"docker:tbuild": "docker build -t hardcoreeng/sign . --platform=linux/amd64 && ../../../common/scripts/docker_tag_push.sh hardcoreeng/sign",
|
||||||
"docker:staging": "../../../common/scripts/docker_tag.sh hardcoreeng/sign staging",
|
"docker:staging": "../../../common/scripts/docker_tag.sh hardcoreeng/sign staging",
|
||||||
"docker:push": "../../../common/scripts/docker_tag.sh hardcoreeng/sign",
|
"docker:push": "../../../common/scripts/docker_tag.sh hardcoreeng/sign",
|
||||||
"run-local": "cross-env ts-node src/index.ts",
|
"run-local": "cross-env ts-node src/index.ts",
|
||||||
|
@ -55,7 +55,7 @@ export class SignController {
|
|||||||
productId: ''
|
productId: ''
|
||||||
})
|
})
|
||||||
const endpoint = await getTransactorEndpoint(token)
|
const endpoint = await getTransactorEndpoint(token)
|
||||||
const connection = await createClient(token, endpoint)
|
const connection = await createClient(endpoint, token)
|
||||||
|
|
||||||
console.log(`Platform client has been created (workspace: ${workspace})`)
|
console.log(`Platform client has been created (workspace: ${workspace})`)
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
"_phase:docker-staging": "rushx docker:staging",
|
"_phase:docker-staging": "rushx docker:staging",
|
||||||
"bundle": "mkdir -p bundle && esbuild src/index.ts --bundle --platform=node > bundle/bundle.js",
|
"bundle": "mkdir -p bundle && esbuild src/index.ts --bundle --platform=node > bundle/bundle.js",
|
||||||
"docker:build": "../../../common/scripts/docker_build.sh hardcoreeng/telegram",
|
"docker:build": "../../../common/scripts/docker_build.sh hardcoreeng/telegram",
|
||||||
|
"docker:tbuild": "docker build -t hardcoreeng/telegram . --platform=linux/amd64 && ../../../common/scripts/docker_tag_push.sh hardcoreeng/telegram",
|
||||||
"docker:staging": "../../../common/scripts/docker_tag.sh hardcoreeng/telegram staging",
|
"docker:staging": "../../../common/scripts/docker_tag.sh hardcoreeng/telegram staging",
|
||||||
"docker:push": "../../../common/scripts/docker_tag.sh hardcoreeng/telegram",
|
"docker:push": "../../../common/scripts/docker_tag.sh hardcoreeng/telegram",
|
||||||
"run-local": "cross-env ts-node src/index.ts",
|
"run-local": "cross-env ts-node src/index.ts",
|
||||||
@ -63,6 +64,7 @@
|
|||||||
"@hcengineering/platform": "^0.6.11",
|
"@hcengineering/platform": "^0.6.11",
|
||||||
"@hcengineering/setting": "^0.6.17",
|
"@hcengineering/setting": "^0.6.17",
|
||||||
"@hcengineering/telegram": "^0.6.21",
|
"@hcengineering/telegram": "^0.6.21",
|
||||||
|
"@hcengineering/server-token": "^0.6.11",
|
||||||
"@hcengineering/server-client": "^0.6.0",
|
"@hcengineering/server-client": "^0.6.0",
|
||||||
"big-integer": "^1.6.51",
|
"big-integer": "^1.6.51",
|
||||||
"dotenv": "~16.0.0",
|
"dotenv": "~16.0.0",
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
import { encode as jwtEncode, decode as jwtDecode } from 'jwt-simple'
|
|
||||||
|
|
||||||
import config from './config'
|
|
||||||
|
|
||||||
export const encode = (data: any): string => jwtEncode(data, config.Secret)
|
|
||||||
export const decode = (data: string): any => jwtDecode(data, config.Secret)
|
|
@ -1,16 +1,16 @@
|
|||||||
import { IncomingHttpHeaders } from 'http'
|
import { IncomingHttpHeaders } from 'http'
|
||||||
import { decode } from './jwt'
|
|
||||||
import { PlatformWorker } from './platform'
|
import { PlatformWorker } from './platform'
|
||||||
import { createServer, Handler, listen } from './server'
|
import { createServer, Handler, listen } from './server'
|
||||||
import { telegram } from './telegram'
|
import { telegram } from './telegram'
|
||||||
|
|
||||||
import { setMetadata } from '@hcengineering/platform'
|
import { setMetadata } from '@hcengineering/platform'
|
||||||
import serverClient from '@hcengineering/server-client'
|
import serverClient from '@hcengineering/server-client'
|
||||||
|
import serverToken, { decodeToken, type Token } from '@hcengineering/server-token'
|
||||||
import config from './config'
|
import config from './config'
|
||||||
|
|
||||||
const extractToken = (header: IncomingHttpHeaders): any => {
|
const extractToken = (header: IncomingHttpHeaders): Token | undefined => {
|
||||||
try {
|
try {
|
||||||
return decode(header.authorization?.slice(7) ?? '')
|
return decodeToken(header.authorization?.slice(7) ?? '')
|
||||||
} catch {
|
} catch {
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
@ -19,6 +19,7 @@ const extractToken = (header: IncomingHttpHeaders): any => {
|
|||||||
export const main = async (): Promise<void> => {
|
export const main = async (): Promise<void> => {
|
||||||
setMetadata(serverClient.metadata.Endpoint, config.AccountsURL)
|
setMetadata(serverClient.metadata.Endpoint, config.AccountsURL)
|
||||||
setMetadata(serverClient.metadata.UserAgent, config.ServiceID)
|
setMetadata(serverClient.metadata.UserAgent, config.ServiceID)
|
||||||
|
setMetadata(serverToken.metadata.Secret, config.Secret)
|
||||||
|
|
||||||
const platformWorker = await PlatformWorker.create()
|
const platformWorker = await PlatformWorker.create()
|
||||||
const endpoints: Array<[string, Handler]> = [
|
const endpoints: Array<[string, Handler]> = [
|
||||||
@ -41,7 +42,7 @@ export const main = async (): Promise<void> => {
|
|||||||
|
|
||||||
const existingRec = await platformWorker.getUserRecord({
|
const existingRec = await platformWorker.getUserRecord({
|
||||||
phone,
|
phone,
|
||||||
workspace
|
workspace: workspace.name
|
||||||
})
|
})
|
||||||
|
|
||||||
if (existingRec !== undefined) {
|
if (existingRec !== undefined) {
|
||||||
@ -79,7 +80,7 @@ export const main = async (): Promise<void> => {
|
|||||||
|
|
||||||
const existingRec = await platformWorker.getUserRecord({
|
const existingRec = await platformWorker.getUserRecord({
|
||||||
phone,
|
phone,
|
||||||
workspace
|
workspace: workspace.name
|
||||||
})
|
})
|
||||||
|
|
||||||
if (existingRec !== undefined) {
|
if (existingRec !== undefined) {
|
||||||
@ -102,7 +103,7 @@ export const main = async (): Promise<void> => {
|
|||||||
if (conn !== undefined) {
|
if (conn !== undefined) {
|
||||||
await platformWorker.addUser({
|
await platformWorker.addUser({
|
||||||
email,
|
email,
|
||||||
workspace,
|
workspace: workspace.name,
|
||||||
phone,
|
phone,
|
||||||
conn
|
conn
|
||||||
})
|
})
|
||||||
@ -134,7 +135,7 @@ export const main = async (): Promise<void> => {
|
|||||||
|
|
||||||
const existingRec = await platformWorker.getUserRecord({
|
const existingRec = await platformWorker.getUserRecord({
|
||||||
phone,
|
phone,
|
||||||
workspace
|
workspace: workspace.name
|
||||||
})
|
})
|
||||||
|
|
||||||
if (existingRec !== undefined) {
|
if (existingRec !== undefined) {
|
||||||
@ -156,7 +157,7 @@ export const main = async (): Promise<void> => {
|
|||||||
if (conn !== undefined) {
|
if (conn !== undefined) {
|
||||||
await platformWorker.addUser({
|
await platformWorker.addUser({
|
||||||
email,
|
email,
|
||||||
workspace,
|
workspace: workspace.name,
|
||||||
phone,
|
phone,
|
||||||
conn
|
conn
|
||||||
})
|
})
|
||||||
@ -177,7 +178,7 @@ export const main = async (): Promise<void> => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const { email, workspace } = token
|
const { email, workspace } = token
|
||||||
await platformWorker.removeUser({ email, workspace })
|
await platformWorker.removeUser({ email, workspace: workspace.name })
|
||||||
|
|
||||||
res.send()
|
res.send()
|
||||||
}
|
}
|
||||||
|
@ -117,7 +117,7 @@ export async function createPlatformClient (token: string): Promise<Client> {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const endpoint = await getTransactorEndpoint(token)
|
const endpoint = await getTransactorEndpoint(token)
|
||||||
const connection = await createClient(token, endpoint)
|
const connection = await createClient(endpoint, token)
|
||||||
|
|
||||||
return connection
|
return connection
|
||||||
}
|
}
|
||||||
|
@ -24,9 +24,9 @@ import core, {
|
|||||||
TxRemoveDoc,
|
TxRemoveDoc,
|
||||||
TxUpdateDoc
|
TxUpdateDoc
|
||||||
} from '@hcengineering/core'
|
} from '@hcengineering/core'
|
||||||
|
import { generateToken } from '@hcengineering/server-token'
|
||||||
import settingP from '@hcengineering/setting'
|
import settingP from '@hcengineering/setting'
|
||||||
import telegramP, { NewTelegramMessage } from '@hcengineering/telegram'
|
import telegramP, { NewTelegramMessage } from '@hcengineering/telegram'
|
||||||
import { encode } from 'jwt-simple'
|
|
||||||
import type { Collection } from 'mongodb'
|
import type { Collection } from 'mongodb'
|
||||||
import fetch from 'node-fetch'
|
import fetch from 'node-fetch'
|
||||||
import { Api } from 'telegram'
|
import { Api } from 'telegram'
|
||||||
@ -155,7 +155,7 @@ export class WorkspaceWorker {
|
|||||||
lastMsgStorage: Collection<LastMsgRecord>,
|
lastMsgStorage: Collection<LastMsgRecord>,
|
||||||
channelsStorage: Collection<WorkspaceChannel>
|
channelsStorage: Collection<WorkspaceChannel>
|
||||||
): Promise<WorkspaceWorker> {
|
): Promise<WorkspaceWorker> {
|
||||||
const token = encode({ email: config.SystemEmail, workspace }, config.Secret)
|
const token = generateToken(config.SystemEmail, { name: workspace, productId: '' })
|
||||||
const client = await createPlatformClient(token)
|
const client = await createPlatformClient(token)
|
||||||
|
|
||||||
const worker = new WorkspaceWorker(client, token, workspace, userStorage, lastMsgStorage, channelsStorage)
|
const worker = new WorkspaceWorker(client, token, workspace, userStorage, lastMsgStorage, channelsStorage)
|
||||||
|
Loading…
Reference in New Issue
Block a user