initial import file implementation

Signed-off-by: Andrey Platov <andrey@hardcoreeng.com>
This commit is contained in:
Andrey Platov 2021-11-09 17:06:52 +01:00
parent 2348a54f63
commit 4c33b4b06e
No known key found for this signature in database
GPG Key ID: C8787EFEB4B64AF0

View File

@ -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'))
})