Commit a787c108 authored by Anton Koch's avatar Anton Koch

Add microservices integration

parent c2207dc2
......@@ -12,6 +12,8 @@ and this project adheres to
### Added
- [cote](https://cote.js.org) Sockend client integration to
connect to [sockets service](https://gitlab.rlp.net/motionbank/microservices/sockets)
- Cell datatype available as vuex store module
- SwimLane component in post-annotator and on standalone page
- Annotations can have durations through target.selector.value
......
......@@ -18,6 +18,7 @@ module.exports = function (ctx) {
'pkg',
'shortkey',
'sort',
'socket',
'vocabularies',
'window'
],
......@@ -60,6 +61,7 @@ module.exports = function (ctx) {
// Hosts
//
API_HOST: JSON.stringify(process.env.API_HOST || 'https://api.motionbank.org'),
SOCKETS_HOST: JSON.stringify(process.env.SOCKETS_HOST || 'https://sockets.motionbank.org'),
STORAGE_HOST: JSON.stringify(process.env.STORAGE_HOST || 'https://storage.motionbank.org'),
PACKAGER_HOST: JSON.stringify(process.env.PACKAGER_HOST || 'https://packager.motionbank.org'),
TRANSCODER_HOST: JSON.stringify(process.env.TRANSCODER_HOST || 'https://transcoder.motionbank.org'),
......
import VueSocketIO from 'vue-socket.io'
export default ({ Vue }) => {
if (!process.env.SOCKETS_HOST) return
Vue.use(new VueSocketIO({
debug: true,
connection: `${process.env.SOCKETS_HOST}`,
query: {
token: localStorage.getItem('access_token')
}
}))
}
import axios from 'axios'
import { BASE_URI } from 'mbjs-data-models/src/constants'
import { Assert } from 'mbjs-utils'
......@@ -17,26 +16,31 @@ const metadata = {
async get (context, payload) {
Assert.ok(typeof payload === 'string' || typeof payload.body.source.id === 'string',
'Metadata request payload must be UUID string or annotation object')
const headers = {
Authorization: `Bearer ${localStorage.getItem('access_token')}`
if (typeof payload === 'string') {
payload = await context.dispatch('annotations/get', payload, { root: true })
}
let metadataURL
if (typeof payload === 'string') metadataURL = `${process.env.TRANSCODER_HOST}/metadata/${payload}`
else metadataURL = `${process.env.TRANSCODER_HOST}/metadata/url?url=${encodeURIComponent(payload.body.source.id)}`
let metadata
metadata = context.state.cache[metadataURL] || metadata
metadata = context.state.cache[payload.body.source.id] || metadata
if (!metadata) {
metadata = {}
try {
let result = await axios.get(metadataURL, {headers})
metadata = result.data
context.commit('setCache', [metadataURL, metadata])
const result = await new Promise(resolve => {
this.$router.app.$socket.emit(
'metadata:get',
{ url: payload.body.source.id, token: localStorage.getItem('access_token') },
data => resolve(data)
)
})
if (result) {
metadata = result
context.commit('setCache', [payload.body.source.id, metadata])
}
}
catch (err) {
if (!err.response || err.response.status > 404) console.error(err.message)
}
}
if (typeof payload === 'string' || payload.id) {
if (payload.id) {
const titleQuery = {
'target.id': typeof payload === 'string' ? `${BASE_URI}/annotations/${payload}` : payload.id,
'body.purpose': 'describing',
......@@ -56,11 +60,11 @@ const metadata = {
Assert.ok(typeof payload === 'string' || typeof payload.body.source.id === 'string',
'Metadata request payload must be UUID string or annotation object')
let metadataURL
if (typeof payload === 'string') metadataURL = `${process.env.TRANSCODER_HOST}/metadata/${payload}`
else metadataURL = `${process.env.TRANSCODER_HOST}/metadata/url?url=${encodeURIComponent(payload.body.source.id)}`
if (typeof payload === 'string') {
payload = await context.dispatch('annotations/get', payload, { root: true })
}
let metadata
metadata = context.state.cache[metadataURL] || {}
metadata = context.state.cache[payload.body.source.id] || {}
const titleQuery = {
'target.id': typeof payload === 'string' ? `${BASE_URI}/annotations/${payload}` : payload.id,
'body.purpose': 'describing',
......
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