Archived
2

implemented /model/files

This commit is contained in:
VLE2FE 2020-08-28 09:04:05 +02:00
parent 349ff16191
commit c891933d11
4 changed files with 68 additions and 0 deletions

View File

@ -73,6 +73,32 @@
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}:
parameters:
- $ref: 'api.yaml#/components/parameters/Name'

View File

@ -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}', (() => {
it('returns the binary data', done => {
TestHelper.request(server, done, {

View File

@ -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) => {
if (!req.auth(res, ['dev', 'admin'], 'all')) return;

View File

@ -32,4 +32,11 @@ export default class ModelValidate { // validate input for model
}).validate(data, {stripUnknown: true});
return error !== undefined? null : value;
}
static fileOutput (data) {
return {
name: data.name,
size: data.data.length
}
}
}