implemented /model/files
This commit is contained in:
parent
349ff16191
commit
c891933d11
@ -73,6 +73,32 @@
|
|||||||
500:
|
500:
|
||||||
$ref: 'api.yaml#/components/responses/500'
|
$ref: 'api.yaml#/components/responses/500'
|
||||||
|
|
||||||
|
/model/files:
|
||||||
|
get:
|
||||||
|
summary: list all stored models
|
||||||
|
description: 'Auth: basic, levels: dev, admin'
|
||||||
|
tags:
|
||||||
|
- /model
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: model details list
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
properties:
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
|
example: model_VN_A3WG6_V1
|
||||||
|
size:
|
||||||
|
type: number
|
||||||
|
example: 4177449
|
||||||
|
401:
|
||||||
|
$ref: 'api.yaml#/components/responses/401'
|
||||||
|
403:
|
||||||
|
$ref: 'api.yaml#/components/responses/403'
|
||||||
|
500:
|
||||||
|
$ref: 'api.yaml#/components/responses/500'
|
||||||
|
|
||||||
/model/file/{name}:
|
/model/file/{name}:
|
||||||
parameters:
|
parameters:
|
||||||
- $ref: 'api.yaml#/components/parameters/Name'
|
- $ref: 'api.yaml#/components/parameters/Name'
|
||||||
|
@ -273,6 +273,32 @@ describe('/model', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('GET /model/files', () => {
|
||||||
|
it('rejects a write user', done => {
|
||||||
|
TestHelper.request(server, done, {
|
||||||
|
method: 'get',
|
||||||
|
url: '/model/files',
|
||||||
|
auth: {basic: 'janedoe'},
|
||||||
|
httpStatus: 403,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('rejects an API key', done => {
|
||||||
|
TestHelper.request(server, done, {
|
||||||
|
method: 'get',
|
||||||
|
url: '/model/files',
|
||||||
|
auth: {key: 'admin'},
|
||||||
|
httpStatus: 401,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('rejects an unauthorized request', done => {
|
||||||
|
TestHelper.request(server, done, {
|
||||||
|
method: 'get',
|
||||||
|
url: '/model/files',
|
||||||
|
httpStatus: 401,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('GET /model/file/{name}', (() => {
|
describe('GET /model/file/{name}', (() => {
|
||||||
it('returns the binary data', done => {
|
it('returns the binary data', done => {
|
||||||
TestHelper.request(server, done, {
|
TestHelper.request(server, done, {
|
||||||
|
@ -95,6 +95,15 @@ router.delete('/model/:group(((?!file)[^\\/]+?))/:name', (req, res, next) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
router.get('/model/files', (req, res, next) => {
|
||||||
|
if (!req.auth(res, ['dev', 'admin'], 'basic')) return;
|
||||||
|
|
||||||
|
ModelFileModel.find().exec((err, data) => {
|
||||||
|
if (err) return next(err);
|
||||||
|
res.json(data.map(e => ModelValidate.fileOutput(e)));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
router.get('/model/file/:name', (req, res, next) => {
|
router.get('/model/file/:name', (req, res, next) => {
|
||||||
if (!req.auth(res, ['dev', 'admin'], 'all')) return;
|
if (!req.auth(res, ['dev', 'admin'], 'all')) return;
|
||||||
|
|
||||||
|
@ -32,4 +32,11 @@ export default class ModelValidate { // validate input for model
|
|||||||
}).validate(data, {stripUnknown: true});
|
}).validate(data, {stripUnknown: true});
|
||||||
return error !== undefined? null : value;
|
return error !== undefined? null : value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static fileOutput (data) {
|
||||||
|
return {
|
||||||
|
name: data.name,
|
||||||
|
size: data.data.length
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user