0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2025-01-20 22:52:46 -05:00

refactor: private methods

This commit is contained in:
Juan Picado @jotadeveloper 2018-04-18 07:22:03 +02:00
parent a75b7bdcdd
commit 7617a51f6e
No known key found for this signature in database
GPG key ID: 18AC54485952D158

View file

@ -50,29 +50,7 @@ class LocalStorage implements IStorage {
this.logger = logger.child({sub: 'fs'}); this.logger = logger.child({sub: 'fs'});
this.config = config; this.config = config;
this.localData = this._loadStorage(config, logger); this.localData = this._loadStorage(config, logger);
config.secret = config.checkSecretKey(this.localData.getSecret()); this._setSecret(config);
this.localData.setSecret(this.config.secret);
}
_loadStorage(config: Config, logger: Logger) {
const Storage = this._loadStorePlugin();
if (_.isNil(Storage)) {
return new LocalDatabase(this.config, logger);
} else {
return Storage;
}
}
_loadStorePlugin() {
const plugin_params = {
config: this.config,
logger: this.logger,
};
return _.head(loadPlugin(this.config, this.config.store, plugin_params, function(plugin) {
return plugin.getPackageStorage;
}));
} }
addPackage(name: string, pkg: Package, callback: Callback) { addPackage(name: string, pkg: Package, callback: Callback) {
@ -857,6 +835,32 @@ class LocalStorage implements IStorage {
hash.url = UrlNode.format(tarballUrl); hash.url = UrlNode.format(tarballUrl);
} }
} }
_setSecret(config: Config) {
this.localData.setSecret(config.checkSecretKey(this.localData.getSecret()));
}
_loadStorage(config: Config, logger: Logger) {
const Storage = this._loadStorePlugin();
if (_.isNil(Storage)) {
return new LocalDatabase(this.config, logger);
} else {
return Storage;
}
}
_loadStorePlugin() {
const plugin_params = {
config: this.config,
logger: this.logger,
};
return _.head(loadPlugin(this.config, this.config.store, plugin_params, function(plugin) {
return plugin.getPackageStorage;
}));
}
} }
export default LocalStorage; export default LocalStorage;