0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-30 22:34:10 -05:00

refactor: apply flow and imports es6

This commit is contained in:
Juan Picado @jotadeveloper 2018-03-10 21:09:04 +01:00
parent 1d5a2c8214
commit 76fe6cb5d7
No known key found for this signature in database
GPG key ID: 18AC54485952D158
10 changed files with 37 additions and 41 deletions

View file

@ -1,12 +1,10 @@
'use strict';
const Middleware = require('../../web/middleware'); const Middleware = require('../../web/middleware');
const mime = require('mime'); const mime = require('mime');
const _ = require('lodash'); const _ = require('lodash');
const media = Middleware.media; const media = Middleware.media;
module.exports = function(route, auth, storage) { export default function(route, auth, storage) {
const can = Middleware.allow(auth); const can = Middleware.allow(auth);
const tag_package_version = function(req, res, next) { const tag_package_version = function(req, res, next) {
if (_.isString(req.body) === false) { if (_.isString(req.body) === false) {
@ -71,4 +69,4 @@ module.exports = function(route, auth, storage) {
return next({ok: 'tags updated'}); return next({ok: 'tags updated'});
}); });
}); });
}; }

View file

@ -4,7 +4,7 @@ const createError = require('http-errors');
const Middleware = require('../../web/middleware'); const Middleware = require('../../web/middleware');
const Utils = require('../../../lib/utils'); const Utils = require('../../../lib/utils');
module.exports = function(route, auth, storage, config) { export default function(route, auth, storage, config) {
const can = Middleware.allow(auth); const can = Middleware.allow(auth);
// TODO: anonymous user? // TODO: anonymous user?
route.get('/:package/:version?', can('access'), function(req, res, next) { route.get('/:package/:version?', can('access'), function(req, res, next) {
@ -56,4 +56,4 @@ module.exports = function(route, auth, storage, config) {
res.header('Content-Type', 'application/octet-stream'); res.header('Content-Type', 'application/octet-stream');
stream.pipe(res); stream.pipe(res);
}); });
}; }

View file

@ -1,7 +1,10 @@
'use strict'; // @flow
module.exports = function(route) { import type {Router} from 'express';
route.get('/-/ping', function(req, res, next) { import type {$RequestExtend, $ResponseExtend, $NextFunctionVer} from '../../../../types';
export default function(route: Router) {
route.get('/-/ping', function(req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer) {
next({}); next({});
}); });
}; }

View file

@ -1,5 +1,3 @@
'use strict';
const _ = require('lodash'); const _ = require('lodash');
const Path = require('path'); const Path = require('path');
const createError = require('http-errors'); const createError = require('http-errors');
@ -13,7 +11,7 @@ const media = Middleware.media;
const expect_json = Middleware.expect_json; const expect_json = Middleware.expect_json;
const notify = Notify.notify; const notify = Notify.notify;
module.exports = function(router, auth, storage, config) { export default function(router, auth, storage, config) {
const can = Middleware.allow(auth); const can = Middleware.allow(auth);
// publishing a package // publishing a package
@ -185,4 +183,4 @@ module.exports = function(router, auth, storage, config) {
}); });
}); });
}); });
}; }

View file

@ -1,6 +1,4 @@
'use strict'; export default function(route, auth, storage) {
module.exports = function(route, auth, storage) {
// searching packages // searching packages
route.get('/-/all(\/since)?', function(req, res) { route.get('/-/all(\/since)?', function(req, res) {
let received_end = false; let received_end = false;
@ -96,4 +94,4 @@ module.exports = function(route, auth, storage) {
check_finish(); check_finish();
}); });
}); });
}; }

View file

@ -7,7 +7,7 @@ import {ErrorCode} from '../../../lib/utils';
import _ from 'lodash'; import _ from 'lodash';
import Cookies from 'cookies'; import Cookies from 'cookies';
module.exports = function(route: Router, auth: IAuth) { export default function(route: Router, auth: IAuth) {
route.get('/-/user/:org_couchdb_user', function(req: $RequestExtend, res: $Response, next: $NextFunctionVer) { route.get('/-/user/:org_couchdb_user', function(req: $RequestExtend, res: $Response, next: $NextFunctionVer) {
res.status(200); res.status(200);
next({ next({
@ -70,4 +70,4 @@ module.exports = function(route: Router, auth: IAuth) {
roles: [], roles: [],
}); });
}); });
}; }

View file

@ -3,7 +3,7 @@
import type {$Response, Router} from 'express'; import type {$Response, Router} from 'express';
import type {$RequestExtend, $NextFunctionVer} from '../../../../types'; import type {$RequestExtend, $NextFunctionVer} from '../../../../types';
module.exports = function(route: Router) { export default function(route: Router) {
route.get('/whoami', (req: $RequestExtend, res: $Response, next: $NextFunctionVer): void => { route.get('/whoami', (req: $RequestExtend, res: $Response, next: $NextFunctionVer): void => {
if (req.headers.referer === 'whoami') { if (req.headers.referer === 'whoami') {
next({username: req.remote_user.name}); next({username: req.remote_user.name});
@ -15,4 +15,4 @@ module.exports = function(route: Router) {
route.get('/-/whoami', (req: $RequestExtend, res: $Response, next: $NextFunctionVer): mixed => { route.get('/-/whoami', (req: $RequestExtend, res: $Response, next: $NextFunctionVer): mixed => {
next({username: req.remote_user.name}); next({username: req.remote_user.name});
}); });
}; }

View file

@ -1,20 +1,25 @@
const express = require('express'); // @flow
const bodyParser = require('body-parser');
import type {IAuth, IStorage} from '../../../types';
import type {Config} from '@verdaccio/types';
import express from 'express';
import bodyParser from 'body-parser';
import whoami from './api/whoami';
import ping from './api/ping';
import user from './api/user';
import distTags from './api/dist-tags';
import publish from './api/publish';
import search from './api/search';
import pkg from './api/package';
const Middleware = require('../web/middleware'); const Middleware = require('../web/middleware');
const match = Middleware.match; const match = Middleware.match;
const validateName = Middleware.validate_name; const validateName = Middleware.validate_name;
const validatePkg = Middleware.validate_package; const validatePkg = Middleware.validate_package;
const encodeScopePackage = Middleware.encodeScopePackage; const encodeScopePackage = Middleware.encodeScopePackage;
const whoami = require('./api/whoami'); module.exports = function(config: Config, auth: IAuth, storage: IStorage) {
const ping = require('./api/ping');
const user = require('./api/user');
const distTags = require('./api/dist-tags');
const publish = require('./api/publish');
const search = require('./api/search');
const pkg = require('./api/package');
module.exports = function(config, auth, storage) {
/* eslint new-cap:off */ /* eslint new-cap:off */
const app = express.Router(); const app = express.Router();
/* eslint new-cap:off */ /* eslint new-cap:off */
@ -38,23 +43,15 @@ module.exports = function(config, auth, storage) {
// app.use(auth.bearer_middleware()) // app.use(auth.bearer_middleware())
app.use(bodyParser.json({strict: false, limit: config.max_body_size || '10mb'})); app.use(bodyParser.json({strict: false, limit: config.max_body_size || '10mb'}));
app.use(Middleware.anti_loop(config)); app.use(Middleware.anti_loop(config));
// encode / in a scoped package name to be matched as a single parameter in routes // encode / in a scoped package name to be matched as a single parameter in routes
app.use(encodeScopePackage); app.use(encodeScopePackage);
// for "npm whoami" // for "npm whoami"
whoami(app); whoami(app);
pkg(app, auth, storage, config); pkg(app, auth, storage, config);
search(app, auth, storage); search(app, auth, storage);
user(app, auth); user(app, auth);
distTags(app, auth, storage); distTags(app, auth, storage);
publish(app, auth, storage, config); publish(app, auth, storage, config);
ping(app); ping(app);
return app; return app;

View file

@ -1,4 +1,5 @@
// @flow // @flow
import rimRaf from 'rimraf'; import rimRaf from 'rimraf';
import path from 'path'; import path from 'path';
import LocalStorage from '../../src/lib/local-storage'; import LocalStorage from '../../src/lib/local-storage';

View file

@ -22,6 +22,7 @@ export interface IAuth {
secret: string; secret: string;
plugins: Array<any>; plugins: Array<any>;
aes_encrypt(buf: Buffer): Buffer; aes_encrypt(buf: Buffer): Buffer;
basic_middleware(): $NextFunctionVer;
add_user(user: string, password: string, cb: Callback): any; add_user(user: string, password: string, cb: Callback): any;
} }