mirror of
https://github.com/hcengineering/platform.git
synced 2025-05-31 12:49:57 +00:00
initial import file implementation
Signed-off-by: Andrey Platov <andrey@hardcoreeng.com>
This commit is contained in:
parent
2348a54f63
commit
4c33b4b06e
@ -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'))
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user