Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var Datastore = require('nedb');
var path = require('path');
var Evt = require('evt');
// 数据库初始化
// var dbPath = require('nw.gui').App.dataPath + '/nedb';
// var dbPath = Evt.getBasePath() + '/Users/life/Library/Application Support/Leanote' + '/nedb';
// nedb2 为了port
var dbPath = Evt.getDBPath();
// console.error(dbPath);
// test
if(dbPath.length < 6) {
var dbPath = '/Users/life/Library/Application Support/Leanote' + '/nedb2';
}
// console.log(dbPath);
// g, 表全局环境
var db = {
// 为全部用户共有的表初始化
initGlobal: function () {
var me = this;
var dbNames = ['users', 'g'];
this.initIt(me, dbNames);
getUserDataStats: function (user) {
var me = this;
var userId = user.UserId;
var dbPath = user.HasDB ? me.getUserDBPath(userId) : Evt.getDBPath();
var dbSize = Common.getFolderSize(dbPath);
var imageSize = Common.getFolderSize(me.getUserImagesPath(userId));
var attachSize = Common.getFolderSize(me.getUserAttachsPath(userId));
return {
db: dbSize,
image: imageSize,
attach: attachSize
};
},
me.getUser(userId, function (user) {
if (!user) {
return callback(false);
}
if (user.HasDB) {
callback(me.getUserDBPath(userId));
}
else {
callback(Evt.getDBPath());
}
});
},
getUserDBPath: function (userId) {
var base = Evt.getDBPath();
if (!base) {
return false;
}
return base + '/' + userId;
},