登录后判断是否有数据文件夹, 如果没有, 则新建之
nw.gui为什么不存在?
Before Width: | Height: | Size: 9.5 KiB |
Before Width: | Height: | Size: 32 KiB |
Before Width: | Height: | Size: 57 KiB |
Before Width: | Height: | Size: 287 KiB |
Before Width: | Height: | Size: 158 KiB |
Before Width: | Height: | Size: 114 KiB |
Before Width: | Height: | Size: 132 KiB |
Before Width: | Height: | Size: 67 KiB |
Before Width: | Height: | Size: 69 KiB |
2
node_modules/db.js
generated
vendored
@@ -2,7 +2,7 @@ var Datastore = require('nedb');
|
||||
var path = require('path');
|
||||
|
||||
// 数据库初始化
|
||||
// var dbPath = require('nw.gui').App.dataPath + '/nedb'
|
||||
// var dbPath = require('nw.gui').App.dataPath + '/nedb';
|
||||
var dbPath = '/Users/life/Library/Application Support/Leanote' + '/nedb';
|
||||
var db = {};
|
||||
var dbNames = ['notebooks', 'notes', 'users', 'tags', 'images', 'attachs', 'noteHistories'];
|
||||
|
16
node_modules/evt.js
generated
vendored
@@ -1,7 +1,20 @@
|
||||
var fs = require('fs');
|
||||
var User = require('user');
|
||||
|
||||
function log(o) {console.log(o)}
|
||||
function log(o) {
|
||||
console.log(o);
|
||||
};
|
||||
|
||||
// 为什么不存在?
|
||||
// var dataBasePath = require('nw.gui').App.dataPath; // + '/data';
|
||||
/*
|
||||
// 判断是否存在, 不存在则创建dir
|
||||
if(!fs.existsSync(dataBasePath)) {
|
||||
fs.mkdirSync(dataBasePath);
|
||||
}
|
||||
*/
|
||||
dataBasePath = '';
|
||||
|
||||
var Evt = {
|
||||
leanoteUrl: 'http://localhost:9000',
|
||||
port: 8008,
|
||||
@@ -14,6 +27,7 @@ var Evt = {
|
||||
},
|
||||
// 项目绝对地址
|
||||
getBasePath: function() {
|
||||
// return dataBasePath; // process.cwd();
|
||||
return process.cwd();
|
||||
},
|
||||
getAbsolutePath: function(relative) {
|
||||
|
32
node_modules/user.js
generated
vendored
@@ -1,5 +1,6 @@
|
||||
var Evt = require('evt');
|
||||
var db = require('db');
|
||||
var fs = require('fs');
|
||||
|
||||
function log(o) {
|
||||
console.log(o);
|
||||
@@ -33,6 +34,9 @@ User = {
|
||||
this.username = user.Username;
|
||||
// 保存到数据库中
|
||||
this.saveCurUser(user);
|
||||
|
||||
// 判断当前用户是否有文件夹
|
||||
me.setUserDataPath();
|
||||
}
|
||||
},
|
||||
saveCurUser: function(user, callback) {
|
||||
@@ -82,7 +86,7 @@ User = {
|
||||
var me = this;
|
||||
db.users.findOne({IsActive: true}, function(err, user) {
|
||||
if(err || !user || !user.UserId) {
|
||||
log('不存在');
|
||||
console.log('不存在');
|
||||
callback && callback(false);
|
||||
} else {
|
||||
// me.setCurUser(doc);
|
||||
@@ -93,6 +97,9 @@ User = {
|
||||
me.LastSyncUsn = user.LastSyncUsn;
|
||||
me.LastSyncTime = user.LastSyncTime;
|
||||
|
||||
// 设置当前用户数据路径
|
||||
me.setUserDataPath();
|
||||
|
||||
callback && callback(user);
|
||||
}
|
||||
});
|
||||
@@ -117,6 +124,29 @@ User = {
|
||||
return 'data/' + this.getCurActiveUserId() + '/attachs';
|
||||
},
|
||||
|
||||
setUserDataPath: function(userId) {
|
||||
var me = this;
|
||||
// 判断是否存在, 不存在则创建dir
|
||||
try {
|
||||
fs.mkdirSync(Evt.getBasePath() + '/data/');
|
||||
}
|
||||
catch(e) {};
|
||||
try {
|
||||
fs.mkdirSync(Evt.getBasePath() + '/data/' + this.getCurActiveUserId());
|
||||
} catch(e) {
|
||||
}
|
||||
try {
|
||||
fs.mkdirSync(Evt.getBasePath() + '/data/' + this.getCurActiveUserId() + '/images');
|
||||
} catch(e) {
|
||||
}
|
||||
try {
|
||||
fs.mkdirSync(Evt.getBasePath() + '/data/' + this.getCurActiveUserId() + '/attachs');
|
||||
} catch(e) {
|
||||
console.log("eeeeeeeeeeeeeeeeee...........")
|
||||
console.log(e);
|
||||
}
|
||||
},
|
||||
|
||||
getCurUser: function(callback) {
|
||||
var me = this;
|
||||
db.users.findOne({_id: me.getCurActiveUserId()}, function(err, doc) {
|
||||
|
@@ -1260,7 +1260,6 @@ Note.listNoteContentHistories = function() {
|
||||
hideDialog();
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|