summaryrefslogtreecommitdiff
path: root/app.js
diff options
context:
space:
mode:
authorYukai Huang2016-10-11 18:39:15 +0800
committerYukai Huang2016-10-11 18:40:23 +0800
commit6e651c8108783d224c5f40d1bb8047a9ebbeff00 (patch)
treec7d501cc6ebb46399c397768b3f58ef05034c522 /app.js
parent21028c57735028574c769fb6650322eb3f0cb924 (diff)
parentcd9f8fe36b707ff5a9f8f7be4d55145ddee97f3a (diff)
Merge branch 'master' into webpack-frontend
Diffstat (limited to 'app.js')
-rw-r--r--app.js68
1 files changed, 14 insertions, 54 deletions
diff --git a/app.js b/app.js
index e18a2f0b..b877bc8f 100644
--- a/app.js
+++ b/app.js
@@ -22,6 +22,7 @@ var i18n = require('i18n');
var config = require("./lib/config.js");
var logger = require("./lib/logger.js");
var auth = require("./lib/auth.js");
+var history = require("./lib/history.js");
var response = require("./lib/response.js");
var models = require("./lib/models");
@@ -94,7 +95,7 @@ app.use(helmet.hsts({
}));
i18n.configure({
- locales: ['en', 'zh', 'fr', 'de', 'ja', 'es', 'el', 'pt'],
+ locales: ['en', 'zh', 'fr', 'de', 'ja', 'es', 'el', 'pt', 'it', 'tr', 'ru', 'nl', 'hr', 'pl', 'uk'],
cookie: 'locale',
directory: __dirname + '/locales'
});
@@ -365,56 +366,15 @@ app.get('/logout', function (req, res) {
res.redirect(config.serverurl + '/');
});
//get history
-app.get('/history', function (req, res) {
- if (req.isAuthenticated()) {
- models.User.findOne({
- where: {
- id: req.user.id
- }
- }).then(function (user) {
- if (!user)
- return response.errorNotFound(res);
- var history = [];
- if (user.history)
- history = JSON.parse(user.history);
- res.send({
- history: history
- });
- if (config.debug)
- logger.info('read history success: ' + user.id);
- }).catch(function (err) {
- logger.error('read history failed: ' + err);
- return response.errorInternalError(res);
- });
- } else {
- return response.errorForbidden(res);
- }
-});
+app.get('/history', history.historyGet);
//post history
-app.post('/history', urlencodedParser, function (req, res) {
- if (req.isAuthenticated()) {
- if (config.debug)
- logger.info('SERVER received history from [' + req.user.id + ']: ' + req.body.history);
- models.User.update({
- history: req.body.history
- }, {
- where: {
- id: req.user.id
- }
- }).then(function (count) {
- if (!count)
- return response.errorNotFound(res);
- if (config.debug)
- logger.info("write user history success: " + req.user.id);
- }).catch(function (err) {
- logger.error('write history failed: ' + err);
- return response.errorInternalError(res);
- });
- res.end();
- } else {
- return response.errorForbidden(res);
- }
-});
+app.post('/history', urlencodedParser, history.historyPost);
+//post history by note id
+app.post('/history/:noteId', urlencodedParser, history.historyPost);
+//delete history
+app.delete('/history', history.historyDelete);
+//delete history by note id
+app.delete('/history/:noteId', history.historyDelete);
//get me info
app.get('/me', function (req, res) {
if (req.isAuthenticated()) {
@@ -522,9 +482,9 @@ function startListen() {
// sync db then start listen
models.sequelize.sync().then(function () {
// check if realtime is ready
- if (realtime.isReady()) {
+ if (history.isReady() && realtime.isReady()) {
models.Revision.checkAllNotesRevision(function (err, notes) {
- if (err) return new Error(err);
+ if (err) throw new Error(err);
if (!notes || notes.length <= 0) return startListen();
});
}
@@ -549,9 +509,9 @@ process.on('SIGINT', function () {
socket.disconnect(true);
});
var checkCleanTimer = setInterval(function () {
- if (realtime.isReady()) {
+ if (history.isReady() && realtime.isReady()) {
models.Revision.checkAllNotesRevision(function (err, notes) {
- if (err) return new Error(err);
+ if (err) throw new Error(err);
if (notes.length <= 0) {
clearInterval(checkCleanTimer);
return process.exit(0);