Commit 989c8675 authored by Anton's avatar Anton

Remove PBA related code

parent bc4e1220
......@@ -57,13 +57,6 @@
"audience": "AUTH0_AUDIENCE"
}
},
"pba": {
"baseUrl": "PBA_BASE_URL",
"credentials": {
"username": "PBA_USERNAME",
"password": "PBA_PASSWORD"
}
},
"microservices": {
"acl": {
"key": "MICROSERVICES_ACL_KEY",
......
......@@ -68,13 +68,6 @@
"youtube": null,
"vimeo": null
},
"pba": {
"baseUrl": null,
"credentials": {
"username": null,
"password": null
}
},
"microservices": {
"acl": {
"key": "acl",
......
......@@ -66,13 +66,6 @@
"youtube": null,
"vimeo": null
},
"pba": {
"baseUrl": null,
"credentials": {
"username": null,
"password": null
}
},
"microservices": {
"acl": {
"key": "acl",
......
......@@ -55,14 +55,6 @@ 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) {
if (config.pba.baseUrl) {
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')
if (result) this._response(req, res, result.pieces)
else this._errorResponse(res, 503, 'PBA vocabularies not available')
}
async getTitlesForPieceHandler (req, res) {
const result = await this._performRequest(`titles/${req.params.piece_id}`)
if (result) this._response(req, res, result.titles)
else this._errorResponse(res, 503, 'PBA vocabularies not available')
}
_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