Commit 1ac7c40a authored by Anton's avatar Anton

Add PBA endpoints, update changelog

parent 5d6334ee
Pipeline #10780 passed with stage
in 12 minutes and 7 seconds
......@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Added
- Basic [Pina Bausch Archive (PBA)](http://www.pinabausch.org) proxy endpoints for pieces and titles
### Updated
- Updated [mbjs-data-models](https://gitlab.rlp.net/motionbank/mbjs/data-models)
......
......@@ -55,5 +55,12 @@
"jwt": {
"audience": "AUTH0_AUDIENCE"
}
},
"pba": {
"baseUrl": "PBA_BASE_URL",
"credentials": {
"username": "PBA_USERNAME",
"password": "PBA_PASSWORD"
}
}
}
......@@ -66,5 +66,12 @@
"apiKeys": {
"youtube": null,
"vimeo": null
},
"pba": {
"baseUrl": null,
"credentials": {
"username": null,
"password": null
}
}
}
......@@ -64,5 +64,12 @@
"apiKeys": {
"youtube": null,
"vimeo": null
},
"pba": {
"baseUrl": null,
"credentials": {
"username": null,
"password": null
}
}
}
......@@ -52,6 +52,14 @@ const setup = async function () {
const archives = require('./lib/archives')
archives.setupArchives(api, maps, annotations, cells)
/**
* Configure PBA
*/
const
PBA = require('./lib/pba'),
pba = new PBA(api)
await api.start()
}
......
const
config = require('config'),
send = require('@polka/send-type'),
TinyEmitter = require('tiny-emitter'),
axios = require('axios')
class PBA extends TinyEmitter {
constructor (api) {
super()
const _this = this
api.app.get('/pba/pieces', (req, res) => _this.getPiecesHandler(req, res))
api.app.get('/pba/pieces/:piece_id/titles', (req, res) => _this.getTitlesForPieceHandler(req, res))
}
async _performRequest (path) {
const result = await axios.get(`${config.pba.baseUrl}/${path}`, { auth: config.pba.credentials })
return result.data
}
async getPiecesHandler (req, res) {
const result = await this._performRequest('pieces')
this._response(req, res, result.pieces)
}
async getTitlesForPieceHandler (req, res) {
const result = await this._performRequest(`titles/${req.params.piece_id}`)
this._response(req, res, result.titles)
}
_response (req, res, data = {}) {
this.emit('message', { method: req.method, id: data.id })
if (typeof res === 'function') res({ data })
else if (typeof res === 'undefined') return Promise.resolve({ data })
else send(res, 200, data)
}
_errorResponse (res, code, message = undefined) {
if (typeof res === 'function') res({ error: true, code })
else if (typeof res === 'undefined') return Promise.resolve({ error: true, code })
else send(res, code, message)
}
}
module.exports = PBA
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