Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Open sidebar
Motion Bank
Services
Transcoder
Commits
3027f4e6
Commit
3027f4e6
authored
Aug 21, 2018
by
A. Koch
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update service signatures, integrate error handler
parent
156758ec
Pipeline
#1084
passed with stage
Changes
8
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
42 additions
and
42 deletions
+42
-42
src/index.js
src/index.js
+8
-8
src/lib/conversions.js
src/lib/conversions.js
+3
-3
src/lib/downloads.js
src/lib/downloads.js
+2
-2
src/lib/metadata.js
src/lib/metadata.js
+6
-6
src/lib/sequences.js
src/lib/sequences.js
+3
-3
src/lib/service.js
src/lib/service.js
+13
-13
src/lib/timecodes.js
src/lib/timecodes.js
+4
-4
src/lib/uploads.js
src/lib/uploads.js
+3
-3
No files found.
src/index.js
View file @
3027f4e6
...
...
@@ -11,10 +11,10 @@ const setup = async function () {
models
=
require
(
'
mbjs-data-models
'
),
Service
=
require
(
'
./lib/service
'
)
const
annotations
=
new
Service
(
'
annotations
'
,
api
.
_app
,
models
.
Annotation
,
api
.
_logger
,
api
.
_acl
)
const
annotations
=
new
Service
(
'
annotations
'
,
api
,
models
.
Annotation
)
// annotations.on('message', message => api._sockets.write(message))
const
maps
=
new
Service
(
'
maps
'
,
api
.
_app
,
models
.
Map
,
api
.
_logger
,
api
.
_acl
)
const
maps
=
new
Service
(
'
maps
'
,
api
,
models
.
Map
)
// annotations.on('message', message => api._sockets.write(message))
/**
...
...
@@ -22,42 +22,42 @@ const setup = async function () {
*/
const
Metadata
=
require
(
'
./lib/metadata
'
),
metadata
=
new
Metadata
(
api
.
_app
,
annotations
)
metadata
=
new
Metadata
(
api
,
annotations
)
/**
* Configure upload
*/
const
Uploads
=
require
(
'
./lib/uploads
'
),
uploads
=
new
Uploads
(
api
.
_app
)
uploads
=
new
Uploads
(
api
)
/**
* Configure download
*/
const
Downloads
=
require
(
'
./lib/downloads
'
),
downloads
=
new
Downloads
(
api
.
_app
)
downloads
=
new
Downloads
(
api
)
/**
* Configure conversion
*/
const
Conversions
=
require
(
'
./lib/conversions
'
),
conversions
=
new
Conversions
(
api
.
_app
)
conversions
=
new
Conversions
(
api
)
/**
* Configure sequences
*/
const
Sequences
=
require
(
'
./lib/sequences
'
),
sequences
=
new
Sequences
(
api
.
_app
,
annotations
,
maps
)
sequences
=
new
Sequences
(
api
,
annotations
,
maps
)
/**
* Configure timecode
*/
const
Timecodes
=
require
(
'
./lib/timecodes
'
),
timecodes
=
new
Timecodes
(
api
.
_app
)
timecodes
=
new
Timecodes
(
api
)
await
api
.
start
()
}
...
...
src/lib/conversions.js
View file @
3027f4e6
...
...
@@ -8,7 +8,7 @@ const
{
ObjectUtil
}
=
require
(
'
mbjs-utils
'
)
class
Metadata
extends
TinyEmitter
{
constructor
(
ap
p
)
{
constructor
(
ap
i
)
{
super
()
const
_this
=
this
...
...
@@ -16,14 +16,14 @@ class Metadata extends TinyEmitter {
this
.
_queue
=
new
Queue
(
'
conversions
'
,
config
.
conversions
.
redisURL
)
this
.
_queue
.
process
(
parseInt
(
config
.
conversions
.
concurrency
),
require
(
'
./workers/convert
'
))
app
.
post
(
'
/conversions
'
,
async
(
req
,
res
)
=>
{
api
.
app
.
post
(
'
/conversions
'
,
async
(
req
,
res
)
=>
{
const
jobId
=
ObjectUtil
.
uuid4
()
req
.
body
.
uuid
=
ObjectUtil
.
uuid4
()
_this
.
_queue
.
add
(
req
.
body
,
{
jobId
})
_this
.
_response
(
req
,
res
,
{
jobId
})
})
app
.
get
(
'
/conversions/:id
'
,
async
(
req
,
res
)
=>
{
api
.
app
.
get
(
'
/conversions/:id
'
,
async
(
req
,
res
)
=>
{
const
job
=
await
_this
.
_queue
.
getJob
(
req
.
params
.
id
)
if
(
!
job
)
return
_this
.
_errorResponse
(
res
,
404
)
const
jobInfo
=
{
...
...
src/lib/downloads.js
View file @
3027f4e6
...
...
@@ -4,13 +4,13 @@ const
TinyEmitter
=
require
(
'
tiny-emitter
'
)
class
Downloads
extends
TinyEmitter
{
constructor
(
ap
p
)
{
constructor
(
ap
i
)
{
super
()
const
_this
=
this
this
.
minioClient
=
new
Minio
.
Client
(
config
.
assets
.
client
)
app
.
get
(
'
/downloads/:file
'
,
async
(
req
,
res
)
=>
{
api
.
app
.
get
(
'
/downloads/:file
'
,
async
(
req
,
res
)
=>
{
const
stream
=
await
_this
.
minioClient
.
getObject
(
config
.
assets
.
bucket
,
req
.
params
.
file
)
res
.
setHeader
(
'
Content-Type
'
,
'
application/force-download
'
)
stream
.
pipe
(
res
)
...
...
src/lib/metadata.js
View file @
3027f4e6
...
...
@@ -19,12 +19,12 @@ const fetchMetaData = async (annotation, user, annotationsService) => {
return
results
.
data
},
config
.
apiKeys
)
}
catch
(
e
)
{
console
.
error
(
'
fetchMetaData
'
,
e
.
messag
e
)
}
catch
(
e
)
{
api
.
captureException
(
e
)
}
return
meta
}
class
Metadata
extends
TinyEmitter
{
constructor
(
ap
p
,
annotationsService
)
{
constructor
(
ap
i
,
annotationsService
)
{
super
()
this
.
_annotations
=
annotationsService
...
...
@@ -32,7 +32,7 @@ class Metadata extends TinyEmitter {
const
_this
=
this
app
.
get
(
'
/metadata/:id
'
,
async
(
req
,
res
)
=>
{
api
.
app
.
get
(
'
/metadata/:id
'
,
async
(
req
,
res
)
=>
{
let
source
,
annotation
if
(
req
.
params
.
id
===
'
url
'
)
{
source
=
req
.
query
.
url
...
...
@@ -43,7 +43,7 @@ class Metadata extends TinyEmitter {
annotation
=
result
.
data
source
=
annotation
.
body
.
source
.
id
}
catch
(
e
)
{
/* ignored */
}
catch
(
e
)
{
api
.
captureException
(
e
)
}
}
if
(
!
source
)
return
_this
.
_errorResponse
(
res
,
404
)
const
key
=
`metadata_
${
ObjectUtil
.
slug
(
source
)}
`
...
...
@@ -51,7 +51,7 @@ class Metadata extends TinyEmitter {
if
(
_this
.
_memcached
)
{
metadata
=
await
new
Promise
((
resolve
,
reject
)
=>
{
_this
.
_memcached
.
get
(
key
,
function
(
err
,
data
)
{
if
(
err
)
console
.
error
(
'
failed to get metadata from cache
'
,
err
.
message
)
if
(
err
)
api
.
captureException
(
err
)
resolve
(
data
)
})
})
...
...
@@ -61,7 +61,7 @@ class Metadata extends TinyEmitter {
if
(
_this
.
_memcached
&&
metadata
)
{
await
new
Promise
((
resolve
,
reject
)
=>
{
_this
.
_memcached
.
set
(
key
,
metadata
,
parseInt
(
config
.
metadata
.
lifetime
.
toString
()),
err
=>
{
if
(
err
)
console
.
error
(
'
failed to store metadata in cache
'
,
err
.
message
)
if
(
err
)
api
.
captureException
(
err
)
resolve
()
})
})
...
...
src/lib/sequences.js
View file @
3027f4e6
...
...
@@ -7,7 +7,7 @@ const
{
ObjectUtil
}
=
require
(
'
mbjs-utils
'
)
class
Sequences
extends
TinyEmitter
{
constructor
(
ap
p
,
annotationsService
,
mapsService
)
{
constructor
(
ap
i
,
annotationsService
,
mapsService
)
{
super
()
const
_this
=
this
...
...
@@ -18,7 +18,7 @@ class Sequences extends TinyEmitter {
this
.
_queue
=
new
Queue
(
'
sequences
'
,
config
.
sequences
.
redisURL
)
this
.
_queue
.
process
(
parseInt
(
config
.
sequences
.
concurrency
),
require
(
'
./workers/concat
'
))
app
.
post
(
'
/sequences
'
,
async
(
req
,
res
)
=>
{
api
.
app
.
post
(
'
/sequences
'
,
async
(
req
,
res
)
=>
{
let
result
=
await
_this
.
_maps
.
getHandler
({
params
:
{
id
:
req
.
body
.
id
...
...
@@ -43,7 +43,7 @@ class Sequences extends TinyEmitter {
_this
.
_response
(
req
,
res
,
{
jobId
})
})
app
.
get
(
'
/sequences/:id
'
,
async
(
req
,
res
)
=>
{
api
.
app
.
get
(
'
/sequences/:id
'
,
async
(
req
,
res
)
=>
{
const
job
=
await
_this
.
_queue
.
getJob
(
req
.
params
.
id
)
if
(
!
job
)
return
_this
.
_errorResponse
(
res
,
404
)
const
jobInfo
=
{
...
...
src/lib/service.js
View file @
3027f4e6
...
...
@@ -6,24 +6,24 @@ const
{
MongoDB
}
=
require
(
'
mbjs-persistence
'
)
class
Service
extends
TinyEmitter
{
constructor
(
name
,
ap
p
,
model
,
logger
,
acl
)
{
constructor
(
name
,
ap
i
,
model
)
{
super
()
const
_this
=
this
this
.
_name
=
name
this
.
_acl
=
acl
this
.
_logger
=
logger
this
.
_acl
=
api
.
acl
this
.
_logger
=
api
.
logger
this
.
_Model
=
model
// TODO: make db adapter configurable (nedb, etc.)
this
.
_client
=
new
MongoDB
(
ObjectUtil
.
merge
({
name
,
logger
},
config
.
get
(
'
resources.mongodb
'
)),
'
uuid
'
)
app
.
get
(
`/
${
this
.
_name
}
`
,
(
req
,
res
)
=>
_this
.
findHandler
(
req
,
res
))
app
.
get
(
`/
${
this
.
_name
}
/:id`
,
(
req
,
res
)
=>
_this
.
getHandler
(
req
,
res
))
app
.
post
(
`/
${
this
.
_name
}
`
,
(
req
,
res
)
=>
_this
.
postHandler
(
req
,
res
))
app
.
put
(
`/
${
this
.
_name
}
/:id`
,
(
req
,
res
)
=>
_this
.
putHandler
(
req
,
res
))
app
.
patch
(
`/
${
this
.
_name
}
/:id`
,
(
req
,
res
)
=>
_this
.
patchHandler
(
req
,
res
))
app
.
delete
(
`/
${
this
.
_name
}
/:id`
,
(
req
,
res
)
=>
_this
.
deleteHandler
(
req
,
res
))
this
.
_client
=
new
MongoDB
(
ObjectUtil
.
merge
({
name
,
logger
:
api
.
logger
},
config
.
get
(
'
resources.mongodb
'
)),
'
uuid
'
)
api
.
app
.
get
(
`/
${
this
.
_name
}
`
,
(
req
,
res
)
=>
_this
.
findHandler
(
req
,
res
))
api
.
app
.
get
(
`/
${
this
.
_name
}
/:id`
,
(
req
,
res
)
=>
_this
.
getHandler
(
req
,
res
))
api
.
app
.
post
(
`/
${
this
.
_name
}
`
,
(
req
,
res
)
=>
_this
.
postHandler
(
req
,
res
))
api
.
app
.
put
(
`/
${
this
.
_name
}
/:id`
,
(
req
,
res
)
=>
_this
.
putHandler
(
req
,
res
))
api
.
app
.
patch
(
`/
${
this
.
_name
}
/:id`
,
(
req
,
res
)
=>
_this
.
patchHandler
(
req
,
res
))
api
.
app
.
delete
(
`/
${
this
.
_name
}
/:id`
,
(
req
,
res
)
=>
_this
.
deleteHandler
(
req
,
res
))
}
async
findHandler
(
req
,
res
)
{
...
...
@@ -38,7 +38,7 @@ class Service extends TinyEmitter {
allowed
=
await
this
.
_acl
.
isAllowed
(
user
,
entry
.
uuid
,
'
get
'
)
}
catch
(
err
)
{
this
.
_logger
.
error
(
`ACL error:
${
err
.
message
}
`
)
api
.
captureException
(
err
)
}
}
if
(
allowed
)
items
.
push
(
entry
)
...
...
@@ -57,7 +57,7 @@ class Service extends TinyEmitter {
allowed
=
await
this
.
_acl
.
isAllowed
(
user
,
result
.
uuid
,
'
get
'
)
}
catch
(
err
)
{
this
.
_logger
.
error
(
`ACL error:
${
err
.
message
}
`
)
api
.
captureException
(
err
)
}
}
if
(
allowed
)
{
...
...
src/lib/timecodes.js
View file @
3027f4e6
...
...
@@ -8,7 +8,7 @@ const
{
ObjectUtil
}
=
require
(
'
mbjs-utils
'
)
class
Timecodes
extends
TinyEmitter
{
constructor
(
ap
p
)
{
constructor
(
ap
i
)
{
super
()
this
.
_queue
=
new
Queue
(
'
timecode
'
,
config
.
timecode
.
redisURL
)
...
...
@@ -18,14 +18,14 @@ class Timecodes extends TinyEmitter {
const
_this
=
this
app
.
post
(
'
/timecodes
'
,
async
(
req
,
res
)
=>
{
api
.
app
.
post
(
'
/timecodes
'
,
async
(
req
,
res
)
=>
{
const
jobId
=
ObjectUtil
.
uuid4
()
req
.
body
.
uuid
=
ObjectUtil
.
uuid4
()
_this
.
_queue
.
add
(
req
.
body
,
{
jobId
})
_this
.
_response
(
req
,
res
,
{
jobId
})
})
app
.
get
(
'
/timecodes/signals/ltc
'
,
async
(
req
,
res
)
=>
{
api
.
app
.
get
(
'
/timecodes/signals/ltc
'
,
async
(
req
,
res
)
=>
{
const
files
=
[]
const
stream
=
await
this
.
_minio
.
listObjects
(
'
ltc
'
,
'
LTC
'
)
stream
.
on
(
'
data
'
,
obj
=>
files
.
push
(
obj
.
name
))
...
...
@@ -40,7 +40,7 @@ class Timecodes extends TinyEmitter {
})
})
app
.
get
(
'
/timecodes/:id
'
,
async
(
req
,
res
)
=>
{
api
.
app
.
get
(
'
/timecodes/:id
'
,
async
(
req
,
res
)
=>
{
const
job
=
await
_this
.
_queue
.
getJob
(
req
.
params
.
id
)
if
(
!
job
)
return
_this
.
_errorResponse
(
res
,
404
)
const
jobInfo
=
{
...
...
src/lib/uploads.js
View file @
3027f4e6
...
...
@@ -9,13 +9,13 @@ const
TinyEmitter
=
require
(
'
tiny-emitter
'
)
class
Uploads
extends
TinyEmitter
{
constructor
(
ap
p
)
{
constructor
(
ap
i
)
{
super
()
const
_this
=
this
const
upload
=
multer
({
dest
:
os
.
tmpdir
()
})
app
.
post
(
'
/uploads
'
,
async
(
req
,
res
)
=>
{
api
.
app
.
post
(
'
/uploads
'
,
async
(
req
,
res
)
=>
{
upload
.
single
(
'
file
'
)(
req
,
res
,
async
()
=>
{
const
extname
=
path
.
extname
(
req
.
file
.
originalname
)
const
filename
=
`
${
ObjectUtil
.
uuid4
()}${
extname
.
toLowerCase
()}
`
...
...
@@ -33,7 +33,7 @@ class Uploads extends TinyEmitter {
})
})
app
.
delete
(
'
/uploads/:file
'
,
async
(
req
,
res
)
=>
{
api
.
app
.
delete
(
'
/uploads/:file
'
,
async
(
req
,
res
)
=>
{
const
minioClient
=
new
Minio
.
Client
(
config
.
assets
.
client
)
await
minioClient
.
removeObject
(
config
.
assets
.
bucket
,
req
.
params
.
file
)
_this
.
_response
(
req
,
res
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment