Mark van Renswoude
4db1b2f23d
Fixed production check in webpack config, removed moment locales and reduced lodash and fontawesome inclusion
59 lines
1.4 KiB
JavaScript
59 lines
1.4 KiB
JavaScript
const path = require('path');
|
|
const mkdirp = require('mkdirp');
|
|
const Datastore = require('nedb');
|
|
|
|
const UserRepository = require('./user').UserRepository;
|
|
const CodeRepository = require('./code').CodeRepository;
|
|
const UploadRepository = require('./upload').UploadRepository;
|
|
const NotificationRepository = require('./notification').NotificationRepository;
|
|
|
|
|
|
class Repository
|
|
{
|
|
constructor(config)
|
|
{
|
|
var self = this;
|
|
self.config = config;
|
|
}
|
|
|
|
|
|
load()
|
|
{
|
|
var self = this;
|
|
|
|
return new Promise((resolve, reject) =>
|
|
{
|
|
const initStore = (filename) =>
|
|
{
|
|
var store = new Datastore({
|
|
filename: path.join(self.config.path, filename),
|
|
autoload: true
|
|
});
|
|
|
|
store.persistence.setAutocompactionInterval(self.config.autocompactionInterval);
|
|
return store;
|
|
};
|
|
|
|
mkdirp(self.config.path, (err) =>
|
|
{
|
|
if (err)
|
|
{
|
|
reject(err);
|
|
return;
|
|
}
|
|
|
|
self.users = new UserRepository(initStore('user.db'));
|
|
self.codes = new CodeRepository(initStore('code.db'));
|
|
self.uploads = new UploadRepository(initStore('upload.db'));
|
|
self.notifications = new NotificationRepository(initStore('notification.db'));
|
|
|
|
self.users.init()
|
|
.then(() => { resolve() })
|
|
.catch((e) => { reject(e); });
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
module.exports = Repository; |