mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-12-16 21:56:25 -05:00
#103 Config file must not be aware of storage database, storage class should handle it.
This commit is contained in:
parent
a3ebb7942d
commit
f08e733cc4
4 changed files with 27 additions and 26 deletions
|
@ -7,8 +7,6 @@ const assert = require('assert');
|
|||
const Crypto = require('crypto');
|
||||
const Error = require('http-errors');
|
||||
const minimatch = require('minimatch');
|
||||
const Path = require('path');
|
||||
const LocalData = require('./local-data');
|
||||
const Utils = require('./utils');
|
||||
const pkginfo = require('pkginfo')(module); // eslint-disable-line no-unused-vars
|
||||
const pkgVersion = module.exports.version;
|
||||
|
@ -93,24 +91,6 @@ class Config {
|
|||
assert.equal(typeof(config), 'object', 'CONFIG: it doesn\'t look like a valid config file');
|
||||
|
||||
assert(self.storage, 'CONFIG: storage path not defined');
|
||||
// local data handler is linked with the configuration handler
|
||||
self.localList = new LocalData(
|
||||
Path.join(
|
||||
Path.resolve(Path.dirname(self.self_path || ''), self.storage),
|
||||
// FUTURE: the database might be parameterizable from config.yaml
|
||||
'.sinopia-db.json'
|
||||
)
|
||||
);
|
||||
// it generates a secret key
|
||||
// FUTURE: this might be an external secret key, perhaps whitin config file?
|
||||
if (!self.secret) {
|
||||
self.secret = self.localList.data.secret;
|
||||
if (!self.secret) {
|
||||
self.secret = Crypto.pseudoRandomBytes(32).toString('hex');
|
||||
self.localList.data.secret = self.secret;
|
||||
self.localList.sync();
|
||||
}
|
||||
}
|
||||
|
||||
const users = {
|
||||
'all': true,
|
||||
|
|
|
@ -39,9 +39,11 @@ class Storage {
|
|||
/**
|
||||
* Constructor
|
||||
* @param {Object} config config list of properties
|
||||
* @param {LocalData} localList reference
|
||||
*/
|
||||
constructor(config) {
|
||||
constructor(config, localList) {
|
||||
this.config = config;
|
||||
this.localList = localList;
|
||||
this.logger = Logger.logger.child({sub: 'fs'});
|
||||
}
|
||||
|
||||
|
@ -135,7 +137,7 @@ class Storage {
|
|||
});
|
||||
|
||||
Search.remove(name);
|
||||
this.config.localList.remove(name);
|
||||
this.localList.remove(name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -285,7 +287,7 @@ class Storage {
|
|||
|
||||
data.versions[version] = metadata;
|
||||
Utils.tag_version(data, version, tag);
|
||||
this.config.localList.add(name);
|
||||
this.localList.add(name);
|
||||
cb();
|
||||
}, callback);
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ class Search {
|
|||
*/
|
||||
query(q) {
|
||||
return q === '*'
|
||||
? this.storage.config.localList.get().map( function( pkg ) {
|
||||
? this.storage.localList.get().map( function( pkg ) {
|
||||
return {ref: pkg, score: 1};
|
||||
}) : this.index.search(q);
|
||||
}
|
||||
|
|
|
@ -2,10 +2,13 @@
|
|||
|
||||
const assert = require('assert');
|
||||
const async = require('async');
|
||||
const path = require('path');
|
||||
const Error = require('http-errors');
|
||||
const semver = require('semver');
|
||||
const Crypto = require('crypto');
|
||||
const Stream = require('stream');
|
||||
const Local = require('./local-storage');
|
||||
const LocalData = require('./local-data');
|
||||
const Logger = require('./logger');
|
||||
const MyStreams = require('./streams');
|
||||
const Proxy = require('./up-storage');
|
||||
|
@ -33,8 +36,24 @@ class Storage {
|
|||
this.uplinks[p].upname = p;
|
||||
}
|
||||
}
|
||||
// local data handler is linked with the configuration handler
|
||||
this.localList = new LocalData(path.join(path.resolve(path.dirname(config.self_path || ''), config.storage),
|
||||
// FUTURE: the database might be parameterizable from config.yaml
|
||||
'.sinopia-db.json'
|
||||
)
|
||||
);
|
||||
// it generates a secret key
|
||||
// FUTURE: this might be an external secret key, perhaps whitin config file?
|
||||
if (!config.secret) {
|
||||
config.secret = this.localList.data.secret;
|
||||
if (!config.secret) {
|
||||
config.secret = Crypto.pseudoRandomBytes(32).toString('hex');
|
||||
this.localList.data.secret = config.secret;
|
||||
this.localList.sync();
|
||||
}
|
||||
}
|
||||
// an instance for local storage
|
||||
this.local = new Local(config);
|
||||
this.local = new Local(config, this.localList);
|
||||
this.logger = Logger.logger.child();
|
||||
}
|
||||
|
||||
|
@ -438,7 +457,7 @@ class Storage {
|
|||
*/
|
||||
get_local(callback) {
|
||||
let self = this;
|
||||
let locals = this.config.localList.get();
|
||||
let locals = this.localList.get();
|
||||
let packages = [];
|
||||
|
||||
const getPackage = function(i) {
|
||||
|
|
Loading…
Reference in a new issue