mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-30 13:35:04 +02:00
UBERF-12153 Update communication blob metadata (#9539)
Signed-off-by: Alexander Onnikov <Alexander.Onnikov@xored.com>
This commit is contained in:
@@ -20,11 +20,15 @@ import {
|
||||
concatLink,
|
||||
type Doc,
|
||||
type DocumentQuery,
|
||||
type DomainParams,
|
||||
type DomainRequestOptions,
|
||||
type DomainResult,
|
||||
type FindOptions,
|
||||
type FindResult,
|
||||
Hierarchy,
|
||||
MeasureMetricsContext,
|
||||
ModelDb,
|
||||
OperationDomain,
|
||||
PersonId,
|
||||
PersonUuid,
|
||||
type Ref,
|
||||
@@ -301,6 +305,31 @@ export class RestClientImpl implements RestClient {
|
||||
return result
|
||||
}
|
||||
|
||||
async domainRequest<T>(
|
||||
domain: OperationDomain,
|
||||
params: DomainParams,
|
||||
options?: DomainRequestOptions
|
||||
): Promise<DomainResult<T>> {
|
||||
const requestUrl = concatLink(this.endpoint, `/api/v1/request/${domain}/${this.workspace}`)
|
||||
|
||||
await this.checkRate()
|
||||
return await withRetry(async () => {
|
||||
const response = await fetch(requestUrl, {
|
||||
method: 'POST',
|
||||
headers: this.jsonHeaders(),
|
||||
keepalive: true,
|
||||
body: JSON.stringify(params)
|
||||
})
|
||||
if (!response.ok) {
|
||||
await this.checkRateLimits(response)
|
||||
throw new PlatformError(unknownError(response.statusText))
|
||||
}
|
||||
this.updateRateLimit(response)
|
||||
const value = await extractJson<T>(response)
|
||||
return { domain, value }
|
||||
}, isRLE)
|
||||
}
|
||||
|
||||
async ensurePerson (
|
||||
socialType: SocialIdType,
|
||||
socialValue: string,
|
||||
|
||||
@@ -14,18 +14,22 @@
|
||||
//
|
||||
|
||||
import {
|
||||
PersonId,
|
||||
PersonUuid,
|
||||
SocialIdType,
|
||||
type Account,
|
||||
type Class,
|
||||
type Doc,
|
||||
type DocumentQuery,
|
||||
type DomainParams,
|
||||
type DomainRequestOptions,
|
||||
type DomainResult,
|
||||
type FindOptions,
|
||||
type FulltextStorage,
|
||||
type Hierarchy,
|
||||
type ModelDb,
|
||||
type OperationDomain,
|
||||
type PersonId,
|
||||
type PersonUuid,
|
||||
type Ref,
|
||||
type SocialIdType,
|
||||
type Storage,
|
||||
type WithLookup
|
||||
} from '@hcengineering/core'
|
||||
@@ -40,6 +44,13 @@ export interface RestClient extends Storage, FulltextStorage {
|
||||
) => Promise<WithLookup<T> | undefined>
|
||||
|
||||
getModel: () => Promise<{ hierarchy: Hierarchy, model: ModelDb }>
|
||||
|
||||
domainRequest: <T>(
|
||||
domain: OperationDomain,
|
||||
params: DomainParams,
|
||||
options?: DomainRequestOptions
|
||||
) => Promise<DomainResult<T>>
|
||||
|
||||
ensurePerson: (
|
||||
socialType: SocialIdType,
|
||||
socialValue: string,
|
||||
|
||||
@@ -44,6 +44,7 @@ import core, {
|
||||
import { type RestClient, createRestClient } from '@hcengineering/api-client'
|
||||
import { getTransactorEndpoint } from '@hcengineering/server-client'
|
||||
import { generateToken } from '@hcengineering/server-token'
|
||||
import { MessageEventType } from '@hcengineering/communication-sdk-types'
|
||||
|
||||
import { BlobSourceType, type VideoTranscodeResult } from './types'
|
||||
|
||||
@@ -121,6 +122,32 @@ export class WorkspaceClient {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async updateCommMetadata (ctx: MeasureContext, result: VideoTranscodeResult, metadata: BlobMetadata): Promise<void> {
|
||||
if (result.source.source !== BlobSourceType.Message) {
|
||||
return
|
||||
}
|
||||
|
||||
const txOps = new TxOperations(this.client, core.account.System)
|
||||
await txOps.domainRequest('communication' as OperationDomain, {
|
||||
event: {
|
||||
type: MessageEventType.BlobPatch,
|
||||
cardId: result.source.cardId,
|
||||
messageId: result.source.messageId,
|
||||
operations: [
|
||||
{
|
||||
opcode: 'update',
|
||||
blobs: [
|
||||
{
|
||||
blobId: result.blobId,
|
||||
metadata
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function toHttpUrl (url: string): string {
|
||||
@@ -139,7 +166,7 @@ class RestClientAdapter implements Client {
|
||||
params: DomainParams,
|
||||
options?: DomainRequestOptions
|
||||
): Promise<DomainResult<T>> {
|
||||
throw new Error('Domain request operation not supported')
|
||||
return await this.client.domainRequest(domain, params, options)
|
||||
}
|
||||
|
||||
async findAll<T extends Doc>(
|
||||
|
||||
@@ -129,8 +129,11 @@ export async function handleTranscodeResult (
|
||||
}
|
||||
}
|
||||
|
||||
const client = await WorkspaceClient.create(workspaceUuid)
|
||||
|
||||
if (msg.source !== undefined && msg.source.source === BlobSourceType.Doc) {
|
||||
const client = await WorkspaceClient.create(workspaceUuid)
|
||||
await client.updateBlobMetadata(ctx, msg, metadata)
|
||||
} else if (msg.source !== undefined && msg.source.source === BlobSourceType.Message) {
|
||||
await client.updateCommMetadata(ctx, msg, metadata)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -345,6 +345,15 @@ export function registerRPC (app: Express, sessions: SessionManager, ctx: Measur
|
||||
})
|
||||
})
|
||||
|
||||
app.post('/api/v1/request/:domain/:workspaceId', (req, res) => {
|
||||
void withSession(req, res, async (ctx, session) => {
|
||||
const domain = req.params.domain as OperationDomain
|
||||
const params = retrieveJson(req)
|
||||
const { result } = await session.domainRequestRaw(ctx, domain, params)
|
||||
await sendJson(req, res, result.value)
|
||||
})
|
||||
})
|
||||
|
||||
app.post('/api/v1/ensure-person/:workspaceId', (req, res) => {
|
||||
void withSession(req, res, async (ctx, session, rateLimit, token) => {
|
||||
const { socialType, socialValue, firstName, lastName } = (await retrieveJson(req)) ?? {}
|
||||
|
||||
Reference in New Issue
Block a user