From 930a758120aca0fbf462b48918d73a473587dde3 Mon Sep 17 00:00:00 2001 From: Andrey Platov <87076238+aplatoff@users.noreply.github.com> Date: Sat, 28 Aug 2021 12:05:36 +0200 Subject: [PATCH] Upload with contributing client (#79) Signed-off-by: Andrey Platov --- common/config/rush/pnpm-lock.yaml | 156 ++++++++++++++---- dev/prod/webpack.config.js | 3 +- .../src/components/DialogHeader.svelte | 7 +- server/contrib/src/connection.ts | 4 + server/upload/package.json | 8 +- server/upload/src/__start.ts | 14 +- server/upload/src/app.ts | 77 +++++++-- 7 files changed, 219 insertions(+), 50 deletions(-) diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index fdb36a9dec..32695b18bc 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -94,7 +94,6 @@ specifiers: file-loader: ^6.2.0 intl-messageformat: ^9.7.1 mini-css-extract-plugin: ^2.2.0 - mongodb: ^4.1.0 node-html-parser: ^4.1.3 postcss: ^8.3.4 postcss-load-config: ^3.1.0 @@ -113,7 +112,6 @@ specifiers: webpack-bundle-analyzer: ^4.4.1 webpack-cli: ^4.6.0 webpack-dev-server: ^3.11.2 - ws: ^8.0.0 dependencies: '@elastic/elasticsearch': 7.14.0 @@ -209,7 +207,6 @@ dependencies: file-loader: 6.2.0_webpack@5.48.0 intl-messageformat: 9.8.1 mini-css-extract-plugin: 2.2.0_webpack@5.48.0 - mongodb: 4.1.0 node-html-parser: 4.1.3 postcss: 8.3.6 postcss-load-config: 3.1.0 @@ -228,7 +225,6 @@ dependencies: webpack-bundle-analyzer: 4.4.2 webpack-cli: 4.7.2_954feff0479d53ccf5b533f71f40f1af webpack-dev-server: 3.11.2_webpack-cli@4.7.2+webpack@5.48.0 - ws: 8.0.0 packages: @@ -1648,7 +1644,7 @@ packages: /@types/whatwg-url/8.2.1: resolution: {integrity: sha512-2YubE1sjj5ifxievI5Ge1sckb9k/Er66HyR2c+3+I6VDUUg1TLPdYYTEbQ+DjRkS4nTxMJhgWfSfMRD2sl2EYQ==} dependencies: - '@types/node': 16.4.13 + '@types/node': 16.7.1 '@types/webidl-conversions': 6.1.1 dev: false @@ -2196,6 +2192,10 @@ packages: resolution: {integrity: sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ==} dev: false + /async/0.9.2: + resolution: {integrity: sha1-rqdNXmHB+JlhO/ZL2mbUx48v0X0=} + dev: false + /async/2.6.3: resolution: {integrity: sha512-zflvls11DCy+dQWzTW2dzuilv8Z5X/pjfmZOWba6TNIVDm+2UDaJmXSOXlasHKfNBs8oo3M0aT50fDEWfKZjXg==} dependencies: @@ -2468,8 +2468,8 @@ packages: node-int64: 0.4.0 dev: false - /bson/4.4.1: - resolution: {integrity: sha512-Uu4OCZa0jouQJCKOk1EmmyqtdWAP5HVLru4lQxTwzJzxT+sJ13lVpEZU/MATDxtHiekWMAL84oQY3Xn1LpJVSg==} + /bson/4.5.1: + resolution: {integrity: sha512-XqFP74pbTVLyLy5KFxVfTUyRrC1mgOlmu/iXHfXqfCKT59jyP9lwbotGfbN59cHBRbJSamZNkrSopjv+N0SqAA==} engines: {node: '>=6.9.0'} dependencies: buffer: 5.7.1 @@ -2787,6 +2787,13 @@ packages: engines: {node: '>=0.8'} dev: false + /connect-redis/2.5.1: + resolution: {integrity: sha1-6MCF227Gg7T8RXzzP5PD5+1vA/c=} + dependencies: + debug: 1.0.5 + redis: 0.12.1 + dev: false + /content-disposition/0.5.3: resolution: {integrity: sha512-ExO0774ikEObIAEV9kDo50o+79VCUdEB6n6lzKgGwupcVeRlhrj3qGAfwq8G6uBJjkqLrhT0qEYFcWng8z1z0g==} engines: {node: '>= 0.6'} @@ -2814,6 +2821,11 @@ packages: engines: {node: '>= 0.6'} dev: false + /cookie/0.4.1: + resolution: {integrity: sha512-ZwrFkGJxUR3EIoXtO+yVE69Eb7KlixbaeAWfBQB9vVsNn/o+Yw69gBWSSDK825hQNdN+wF8zELf3dFNl/kxkUA==} + engines: {node: '>= 0.6'} + dev: false + /copy-descriptor/0.1.1: resolution: {integrity: sha1-Z29us8OZl8LuGsOpJP1hJHSPV40=} engines: {node: '>=0.10.0'} @@ -2959,6 +2971,12 @@ packages: whatwg-url: 7.1.0 dev: false + /debug/1.0.5: + resolution: {integrity: sha1-9yQSF0MPmd7EwrRz6rkiKOh0wqw=} + dependencies: + ms: 2.0.0 + dev: false + /debug/2.6.9: resolution: {integrity: sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==} dependencies: @@ -3091,6 +3109,11 @@ packages: engines: {node: '>= 0.6'} dev: false + /depd/2.0.0: + resolution: {integrity: sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==} + engines: {node: '>= 0.8'} + dev: false + /destroy/1.0.4: resolution: {integrity: sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=} dev: false @@ -3726,6 +3749,20 @@ packages: busboy: 0.3.1 dev: false + /express-session/1.17.2: + resolution: {integrity: sha512-mPcYcLA0lvh7D4Oqr5aNJFMtBMKPLl++OKKxkHzZ0U0oDq1rpKBnkR5f5vCHR26VeArlTOEF9td4x5IjICksRQ==} + engines: {node: '>= 0.8.0'} + dependencies: + cookie: 0.4.1 + cookie-signature: 1.0.6 + debug: 2.6.9 + depd: 2.0.0 + on-headers: 1.0.2 + parseurl: 1.3.3 + safe-buffer: 5.2.1 + uid-safe: 2.1.5 + dev: false + /express/4.17.1: resolution: {integrity: sha512-mHJ9O79RqluphRrcw2X/GTh3k9tVv8YcoyY4Kkh4WDMUYKRZUq0h1o0w2rrrxBqM7VoeUVqgb27xlEMXTnYt4g==} engines: {node: '>= 0.10.0'} @@ -4120,6 +4157,15 @@ packages: resolution: {integrity: sha512-lkX1HJXwyMcprw/5YUZc2s7DrpAiHB21/V+E1rHUrVNokkvB6bqMzT0VfV6/86ZNabt1k14YOIaT7nDvOX3Iiw==} dev: false + /glob/4.5.3: + resolution: {integrity: sha1-xstz0yJsHv7wTePFbQEvAzd+4V8=} + dependencies: + inflight: 1.0.6 + inherits: 2.0.4 + minimatch: 2.0.10 + once: 1.4.0 + dev: false + /glob/7.0.6: resolution: {integrity: sha1-IRuvr0nlJbjNkyYNFKsTYVKz9Xo=} dependencies: @@ -4796,6 +4842,10 @@ packages: dev: false optional: true + /isarray/0.0.1: + resolution: {integrity: sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=} + dev: false + /isarray/1.0.0: resolution: {integrity: sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=} dev: false @@ -5596,6 +5646,11 @@ packages: resolution: {integrity: sha1-WjUNoLERO4N+z//VgSy+WNbq4ZM=} dev: false + /lodash/2.4.2: + resolution: {integrity: sha1-+t2DS5aDBz2hebPq5tnA0VBT9z4=} + engines: {'0': node, '1': rhino} + dev: false + /lodash/4.17.21: resolution: {integrity: sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==} dev: false @@ -5771,6 +5826,13 @@ packages: resolution: {integrity: sha512-UtJcAD4yEaGtjPezWuO9wC4nwUnVH/8/Im3yEHQP4b67cXlD/Qr9hdITCU1xDbSEXg2XKNaP8jsReV7vQd00/A==} dev: false + /minimatch/2.0.10: + resolution: {integrity: sha1-jQh8OcazjAAbl/ynzm0OHoCvusc=} + deprecated: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue + dependencies: + brace-expansion: 1.1.11 + dev: false + /minimatch/3.0.4: resolution: {integrity: sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==} dependencies: @@ -5796,20 +5858,20 @@ packages: minimist: 1.2.5 dev: false - /mongodb-connection-string-url/1.1.2: - resolution: {integrity: sha512-mp5lv4guWuykOpkwNNqQ0tKKytuJUjL/aC/bu/DqoJVWL5NSh4j/u+gJ+EiOdweLujHyq6JZZqcTVipHhL5xRg==} + /mongodb-connection-string-url/2.0.0: + resolution: {integrity: sha512-M0I1vyLoq5+HQTuPSJWbt+hIXsMCfE8sS1fS5mvP9R2DOMoi2ZD32yWqgBIITyu0dFu4qtS50erxKjvUeBiyog==} dependencies: '@types/whatwg-url': 8.2.1 - whatwg-url: 8.7.0 + whatwg-url: 9.1.0 dev: false - /mongodb/4.1.0: - resolution: {integrity: sha512-Gx9U9MsFWgJ3E0v4oHAdWvYTGBznNYPCkhmD/3i/kPTY/URnPfHD5/6VoKUFrdgQTK3icFiM9976hVbqCRBO9Q==} + /mongodb/4.1.1: + resolution: {integrity: sha512-fbACrWEyvr6yl0sSiCGV0sqEiBwTtDJ8iSojmkDjAfw9JnOZSAkUyv9seFSPYhPPKwxp1PDtyjvBNfMDz0WBLQ==} engines: {node: '>=12.9.0'} dependencies: - bson: 4.4.1 + bson: 4.5.1 denque: 1.5.1 - mongodb-connection-string-url: 1.1.2 + mongodb-connection-string-url: 2.0.0 optionalDependencies: saslprep: 1.0.3 dev: false @@ -6281,6 +6343,12 @@ packages: resolution: {integrity: sha1-32BBeABfUi8V60SQ5yR6G/qmf4w=} dev: false + /path-to-regexp/1.8.0: + resolution: {integrity: sha512-n43JRhlUKUAlibEJhPeir1ncUID16QnEjNpwzNdO3Lm4ywrBpBZ5oLD0I6br9evr1Y9JTqwRtAh7JLoOzAQdVA==} + dependencies: + isarray: 0.0.1 + dev: false + /path-type/3.0.0: resolution: {integrity: sha512-T2ZUsdZFHgA3u4e5PfPbjd7HDDpxPnQb5jN0SrDsjNSuVXHJqtwTnWqG0B1jZrgmJ/7lj1EmVIByWt1gxGkWvg==} engines: {node: '>=4'} @@ -6654,6 +6722,11 @@ packages: resolution: {integrity: sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==} dev: false + /random-bytes/1.0.0: + resolution: {integrity: sha1-T2ih3Arli9P7lYSMMDJNt11kNgs=} + engines: {node: '>= 0.8'} + dev: false + /randombytes/2.1.0: resolution: {integrity: sha512-vYl3iOX+4CKUWuxGi9Ukhie6fsqXqS9FE2Zaic4tNFD2N2QQaXOMFbuKK4QmDHC0JO6B1Zp41J0LpT0oR68amQ==} dependencies: @@ -6768,6 +6841,10 @@ packages: resolve: 1.20.0 dev: false + /redis/0.12.1: + resolution: {integrity: sha1-ZN92rQ/IrOuuvSoGReikj6xJGF4=} + dev: false + /regex-not/1.0.2: resolution: {integrity: sha512-J6SDjUgDxQj5NusnOtdFxDwN/+HWykR8GELwctJ7mdqhcyy1xEc4SRFHUXvxTp661YaVKAjfRLZ9cCqS6tn32A==} engines: {node: '>=0.10.0'} @@ -7155,6 +7232,19 @@ packages: send: 0.17.1 dev: false + /server-core/0.1.0: + resolution: {integrity: sha1-zs3yDCQ6jCu61BSnlWKLyxIIg7Q=} + dependencies: + async: 0.9.2 + connect-redis: 2.5.1 + debug: 2.6.9 + express: 4.17.1 + express-session: 1.17.2 + glob: 4.5.3 + lodash: 2.4.2 + path-to-regexp: 1.8.0 + dev: false + /set-blocking/2.0.0: resolution: {integrity: sha1-BF+XgtARrppoA93TgrJDkrPYkPc=} dev: false @@ -8131,6 +8221,13 @@ packages: hasBin: true dev: false + /uid-safe/2.1.5: + resolution: {integrity: sha512-KPHm4VL5dDXKz01UuEd88Df+KzynaohSL9fBh096KWAxSKZQDI2uBrVqtvRM4rwrIrRRKsdLNML/lnaaVSRioA==} + engines: {node: '>= 0.8'} + dependencies: + random-bytes: 1.0.0 + dev: false + /unbox-primitive/1.0.1: resolution: {integrity: sha512-tZU/3NqK3dA5gpE1KtyiJUrEB0lxnGkMFHptJ7q6ewdZ8s12QrODwNbhIJStmJkd1QDXa1NRA8aF2A1zk/Ypyw==} dependencies: @@ -8531,11 +8628,10 @@ packages: webidl-conversions: 4.0.2 dev: false - /whatwg-url/8.7.0: - resolution: {integrity: sha512-gAojqb/m9Q8a5IV96E3fHJM70AzCkgt4uXYX2O7EmuyOnLrViCQlsEBmF9UQIu3/aeAIp2U17rtbpZWNntQqdg==} - engines: {node: '>=10'} + /whatwg-url/9.1.0: + resolution: {integrity: sha512-CQ0UcrPHyomtlOCot1TL77WyMIm/bCwrJ2D6AOKGwEczU9EpyoqAokfqrf/MioU9kHcMsmJZcg1egXix2KYEsA==} + engines: {node: '>=12'} dependencies: - lodash: 4.17.21 tr46: 2.1.0 webidl-conversions: 6.1.0 dev: false @@ -8651,19 +8747,6 @@ packages: optional: true dev: false - /ws/8.0.0: - resolution: {integrity: sha512-6AcSIXpBlS0QvCVKk+3cWnWElLsA6SzC0lkQ43ciEglgXJXiCWK3/CGFEJ+Ybgp006CMibamAsqOlxE9s4AvYA==} - engines: {node: '>=10.0.0'} - peerDependencies: - bufferutil: ^4.0.1 - utf-8-validate: ^5.0.2 - peerDependenciesMeta: - bufferutil: - optional: true - utf-8-validate: - optional: true - dev: false - /ws/8.2.0: resolution: {integrity: sha512-uYhVJ/m9oXwEI04iIVmgLmugh2qrZihkywG9y5FfZV2ATeLIzHf93qs+tUNqlttbQK957/VX3mtwAS+UfIwA4g==} engines: {node: '>=10.0.0'} @@ -8903,7 +8986,7 @@ packages: dev: false file:projects/contrib.tgz_6c259fadfeb3a4b20890aefe87070b8b: - resolution: {integrity: sha512-TRDsaFqjTSL/z6QaCR7OY5xKYJlr936zX/c4ODZRBDSU3CH4wcpbux4ZW2p5wIbCGdx8r/p2CBjXjOj73xnrgQ==, tarball: file:projects/contrib.tgz} + resolution: {integrity: sha512-wW5bJ11QbwRxQHQ7+8UigQ+iCm1DPGVFVsmRA4F58Wz9a6WpJkD4mLSJbavVRG1MWrppR8psoezBBExtXvo38Q==, tarball: file:projects/contrib.tgz} id: file:projects/contrib.tgz name: '@rush-temp/contrib' version: 0.0.0 @@ -9356,7 +9439,7 @@ packages: eslint-plugin-import: 2.23.4_eslint@7.32.0 eslint-plugin-node: 11.1.0_eslint@7.32.0 eslint-plugin-promise: 4.3.1 - mongodb: 4.1.0 + mongodb: 4.1.1 transitivePeerDependencies: - '@typescript-eslint/parser' - supports-color @@ -9763,7 +9846,7 @@ packages: dev: false file:projects/upload.tgz_6c259fadfeb3a4b20890aefe87070b8b: - resolution: {integrity: sha512-kz9bPnD7xvZFIgoL1y70wmTnDJAXrlwiHksRQWC3pTwRnhClbQd2Vd4ecrwG+mOUrvDjKtSIgjfggTwejC2DHA==, tarball: file:projects/upload.tgz} + resolution: {integrity: sha512-StYlClUVsoxqeaYRM3BKSCnt2vfYSyxBobnnihP5f/6qVCazJTeCEDjZhYOOPNzJqQt+Z8iO63ajYuIV2c+1IA==, tarball: file:projects/upload.tgz} id: file:projects/upload.tgz name: '@rush-temp/upload' version: 0.0.0 @@ -9784,6 +9867,9 @@ packages: eslint-plugin-promise: 4.3.1 express: 4.17.1 express-fileupload: 1.2.1 + jwt-simple: 0.5.6 + mongodb: 4.1.1 + server-core: 0.1.0 ts-node: 10.2.1_f50b86b1778cd2aa4e5405c08bb39559 uuid: 8.3.2 transitivePeerDependencies: @@ -9895,7 +9981,7 @@ packages: eslint-plugin-import: 2.23.4_eslint@7.32.0 eslint-plugin-node: 11.1.0_eslint@7.32.0 eslint-plugin-promise: 4.3.1 - mongodb: 4.1.0 + mongodb: 4.1.1 ts-node: 10.2.1_typescript@4.3.5 transitivePeerDependencies: - '@swc/core' diff --git a/dev/prod/webpack.config.js b/dev/prod/webpack.config.js index ec4ee7f74a..d5e432e493 100644 --- a/dev/prod/webpack.config.js +++ b/dev/prod/webpack.config.js @@ -168,7 +168,8 @@ module.exports = { logLevel: 'debug' }, '/upload': { - target: 'https://anticrm-upload.herokuapp.com/', + // target: 'https://anticrm-upload.herokuapp.com/', + target: 'http://localhost:3000/', changeOrigin: true, pathRewrite: { '^/upload': '' }, logLevel: 'debug' diff --git a/plugins/recruit-resources/src/components/DialogHeader.svelte b/plugins/recruit-resources/src/components/DialogHeader.svelte index 37b0ff7e60..0dca7f4583 100644 --- a/plugins/recruit-resources/src/components/DialogHeader.svelte +++ b/plugins/recruit-resources/src/components/DialogHeader.svelte @@ -32,9 +32,14 @@ if (droppedFile !== undefined && uploadUrl !== undefined) { const data = new FormData() data.append('file', droppedFile) + + const url = `${uploadUrl}?collection=resume&name=${droppedFile.name}` - fetch(uploadUrl, { + fetch(url, { method: 'POST', + headers: { + 'Authorization': 'Bearer ' + getMetadata(login.metadata.LoginToken) + }, body: data }) .then(resonse => { console.log(resonse) }) diff --git a/server/contrib/src/connection.ts b/server/contrib/src/connection.ts index 6814d1e52c..0aa86aa3e7 100644 --- a/server/contrib/src/connection.ts +++ b/server/contrib/src/connection.ts @@ -31,6 +31,10 @@ export class ContributingClient implements WithTx { params: [tx] })) } + + close (): void { + this.websocket.close() + } } /** diff --git a/server/upload/package.json b/server/upload/package.json index 12c0822c74..94566af27c 100644 --- a/server/upload/package.json +++ b/server/upload/package.json @@ -31,6 +31,12 @@ "express-fileupload":"^1.2.1", "aws-sdk":"^2.969.0", "uuid":"^8.3.2", - "cors":"^2.8.5" + "cors":"^2.8.5", + "@anticrm/elastic":"~0.6.0", + "jwt-simple":"^0.5.6", + "@anticrm/server-core":"~0.6.1", + "@anticrm/chunter":"~0.6.0", + "@anticrm/core":"~0.6.11", + "@anticrm/contrib":"~0.6.0" } } diff --git a/server/upload/src/__start.ts b/server/upload/src/__start.ts index c479117014..9c5544de8a 100644 --- a/server/upload/src/__start.ts +++ b/server/upload/src/__start.ts @@ -16,4 +16,16 @@ import { start } from './app' -start(3000) +const url = process.env.TRANSACTOR_URL +if (url === undefined) { + console.error('please provide transactor url') + process.exit(1) +} + +const elasticUrl = process.env.ELASTIC_URL +if (elasticUrl === undefined) { + console.error('please provide elastic url') + process.exit(1) +} + +start(url, elasticUrl, 3000) diff --git a/server/upload/src/app.ts b/server/upload/src/app.ts index d5195951ea..79f780ded9 100644 --- a/server/upload/src/app.ts +++ b/server/upload/src/app.ts @@ -19,42 +19,97 @@ import fileUpload, { UploadedFile } from 'express-fileupload' import cors from 'cors' import { S3 } from 'aws-sdk' import { v4 as uuid } from 'uuid' +// import { decode } from 'jwt-simple' + +import type { Space, Ref, Account, Doc } from '@anticrm/core' +import { TxFactory } from '@anticrm/core' +// import type { Token } from '@anticrm/server-core' +import chunter from '@anticrm/chunter' +import { createContributingClient } from '@anticrm/contrib' + +// import { createElasticAdapter } from '@anticrm/elastic' const BUCKET = 'anticrm-upload-9e4e89c' -async function awsUpload (file: UploadedFile): Promise { - console.log(file) +async function awsUpload (file: UploadedFile): Promise { + const id = uuid() const s3 = new S3() const resp = await s3.upload({ Bucket: BUCKET, - Key: uuid(), + Key: id, Body: file.data, ContentType: file.mimetype, ACL: 'public-read' }).promise() console.log(resp) - return resp + return id +} + +async function createAttachment (endpoint: string, token: string, account: Ref, space: Ref, attachmentTo: Ref, collection: string, name: string, file: string): Promise { + const txFactory = new TxFactory(account) + const tx = txFactory.createTxCreateDoc(chunter.class.Attachment, space, { + attachmentTo, + collection, + name, + file + }) + const url = new URL(`/${token}`, endpoint) + const client = await createContributingClient(url.href) + await client.tx(tx) + client.close() } /** * @public * @param port - */ -export function start (port: number): void { +export function start (transactorEndpoint: string, elasticUrl: string, port: number): void { const app = express() app.use(cors()) app.use(fileUpload()) - app.post('/', (req, res) => { + // eslint-disable-next-line @typescript-eslint/no-misused-promises + app.post('/', async (req, res) => { const file = req.files?.file - if (file !== undefined) { - awsUpload(file as UploadedFile) - .then(() => res.status(200).send()) - .catch(error => console.log(error)) - } else { + if (file === undefined) { res.status(400).send() + return + } + + const authHeader = req.headers.authorization + if (authHeader === undefined) { + res.status(403).send() + return + } + + try { + const token = authHeader.split(' ')[1] + // const payload = decode(token ?? '', 'secret', false) as Token + const fileId = await awsUpload(file as UploadedFile) + + const space = req.query.space as Ref + const attachmentTo = req.query.attachmentTo as Ref + const name = req.query.name as string + const collection = req.query.collection as string + console.log('name', name) + + await createAttachment( + transactorEndpoint, + token, + 'core:account:System' as Ref, + space, + attachmentTo, + collection, + name, + fileId + ) + + res.status(200).send() + } catch (error) { + console.log(error) + res.status(500).send() } })