From 3979c1acb73a02e009832a68cc73b0789aeffd73 Mon Sep 17 00:00:00 2001 From: Andrey Sobolev Date: Wed, 15 Mar 2023 23:36:50 +0700 Subject: [PATCH] TSK-842: Fix resume recognition functionality (#2736) Signed-off-by: Andrey Sobolev --- dev/docker-compose.yaml | 3 +- dev/prod/.env | 2 +- dev/prod/.env-prod | 4 -- dev/prod/public/config.json | 5 ++- dev/prod/src/platform.ts | 19 ++++++--- packages/rekoni/src/index.ts | 15 +++---- .../src/components/CreateCandidate.svelte | 9 ++--- .../src/components/NewCandidateHeader.svelte | 1 + .../src/components/NewIssueHeader.svelte | 1 - products/tracker/src/platform.ts | 1 - server/front/kube/front.yml | 2 - server/front/src/__start.ts | 31 ++++++++++++++- server/front/src/index.ts | 8 +++- server/ws/src/server.ts | 39 ++++++++++--------- tests/docker-compose.yaml | 5 ++- tests/prepare.sh | 1 - 16 files changed, 95 insertions(+), 51 deletions(-) diff --git a/dev/docker-compose.yaml b/dev/docker-compose.yaml index ff675b5268..0fd07898b2 100644 --- a/dev/docker-compose.yaml +++ b/dev/docker-compose.yaml @@ -89,7 +89,8 @@ services: - ACCOUNTS_URL=http://localhost:3000 - REKONI_URL=http://localhost:4004 - COLLABORATOR_URL=ws://localhost:3078 - - FRONT_URL=http://front:8080 + - GMAIL_URL=http://localhost:8088 + - TELEGRAM_URL=http://localhost:8086 - UPLOAD_URL=/files - TRANSACTOR_URL=ws://localhost:3333 - ELASTIC_URL=http://elastic:9200 diff --git a/dev/prod/.env b/dev/prod/.env index d84a38f1e3..af9a193c98 100644 --- a/dev/prod/.env +++ b/dev/prod/.env @@ -3,7 +3,7 @@ LOGIN_ENDPOINT=ws://localhost:3333 TELEGRAM_URL=http://localhost:8086 GMAIL_URL=http://localhost:8088 -FRONT_URL=http://front:8080 +FRONT_URL=http://localhost:8080 REKONI_URL=http://localhost:4004 diff --git a/dev/prod/.env-prod b/dev/prod/.env-prod index 6925578a2a..e69de29bb2 100644 --- a/dev/prod/.env-prod +++ b/dev/prod/.env-prod @@ -1,4 +0,0 @@ - -TELEGRAM_URL = https://telegram.hc.engineering -GMAIL_URL = https://gmail.hc.engineering -REKONI_URL = https://rekoni.hc.engineering \ No newline at end of file diff --git a/dev/prod/public/config.json b/dev/prod/public/config.json index 1e971524a3..0955830787 100644 --- a/dev/prod/public/config.json +++ b/dev/prod/public/config.json @@ -2,5 +2,8 @@ "ACCOUNTS_URL":"/account", "COLLABORATOR_URL": "ws://localhost:3078", "UPLOAD_URL":"/files", - "MODEL_VERSION": null + "MODEL_VERSION": null, + "TELEGRAM_URL": "http://localhost:8086", + "GMAIL_URL": "http://localhost:8088", + "REKONI_URL": "http://localhost:4004" } \ No newline at end of file diff --git a/dev/prod/src/platform.ts b/dev/prod/src/platform.ts index 00b533b64f..afd0a17742 100644 --- a/dev/prod/src/platform.ts +++ b/dev/prod/src/platform.ts @@ -80,8 +80,18 @@ import { textEditorId } from '@hcengineering/text-editor' import { setMetadata } from '@hcengineering/platform' +interface Config { + ACCOUNTS_URL: string + UPLOAD_URL: string + MODEL_VERSION: string + COLLABORATOR_URL: string + REKONI_URL: string + TELEGRAM_URL: string + GMAIL_URL: string +} + export async function configurePlatform() { - const config = await (await fetch('/config.json')).json() + const config: Config = await (await fetch('/config.json')).json() console.log('loading configuration', config) setMetadata(login.metadata.AccountsUrl, config.ACCOUNTS_URL) setMetadata(login.metadata.UploadUrl, config.UPLOAD_URL) @@ -92,12 +102,11 @@ export async function configurePlatform() { console.log('Minimal Model version requirement', config.MODEL_VERSION) setMetadata(presentation.metadata.RequiredVersion, config.MODEL_VERSION) } - setMetadata(login.metadata.TelegramUrl, process.env.TELEGRAM_URL ?? 'http://localhost:8086') - setMetadata(login.metadata.GmailUrl, process.env.GMAIL_URL ?? 'http://localhost:8087') + setMetadata(login.metadata.TelegramUrl, config.TELEGRAM_URL ?? 'http://localhost:8086') + setMetadata(login.metadata.GmailUrl, config.GMAIL_URL ?? 'http://localhost:8087') setMetadata(login.metadata.OverrideEndpoint, process.env.LOGIN_ENDPOINT) - setMetadata(login.metadata.FrontUrl, process.env.FRONT_URL) - setMetadata(rekoni.metadata.RekoniUrl, process.env.REKONI_URL) + setMetadata(rekoni.metadata.RekoniUrl, config.REKONI_URL) setMetadata(uiPlugin.metadata.DefaultApplication, login.component.LoginApp) diff --git a/packages/rekoni/src/index.ts b/packages/rekoni/src/index.ts index ebf4163ed0..c997230208 100644 --- a/packages/rekoni/src/index.ts +++ b/packages/rekoni/src/index.ts @@ -24,23 +24,24 @@ export * from './types' /** * @public */ -export async function recognizeDocument (token: string, url: string, contentType: string): Promise { +export async function recognizeDocument (token: string, file: File): Promise { const rekoniUrl = getMetadata(plugin.metadata.RekoniUrl) if (rekoniUrl === undefined) { // We could try use recognition service to find some document properties. throw new PlatformError(unknownError('recognition framework is not configured')) } + const data = new FormData() + data.append('file', file) + data.append('type', file.type) + data.append('name', file.name) + return (await ( await fetch(concatLink(rekoniUrl, '/recognize'), { method: 'POST', headers: { - Authorization: 'Bearer ' + token, - 'Content-Type': 'application/json' + Authorization: 'Bearer ' + token }, - body: JSON.stringify({ - contentType, - fileUrl: url - }) + body: data }) ).json()) as ReconiDocument } diff --git a/plugins/recruit-resources/src/components/CreateCandidate.svelte b/plugins/recruit-resources/src/components/CreateCandidate.svelte index 1e8c5f816c..59385f5fb0 100644 --- a/plugins/recruit-resources/src/components/CreateCandidate.svelte +++ b/plugins/recruit-resources/src/components/CreateCandidate.svelte @@ -37,7 +37,6 @@ createQuery, EditableAvatar, getClient, - getFileUrl, getUserDraft, KeyedAttribute, MessageBox, @@ -348,13 +347,11 @@ } } - async function recognize (contentType: string): Promise { + async function recognize (file: File): Promise { const token = getMetadata(login.metadata.LoginToken) ?? '' - const frontUrl = getMetadata(login.metadata.FrontUrl) ?? '' - const fileUrl = frontUrl + getFileUrl(resume.uuid) try { - const doc = await recognizeDocument(token, fileUrl, contentType) + const doc = await recognizeDocument(token, file) if (isUndef(object.title) && doc.title !== undefined) { object.title = doc.title @@ -462,7 +459,7 @@ resume.type = file.type resume.lastModified = file.lastModified - await recognize(file.type) + await recognize(file) } catch (err: any) { setPlatformStatus(unknownError(err)) } finally { diff --git a/plugins/recruit-resources/src/components/NewCandidateHeader.svelte b/plugins/recruit-resources/src/components/NewCandidateHeader.svelte index bea6f3bb10..46c5bac166 100644 --- a/plugins/recruit-resources/src/components/NewCandidateHeader.svelte +++ b/plugins/recruit-resources/src/components/NewCandidateHeader.svelte @@ -35,6 +35,7 @@ icon={recruit.icon.CreateCandidate} label={draftExists ? recruit.string.ResumeDraft : recruit.string.CreateTalent} justify={'left'} + kind={'primary'} width={'100%'} on:click={newCandidate} > diff --git a/plugins/tracker-resources/src/components/NewIssueHeader.svelte b/plugins/tracker-resources/src/components/NewIssueHeader.svelte index c3a0693b88..bf482fe6ce 100644 --- a/plugins/tracker-resources/src/components/NewIssueHeader.svelte +++ b/plugins/tracker-resources/src/components/NewIssueHeader.svelte @@ -69,7 +69,6 @@ -