mirror of
https://github.com/verdaccio/verdaccio.git
synced 2025-02-17 23:45:29 -05:00
refactor: improve readability
This commit is contained in:
parent
02d910149b
commit
cbc6479003
4 changed files with 9 additions and 21 deletions
|
@ -20,11 +20,11 @@ export function allow_action(action) {
|
||||||
|
|
||||||
export function getDefaultPlugins() {
|
export function getDefaultPlugins() {
|
||||||
return {
|
return {
|
||||||
authenticate: function(user, password, cb) {
|
authenticate(user, password, cb) {
|
||||||
cb(ErrorCode.getForbidden(API_ERROR.BAD_USERNAME_PASSWORD));
|
cb(ErrorCode.getForbidden(API_ERROR.BAD_USERNAME_PASSWORD));
|
||||||
},
|
},
|
||||||
|
|
||||||
add_user: function(user, password, cb) {
|
add_user(user, password, cb) {
|
||||||
return cb(ErrorCode.getConflict(API_ERROR.BAD_USERNAME_PASSWORD));
|
return cb(ErrorCode.getConflict(API_ERROR.BAD_USERNAME_PASSWORD));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ export function normalizeUserlist(oldFormat: any, newFormat: any) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// if it's a string, split it to array
|
// if it's a string, split it to array
|
||||||
if (typeof(arguments[i]) === 'string') {
|
if (_.isString(arguments[i])) {
|
||||||
result.push(arguments[i].split(/\s+/));
|
result.push(arguments[i].split(/\s+/));
|
||||||
} else if (Array.isArray(arguments[i])) {
|
} else if (Array.isArray(arguments[i])) {
|
||||||
result.push(arguments[i]);
|
result.push(arguments[i]);
|
||||||
|
@ -60,7 +60,7 @@ export function uplinkSanityCheck(uplinks: UpLinksConfList, users: any = BLACKLI
|
||||||
export function sanityCheckNames(item: string, users: any) {
|
export function sanityCheckNames(item: string, users: any) {
|
||||||
assert(item !== 'all' && item !== 'owner' && item !== 'anonymous' && item !== 'undefined' && item !== 'none', 'CONFIG: reserved uplink name: ' + item);
|
assert(item !== 'all' && item !== 'owner' && item !== 'anonymous' && item !== 'undefined' && item !== 'none', 'CONFIG: reserved uplink name: ' + item);
|
||||||
assert(!item.match(/\s/), 'CONFIG: invalid uplink name: ' + item);
|
assert(!item.match(/\s/), 'CONFIG: invalid uplink name: ' + item);
|
||||||
assert(users[item] == null, 'CONFIG: duplicate uplink name: ' + item);
|
assert(_.isNil(users[item]), 'CONFIG: duplicate uplink name: ' + item);
|
||||||
users[item] = true;
|
users[item] = true;
|
||||||
|
|
||||||
return users;
|
return users;
|
||||||
|
@ -87,12 +87,7 @@ export function hasProxyTo(pkg: string, upLink: string, packages: PackageList):
|
||||||
const matchedPkg: MatchedPackage = (getMatchedPackagesSpec(pkg, packages): MatchedPackage);
|
const matchedPkg: MatchedPackage = (getMatchedPackagesSpec(pkg, packages): MatchedPackage);
|
||||||
const proxyList = typeof matchedPkg !== 'undefined' ? matchedPkg.proxy : [];
|
const proxyList = typeof matchedPkg !== 'undefined' ? matchedPkg.proxy : [];
|
||||||
if (proxyList) {
|
if (proxyList) {
|
||||||
return proxyList.reduce((prev, curr) => {
|
return proxyList.some((curr) => upLink === curr);
|
||||||
if (upLink === curr) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return prev;
|
|
||||||
}, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -78,11 +78,11 @@ class Config implements AppConfig {
|
||||||
this.packages = normalisePackageAccess(self.packages);
|
this.packages = normalisePackageAccess(self.packages);
|
||||||
|
|
||||||
// loading these from ENV if aren't in config
|
// loading these from ENV if aren't in config
|
||||||
allowedEnvConfig.forEach((function(v) {
|
allowedEnvConfig.forEach((envConf) => {
|
||||||
if (!(v in self)) {
|
if (!(envConf in self)) {
|
||||||
self[v] = process.env[v] || process.env[v.toUpperCase()];
|
self[envConf] = process.env[envConf] || process.env[envConf.toUpperCase()];
|
||||||
}
|
}
|
||||||
}));
|
});
|
||||||
|
|
||||||
// unique identifier of self server (or a cluster), used to avoid loops
|
// unique identifier of self server (or a cluster), used to avoid loops
|
||||||
if (!this.server_id) {
|
if (!this.server_id) {
|
||||||
|
|
|
@ -96,13 +96,6 @@ export interface IStorageHandler {
|
||||||
_updateVersionsHiddenUpLink(versions: Versions, upLink: IProxy): void;
|
_updateVersionsHiddenUpLink(versions: Versions, upLink: IProxy): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
// export interface ConfigHandler {
|
|
||||||
// checkSecretKey(token: string): string;
|
|
||||||
// hasProxyTo(pkg: string, upLink: string): boolean;
|
|
||||||
// getMatchedPackagesSpec(storage: string): verdaccio$PackageAccess | void;
|
|
||||||
// [key: string]: number;
|
|
||||||
// }
|
|
||||||
|
|
||||||
export type StartUpConfig = {
|
export type StartUpConfig = {
|
||||||
storage: string;
|
storage: string;
|
||||||
self_path: string;
|
self_path: string;
|
||||||
|
|
Loading…
Add table
Reference in a new issue