api: lint

This commit is contained in:
Thomas Hobson 2021-02-27 13:08:51 +13:00
parent 8b61f4f69f
commit 764641b5a6
No known key found for this signature in database
GPG Key ID: 9F1FD9D87950DB6F
3 changed files with 23 additions and 23 deletions

View File

@ -8,26 +8,26 @@ const { body } = require('express-validator');
module.exports = { module.exports = {
run_job_validators: [ run_job_validators: [
body('language') body('language')
.isString(), .isString(), // eslint-disable-line snakecasejs/snakecasejs
body('version') body('version')
.isSemVer(), .isSemVer(), // eslint-disable-line snakecasejs/snakecasejs
body('files') body('files')
.isArray(), .isArray(), // eslint-disable-line snakecasejs/snakecasejs
body('files.*.name') body('files.*.name')
.isString() .isString() // eslint-disable-line snakecasejs/snakecasejs
.bail() .bail()
.not() .not()
.contains('/'), .contains('/'),
body('files.*.content') body('files.*.content')
.isString(), .isString(), // eslint-disable-line snakecasejs/snakecasejs
body('*_timeout') body('*_timeout')
.isNumeric(), .isNumeric(), // eslint-disable-line snakecasejs/snakecasejs
body('stdin') body('stdin')
.isString(), .isString(), // eslint-disable-line snakecasejs/snakecasejs
body('args') body('args')
.isArray(), .isArray(),
body('args.*') body('args.*')
.isString() .isString() // eslint-disable-line snakecasejs/snakecasejs
], ],
async run_job(req, res){ async run_job(req, res){
// POST /jobs // POST /jobs

View File

@ -11,7 +11,7 @@ const fs = require('fs/promises');
const fss = require('fs'); const fss = require('fs');
const body_parser = require('body-parser'); const body_parser = require('body-parser');
const runtime = require('./runtime'); const runtime = require('./runtime');
const {validationResult} = require('express-validator'); const {validationResult} = require('express-validator'); //eslint-disable-line snakecasejs/snakecasejs
const logger = Logger.create('index'); const logger = Logger.create('index');
const app = express(); const app = express();
@ -77,8 +77,8 @@ const app = express();
function validate(req, res, next) { function validate(req, res, next) {
const errors = validationResult(req); const errors = validationResult(req); //eslint-disable-line snakecasejs/snakecasejs
if (!errors.isEmpty()) if (!errors.isEmpty()) //eslint-disable-line snakecasejs/snakecasejs
return res.json_error(errors.array(), 422); return res.json_error(errors.array(), 422);
next(); next();
} }

View File

@ -42,17 +42,17 @@ module.exports = {
}, },
repo_add_validators: [ repo_add_validators: [
body('slug') body('slug')
.notEmpty() .notEmpty() // eslint-disable-line snakecasejs/snakecasejs
.bail() .bail()
.isSlug() .isSlug() // eslint-disable-line snakecasejs/snakecasejs
.bail() .bail()
.not() .not()
.custom(value=>state.state.get('repositories').keys().includes(value)) .custom(value=>state.state.get('repositories').keys().includes(value))
.withMessage("slug is already in use"), .withMessage('slug is already in use'), // eslint-disable-line snakecasejs/snakecasejs
body('url') body('url')
.notEmpty() .notEmpty() // eslint-disable-line snakecasejs/snakecasejs
.bail() .bail()
.isURL({require_protocol: true}) .isURL({require_protocol: true}) // eslint-disable-line snakecasejs/snakecasejs
], ],
async repo_add(req, res){ async repo_add(req, res){
@ -69,10 +69,10 @@ module.exports = {
}, },
repo_info_validators: [ repo_info_validators: [
param('repo_slug') param('repo_slug')
.isSlug() .isSlug() // eslint-disable-line snakecasejs/snakecasejs
.bail() .bail()
.custom(value=>state.state.get('repositories').has(value)) .custom(value=>state.state.get('repositories').has(value))
.withMessage("repository does not exist") .withMessage('repository does not exist') // eslint-disable-line snakecasejs/snakecasejs
.bail() .bail()
], ],
async repo_info(req, res){ async repo_info(req, res){
@ -89,10 +89,10 @@ module.exports = {
}, },
repo_packages_validators: [ repo_packages_validators: [
param('repo_slug') param('repo_slug')
.isSlug() .isSlug() // eslint-disable-line snakecasejs/snakecasejs
.bail() .bail()
.custom(value=>state.state.get('repositories').has(value)) .custom(value=>state.state.get('repositories').has(value))
.withMessage("repository does not exist") .withMessage('repository does not exist') // eslint-disable-line snakecasejs/snakecasejs
.bail() .bail()
], ],
async repo_packages(req, res){ async repo_packages(req, res){
@ -112,10 +112,10 @@ module.exports = {
}, },
package_info_validators: [ package_info_validators: [
param('repo_slug') param('repo_slug')
.isSlug() .isSlug() // eslint-disable-line snakecasejs/snakecasejs
.bail() .bail()
.custom(value=>state.state.get('repositories').has(value)) .custom(value=>state.state.get('repositories').has(value))
.withMessage("repository does not exist") .withMessage('repository does not exist') // eslint-disable-line snakecasejs/snakecasejs
.bail() .bail()
], ],
async package_info(req, res){ async package_info(req, res){
@ -161,6 +161,6 @@ module.exports = {
// DELETE /repos/:slug/packages/:language/:version // DELETE /repos/:slug/packages/:language/:version
//res.json(req.body); //TODO //res.json(req.body); //TODO
res.json_error("not implemented", 500) res.json_error('not implemented', 500);
} }
}; };