mirror of
https://github.com/verdaccio/verdaccio.git
synced 2025-01-27 22:59:51 -05:00
refactor: renaming validate name method
This commit is contained in:
parent
c9933820cb
commit
d5f4b54a41
7 changed files with 27 additions and 31 deletions
|
@ -7,7 +7,6 @@ import {DIST_TAGS} from '../../../lib/utils';
|
|||
import type {Router} from 'express';
|
||||
import type {IAuth, $ResponseExtend, $RequestExtend, $NextFunctionVer, IStorageHandler} from '../../../../types';
|
||||
|
||||
|
||||
export default function(route: Router, auth: IAuth, storage: IStorageHandler) {
|
||||
const can = allow(auth);
|
||||
const tag_package_version = function(req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer) {
|
||||
|
@ -27,14 +26,11 @@ export default function(route: Router, auth: IAuth, storage: IStorageHandler) {
|
|||
};
|
||||
|
||||
// tagging a package
|
||||
route.put('/:package/:tag',
|
||||
can('publish'), media(mime.getType('json')), tag_package_version);
|
||||
route.put('/:package/:tag', can('publish'), media(mime.getType('json')), tag_package_version);
|
||||
|
||||
route.post('/-/package/:package/dist-tags/:tag',
|
||||
can('publish'), media(mime.getType('json')), tag_package_version);
|
||||
route.post('/-/package/:package/dist-tags/:tag', can('publish'), media(mime.getType('json')), tag_package_version);
|
||||
|
||||
route.put('/-/package/:package/dist-tags/:tag',
|
||||
can('publish'), media(mime.getType('json')), tag_package_version);
|
||||
route.put('/-/package/:package/dist-tags/:tag', can('publish'), media(mime.getType('json')), tag_package_version);
|
||||
|
||||
route.delete('/-/package/:package/dist-tags/:tag', can('publish'), function(req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer) {
|
||||
const tags = {};
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
import _ from 'lodash';
|
||||
import {allow} from '../../middleware';
|
||||
import {DIST_TAGS, filter_tarball_urls, get_version, ErrorCode} from '../../../lib/utils';
|
||||
import {HEADERS} from '../../../lib/constants';
|
||||
import type {Router} from 'express';
|
||||
import type {Config} from '@verdaccio/types';
|
||||
import type {IAuth, $ResponseExtend, $RequestExtend, $NextFunctionVer, IStorageHandler} from '../../../../types';
|
||||
|
@ -22,21 +23,21 @@ export default function(route: Router, auth: IAuth, storage: IStorageHandler, co
|
|||
return next(info);
|
||||
}
|
||||
|
||||
let t = get_version(info, queryVersion);
|
||||
if (_.isNil(t) === false) {
|
||||
return next(t);
|
||||
let version = get_version(info, queryVersion);
|
||||
if (_.isNil(version) === false) {
|
||||
return next(version);
|
||||
}
|
||||
|
||||
if (_.isNil(info[DIST_TAGS]) === false) {
|
||||
if (_.isNil(info[DIST_TAGS][queryVersion]) === false) {
|
||||
queryVersion = info[DIST_TAGS][queryVersion];
|
||||
t = get_version(info, queryVersion);
|
||||
if (_.isNil(t) === false) {
|
||||
return next(t);
|
||||
version = get_version(info, queryVersion);
|
||||
if (_.isNil(version) === false) {
|
||||
return next(version);
|
||||
}
|
||||
}
|
||||
}
|
||||
return next(ErrorCode.get404('version not found: ' + req.params.version));
|
||||
return next(ErrorCode.get404(`version not found: ${req.params.version}`));
|
||||
};
|
||||
|
||||
storage.getPackage({
|
||||
|
@ -55,7 +56,7 @@ export default function(route: Router, auth: IAuth, storage: IStorageHandler, co
|
|||
stream.on('error', function(err) {
|
||||
return res.report_error(err);
|
||||
});
|
||||
res.header('Content-Type', 'application/octet-stream');
|
||||
res.header('Content-Type', HEADERS.OCTET_STREAM);
|
||||
stream.pipe(res);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import _ from 'lodash';
|
|||
import Path from 'path';
|
||||
import mime from 'mime';
|
||||
|
||||
import {HEADERS} from '../../../lib/constants';
|
||||
import {DIST_TAGS, validate_metadata, isObject, ErrorCode} from '../../../lib/utils';
|
||||
import {media, expectJson, allow} from '../../middleware';
|
||||
import {notify} from '../../../lib/notify';
|
||||
|
@ -144,7 +145,7 @@ export default function(router: Router, auth: IAuth, storage: IStorageHandler, c
|
|||
});
|
||||
|
||||
// uploading package tarball
|
||||
router.put('/:package/-/:filename/*', can('publish'), media('application/octet-stream'),
|
||||
router.put('/:package/-/:filename/*', can('publish'), media(HEADERS.OCTET_STREAM),
|
||||
function(req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer) {
|
||||
const name = req.params.package;
|
||||
const stream = storage.addTarball(name, req.params.filename);
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
import _ from 'lodash';
|
||||
import {
|
||||
validate_name as utilValidateName,
|
||||
validateName as utilValidateName,
|
||||
validate_package as utilValidatePackage,
|
||||
isObject,
|
||||
ErrorCode} from '../lib/utils';
|
||||
|
@ -87,7 +87,7 @@ export function anti_loop(config: Config) {
|
|||
let arr = req.headers.via.split(',');
|
||||
|
||||
for (let i=0; i<arr.length; i++) {
|
||||
let m = arr[i].match(/\s*(\S+)\s+(\S+)/);
|
||||
const m = arr[i].match(/\s*(\S+)\s+(\S+)/);
|
||||
if (m && m[2] === config.server_id) {
|
||||
return next( ErrorCode.getCode(508, 'loop detected') );
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ import UrlNode from 'url';
|
|||
import _ from 'lodash';
|
||||
// $FlowFixMe
|
||||
import async from 'async';
|
||||
import {ErrorCode, isObject, getLatestVersion, tagVersion, validate_name, semverSort, DIST_TAGS} from './utils';
|
||||
import {ErrorCode, isObject, getLatestVersion, tagVersion, validateName, semverSort, DIST_TAGS} from './utils';
|
||||
import {
|
||||
generatePackageTemplate, normalizePackage, generateRevision, getLatestReadme, cleanUpReadme,
|
||||
fileExist, noSuchFile, DEFAULT_REVISION, pkgFileName,
|
||||
|
@ -355,7 +355,7 @@ class LocalStorage implements IStorage {
|
|||
*/
|
||||
removeTarball(name: string, filename: string,
|
||||
revision: string, callback: Callback) {
|
||||
assert(validate_name(filename));
|
||||
assert(validateName(filename));
|
||||
|
||||
this._updatePackage(name, (data, cb) => {
|
||||
if (data._attachments[filename]) {
|
||||
|
@ -383,7 +383,7 @@ class LocalStorage implements IStorage {
|
|||
* @return {Stream}
|
||||
*/
|
||||
addTarball(name: string, filename: string) {
|
||||
assert(validate_name(filename));
|
||||
assert(validateName(filename));
|
||||
|
||||
let length = 0;
|
||||
const shaOneHash = createTarballHash();
|
||||
|
@ -479,7 +479,7 @@ class LocalStorage implements IStorage {
|
|||
* @return {ReadTarball}
|
||||
*/
|
||||
getTarball(name: string, filename: string): IReadTarball {
|
||||
assert(validate_name(filename));
|
||||
assert(validateName(filename));
|
||||
|
||||
const storage: IPackageStorage = this._getLocalStorage(name);
|
||||
|
||||
|
@ -683,7 +683,7 @@ class LocalStorage implements IStorage {
|
|||
}
|
||||
|
||||
async.eachSeries(files, (file2, cb) => {
|
||||
if (validate_name(file2)) {
|
||||
if (validateName(file2)) {
|
||||
onPackage({
|
||||
name: `${file}/${file2}`,
|
||||
path: Path.resolve(base, storage, file, file2),
|
||||
|
@ -693,7 +693,7 @@ class LocalStorage implements IStorage {
|
|||
}
|
||||
}, cb);
|
||||
});
|
||||
} else if (validate_name(file)) {
|
||||
} else if (validateName(file)) {
|
||||
onPackage({
|
||||
name: file,
|
||||
path: Path.resolve(base, storage, file),
|
||||
|
|
|
@ -24,12 +24,10 @@ function validate_package(name: any): boolean {
|
|||
name = name.split('/', 2);
|
||||
if (name.length === 1) {
|
||||
// normal package
|
||||
return module.exports.validate_name(name[0]);
|
||||
return validateName(name[0]);
|
||||
} else {
|
||||
// scoped package
|
||||
return name[0][0] === '@'
|
||||
&& module.exports.validate_name(name[0].slice(1))
|
||||
&& module.exports.validate_name(name[1]);
|
||||
return name[0][0] === '@' && validateName(name[0].slice(1)) && validateName(name[1]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -38,7 +36,7 @@ function validate_package(name: any): boolean {
|
|||
* @param {*} name the package name
|
||||
* @return {Boolean} whether is valid or not
|
||||
*/
|
||||
function validate_name(name: string): boolean {
|
||||
function validateName(name: string): boolean {
|
||||
if (_.isString(name) === false) {
|
||||
return false;
|
||||
}
|
||||
|
@ -444,7 +442,7 @@ export {
|
|||
filter_tarball_urls,
|
||||
validate_metadata,
|
||||
isObject,
|
||||
validate_name,
|
||||
validateName,
|
||||
validate_package,
|
||||
getWebProtocol,
|
||||
getLatestVersion,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// @flow
|
||||
|
||||
import assert from 'assert';
|
||||
import {validate_name as validate} from '../../src/lib/utils';
|
||||
import {validateName as validate} from '../../src/lib/utils';
|
||||
import {generateGravatarUrl, GRAVATAR_DEFAULT} from '../../src/utils/user';
|
||||
import {spliceURL} from '../../src/utils/string';
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue