From 4c33b4b06e8d8edf4d3b124d70962394cc4556c1 Mon Sep 17 00:00:00 2001 From: Andrey Platov Date: Tue, 9 Nov 2021 17:06:52 +0100 Subject: [PATCH] initial import file implementation Signed-off-by: Andrey Platov --- server/front/src/app.ts | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/server/front/src/app.ts b/server/front/src/app.ts index cbf267b6f5..4498eade68 100644 --- a/server/front/src/app.ts +++ b/server/front/src/app.ts @@ -15,6 +15,7 @@ // import { resolve, join } from 'path' +import https from 'https' import express from 'express' import fileUpload, { UploadedFile } from 'express-fileupload' import cors from 'cors' @@ -182,6 +183,37 @@ export function start (transactorEndpoint: string, elasticUrl: string, minio: Cl } }) + app.get('/import', (req, res) => { + const authHeader = req.headers.authorization + if (authHeader === undefined) { + res.status(403).send() + return + } + const token = authHeader.split(' ')[1] + const payload = decode(token ?? '', 'secret', false) as Token + const url = req.query.url as string + + console.log('importing from ', url) + + https.get(url, response => { + console.log('status', response.statusCode) + const id = uuid() + const contentType = response.headers['content-type'] + const meta: ItemBucketMetadata = { + 'Content-Type': contentType + } + minio.putObject(payload.workspace, id, response, 0, meta, (err, objInfo) => { + if (err !== null) { + console.log('minio putObject error', err) + res.status(500).send(err) + } else { + console.log('uploaded uuid', id) + res.status(200).send(id) + } + }) + }) + }) + app.get('*', function (request, response) { response.sendFile(join(dist, 'index.html')) })