Commit 2f445243 authored by A. Koch's avatar A. Koch

fix minio config parsing when external env vars are set

parent 0303046a
Pipeline #1241 passed with stage
......@@ -8,7 +8,10 @@ class Downloads extends TinyEmitter {
super()
const _this = this
this.minioClient = new Minio.Client(config.assets.client)
const opts = Object.assign({}, config.assets.client)
opts.secure = config.assets.client.secure && (config.assets.client.secure === true || config.assets.client.secure === 'true')
opts.port = config.assets.client.port ? parseInt(config.assets.client.port) : undefined
const minioClient = new Minio.Client(opts)
api.app.get('/downloads/:file', async (req, res) => {
const stream = await _this.minioClient.getObject(config.assets.bucket, req.params.file)
......
......@@ -14,7 +14,10 @@ class Timecodes extends TinyEmitter {
this._queue = new Queue('timecode', config.timecode.redisURL)
this._queue.process(parseInt(config.timecode.concurrency), require('./workers/extract-ltc'))
this._minio = new Minio.Client(config.assets.client)
const opts = Object.assign({}, config.assets.client)
opts.secure = config.assets.client.secure && (config.assets.client.secure === true || config.assets.client.secure === 'true')
opts.port = config.assets.client.port ? parseInt(config.assets.client.port) : undefined
this._minio = new Minio.Client(opts)
const _this = this
......@@ -30,8 +33,10 @@ class Timecodes extends TinyEmitter {
stream.on('data', obj => files.push(obj.name))
stream.on('error', err => _this._errorResponse(res, 500, err.message))
stream.on('end', () => {
let assetHost = `${config.assets.client.secure ? 'https://' : 'http://'}${config.assets.client.endPoint}`
if (config.assets.client.port !== 80 && config.assets.client.port !== 443) assetHost += `:${config.assets.client.port}`
let port = config.assets.client.port ? parseInt(config.assets.client.port) : undefined
let secure = config.assets.client.secure && (config.assets.client.secure === true || config.assets.client.secure === 'true')
let assetHost = `${secure ? 'https://' : 'http://'}${config.assets.client.endPoint}`
if (port !== 80 && port !== 443) assetHost += `:${port}`
assetHost += '/ltc'
_this._response(req, res, files.map(file => {
return `${assetHost}/${file}`
......
......@@ -19,12 +19,17 @@ class Uploads extends TinyEmitter {
upload.single('file')(req, res, async () => {
const extname = path.extname(req.file.originalname)
const filename = `${ObjectUtil.uuid4()}${extname.toLowerCase()}`
const minioClient = new Minio.Client(config.assets.client)
const opts = Object.assign({}, config.assets.client)
opts.secure = config.assets.client.secure && (config.assets.client.secure === true || config.assets.client.secure === 'true')
opts.port = config.assets.client.port ? parseInt(config.assets.client.port) : undefined
const minioClient = new Minio.Client(opts)
await minioClient.fPutObject(config.assets.bucket, filename, req.file.path, { 'Content-Type': req.file.mimetype })
let assetHost = `${config.assets.client.secure ? 'https://' : 'http://'}${config.assets.client.endPoint}`
if (config.assets.client.port !== 80 && config.assets.client.port !== 443) assetHost += `:${config.assets.client.port}`
let port = config.assets.client.port ? parseInt(config.assets.client.port) : undefined
let secure = config.assets.client.secure && (config.assets.client.secure === true || config.assets.client.secure === 'true')
let assetHost = `${secure ? 'https://' : 'http://'}${config.assets.client.endPoint}`
if (port !== 80 && port !== 443) assetHost += `:${port}`
assetHost += `/${config.assets.bucket}`
_this._response(req, res, {
......@@ -35,7 +40,10 @@ class Uploads extends TinyEmitter {
})
api.app.delete('/uploads/:file', async (req, res) => {
const minioClient = new Minio.Client(config.assets.client)
const opts = Object.assign({}, config.assets.client)
opts.secure = config.assets.client.secure && (config.assets.client.secure === true || config.assets.client.secure === 'true')
opts.port = config.assets.client.port ? parseInt(config.assets.client.port) : undefined
const minioClient = new Minio.Client(opts)
await minioClient.removeObject(config.assets.bucket, req.params.file)
_this._response(req, res)
})
......
......@@ -59,7 +59,10 @@ const concatJob = async function (job) {
if (!errored) {
try {
const minioClient = new Minio.Client(config.assets.client)
const opts = Object.assign({}, config.assets.client)
opts.secure = config.assets.client.secure && (config.assets.client.secure === true || config.assets.client.secure === 'true')
opts.port = config.assets.client.port ? parseInt(config.assets.client.port) : undefined
const minioClient = new Minio.Client(opts)
await minioClient.fPutObject(config.assets.bucket, destFile, destination, {'Content-Type': 'video/mp4'})
await minioClient.fPutObject(config.assets.bucket, thumbFile, thumbPath, {'Content-Type': 'image/jpeg'})
await minioClient.fPutObject(config.assets.bucket, thumbFileSmall, thumbPathSmall, {'Content-Type': 'image/jpeg'})
......@@ -75,8 +78,10 @@ const concatJob = async function (job) {
job.progress(100)
let assetHost = `${config.assets.client.secure ? 'https://' : 'http://'}${config.assets.client.endPoint}`
if (config.assets.client.port !== 80 && config.assets.client.port !== 443) assetHost += `:${config.assets.client.port}`
let port = config.assets.client.port ? parseInt(config.assets.client.port) : undefined
let secure = config.assets.client.secure && (config.assets.client.secure === true || config.assets.client.secure === 'true')
let assetHost = `${secure ? 'https://' : 'http://'}${config.assets.client.endPoint}`
if (port !== 80 && port !== 443) assetHost += `:${port}`
assetHost += `/${config.assets.bucket}`
if (errored) return
......
......@@ -87,7 +87,10 @@ const convertJob = async function (job) {
if (!errored) {
try {
const minioClient = new Minio.Client(config.assets.client)
const opts = Object.assign({}, config.assets.client)
opts.secure = config.assets.client.secure && (config.assets.client.secure === true || config.assets.client.secure === 'true')
opts.port = config.assets.client.port ? parseInt(config.assets.client.port) : undefined
const minioClient = new Minio.Client(opts)
await minioClient.fPutObject(config.assets.bucket, destFile, destination, {'Content-Type': 'video/mp4'})
await minioClient.fPutObject(config.assets.bucket, thumbFile, thumbPath, {'Content-Type': 'image/jpeg'})
await minioClient.fPutObject(config.assets.bucket, thumbFileSmall, thumbPathSmall, {'Content-Type': 'image/jpeg'})
......@@ -103,8 +106,10 @@ const convertJob = async function (job) {
job.progress(100)
let assetHost = `${config.assets.client.secure ? 'https://' : 'http://'}${config.assets.client.endPoint}`
if (config.assets.client.port !== 80 && config.assets.client.port !== 443) assetHost += `:${config.assets.client.port}`
let port = config.assets.client.port ? parseInt(config.assets.client.port) : undefined
let secure = config.assets.client.secure && (config.assets.client.secure === true || config.assets.client.secure === 'true')
let assetHost = `${secure ? 'https://' : 'http://'}${config.assets.client.endPoint}`
if (port !== 80 && port !== 443) assetHost += `:${port}`
assetHost += `/${config.assets.bucket}`
if (errored) return
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment