summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/config/default.js1
-rw-r--r--lib/config/environment.js2
-rw-r--r--lib/config/index.js6
-rw-r--r--lib/history.js15
-rw-r--r--lib/migrations/20150702001020-update-to-0_3_1.js6
-rw-r--r--lib/migrations/20160112220142-note-add-lastchange.js6
-rw-r--r--lib/migrations/20160420180355-note-add-alias.js6
-rw-r--r--lib/migrations/20160515114000-user-add-tokens.js6
-rw-r--r--lib/migrations/20160607060246-support-revision.js6
-rw-r--r--lib/migrations/20160703062241-support-authorship.js6
-rw-r--r--lib/migrations/20161009040430-support-delete-note.js8
-rw-r--r--lib/migrations/20161201050312-support-email-signin.js14
-rw-r--r--lib/models/note.js6
-rw-r--r--lib/response.js4
14 files changed, 86 insertions, 6 deletions
diff --git a/lib/config/default.js b/lib/config/default.js
index 5c39a4da..6096bce4 100644
--- a/lib/config/default.js
+++ b/lib/config/default.js
@@ -3,6 +3,7 @@
module.exports = {
domain: '',
urlPath: '',
+ host: '0.0.0.0',
port: 3000,
urlAddPort: false,
allowOrigin: ['localhost'],
diff --git a/lib/config/environment.js b/lib/config/environment.js
index d850ac9d..6c4ce92f 100644
--- a/lib/config/environment.js
+++ b/lib/config/environment.js
@@ -5,7 +5,9 @@ const {toBooleanConfig, toArrayConfig, toIntegerConfig} = require('./utils')
module.exports = {
domain: process.env.CMD_DOMAIN,
urlPath: process.env.CMD_URL_PATH,
+ host: process.env.CMD_HOST,
port: toIntegerConfig(process.env.CMD_PORT),
+ path: process.env.CMD_PATH,
urlAddPort: toBooleanConfig(process.env.CMD_URL_ADDPORT),
useSSL: toBooleanConfig(process.env.CMD_USESSL),
hsts: {
diff --git a/lib/config/index.js b/lib/config/index.js
index ac03fcd4..f96684ea 100644
--- a/lib/config/index.js
+++ b/lib/config/index.js
@@ -103,6 +103,12 @@ config.isSAMLEnable = config.saml.idpSsoUrl
config.isOAuth2Enable = config.oauth2.clientID && config.oauth2.clientSecret
config.isPDFExportEnable = config.allowPDFExport
+// Check gitlab api version
+if (config.gitlab.version !== 'v4' && config.gitlab.version !== 'v3') {
+ logger.warn('config.js contains wrong version (' + config.gitlab.version + ') for gitlab api; it should be \'v3\' or \'v4\'. Defaulting to v4')
+ config.gitlab.version = 'v4'
+}
+
// Only update i18n files in development setups
config.updateI18nFiles = (env === Environment.development)
diff --git a/lib/history.js b/lib/history.js
index c7d2472c..9c389bfa 100644
--- a/lib/history.js
+++ b/lib/history.js
@@ -31,6 +31,15 @@ function getHistory (userid, callback) {
history = JSON.parse(user.history)
// migrate LZString encoded note id to base64url encoded note id
for (let i = 0, l = history.length; i < l; i++) {
+ // Calculate minimal string length for an UUID that is encoded
+ // base64 encoded and optimize comparsion by using -1
+ // this should make a lot of LZ-String parsing errors obsolete
+ // as we can assume that a nodeId that is 48 chars or longer is a
+ // noteID.
+ const base64UuidLength = ((4 * 36) / 3) - 1
+ if (!(history[i].id.length > base64UuidLength)) {
+ continue
+ }
try {
let id = LZString.decompressFromBase64(history[i].id)
if (id && models.Note.checkNoteIdValid(id)) {
@@ -38,7 +47,11 @@ function getHistory (userid, callback) {
}
} catch (err) {
// most error here comes from LZString, ignore
- logger.error(err)
+ if (err.message === 'Cannot read property \'charAt\' of undefined') {
+ logger.warning('Looks like we can not decode "' + history[i].id + '" with LZString. Can be ignored.')
+ } else {
+ logger.error(err)
+ }
}
}
history = parseHistoryToObject(history)
diff --git a/lib/migrations/20150702001020-update-to-0_3_1.js b/lib/migrations/20150702001020-update-to-0_3_1.js
index 40d9c97a..e661a343 100644
--- a/lib/migrations/20150702001020-update-to-0_3_1.js
+++ b/lib/migrations/20150702001020-update-to-0_3_1.js
@@ -20,6 +20,12 @@ module.exports = {
type: Sequelize.INTEGER,
defaultValue: 0
})
+ }).catch(function (error) {
+ if (error.message === "ER_DUP_FIELDNAME: Duplicate column name 'shortid'") {
+ console.log('Migration has already run… ignoring.')
+ } else {
+ throw error
+ }
})
},
diff --git a/lib/migrations/20160112220142-note-add-lastchange.js b/lib/migrations/20160112220142-note-add-lastchange.js
index b4e111b3..d0030d6b 100644
--- a/lib/migrations/20160112220142-note-add-lastchange.js
+++ b/lib/migrations/20160112220142-note-add-lastchange.js
@@ -7,6 +7,12 @@ module.exports = {
return queryInterface.addColumn('Notes', 'lastchangeAt', {
type: Sequelize.DATE
})
+ }).catch(function (error) {
+ if (error.message === "ER_DUP_FIELDNAME: Duplicate column name 'lastchangeuserId'") {
+ console.log('Migration has already run… ignoring.')
+ } else {
+ throw error
+ }
})
},
diff --git a/lib/migrations/20160420180355-note-add-alias.js b/lib/migrations/20160420180355-note-add-alias.js
index a043cd5c..4bad29ca 100644
--- a/lib/migrations/20160420180355-note-add-alias.js
+++ b/lib/migrations/20160420180355-note-add-alias.js
@@ -7,6 +7,12 @@ module.exports = {
return queryInterface.addIndex('Notes', ['alias'], {
indicesType: 'UNIQUE'
})
+ }).catch(function (error) {
+ if (error.message === "ER_DUP_FIELDNAME: Duplicate column name 'alias'") {
+ console.log('Migration has already run… ignoring.')
+ } else {
+ throw error
+ }
})
},
diff --git a/lib/migrations/20160515114000-user-add-tokens.js b/lib/migrations/20160515114000-user-add-tokens.js
index 4d5818be..4245f1ad 100644
--- a/lib/migrations/20160515114000-user-add-tokens.js
+++ b/lib/migrations/20160515114000-user-add-tokens.js
@@ -3,6 +3,12 @@ module.exports = {
up: function (queryInterface, Sequelize) {
return queryInterface.addColumn('Users', 'accessToken', Sequelize.STRING).then(function () {
return queryInterface.addColumn('Users', 'refreshToken', Sequelize.STRING)
+ }).catch(function (error) {
+ if (error.message === "ER_DUP_FIELDNAME: Duplicate column name 'accessToken'") {
+ console.log('Migration has already run… ignoring.')
+ } else {
+ throw error
+ }
})
},
diff --git a/lib/migrations/20160607060246-support-revision.js b/lib/migrations/20160607060246-support-revision.js
index bcab97e3..10f288b0 100644
--- a/lib/migrations/20160607060246-support-revision.js
+++ b/lib/migrations/20160607060246-support-revision.js
@@ -15,6 +15,12 @@ module.exports = {
createdAt: Sequelize.DATE,
updatedAt: Sequelize.DATE
})
+ }).catch(function (error) {
+ if (error.message === "ER_DUP_FIELDNAME: Duplicate column name 'savedAt'") {
+ console.log('Migration has already run… ignoring.')
+ } else {
+ throw error
+ }
})
},
diff --git a/lib/migrations/20160703062241-support-authorship.js b/lib/migrations/20160703062241-support-authorship.js
index d73923b0..b3ced8c4 100644
--- a/lib/migrations/20160703062241-support-authorship.js
+++ b/lib/migrations/20160703062241-support-authorship.js
@@ -16,6 +16,12 @@ module.exports = {
createdAt: Sequelize.DATE,
updatedAt: Sequelize.DATE
})
+ }).catch(function (error) {
+ if (error.message === "ER_DUP_FIELDNAME: Duplicate column name 'authorship'") {
+ console.log('Migration has already run… ignoring.')
+ } else {
+ throw error
+ }
})
},
diff --git a/lib/migrations/20161009040430-support-delete-note.js b/lib/migrations/20161009040430-support-delete-note.js
index a39d1086..4df7a81c 100644
--- a/lib/migrations/20161009040430-support-delete-note.js
+++ b/lib/migrations/20161009040430-support-delete-note.js
@@ -1,7 +1,13 @@
'use strict'
module.exports = {
up: function (queryInterface, Sequelize) {
- return queryInterface.addColumn('Notes', 'deletedAt', Sequelize.DATE)
+ return queryInterface.addColumn('Notes', 'deletedAt', Sequelize.DATE).catch(function (error) {
+ if (error.message === "ER_DUP_FIELDNAME: Duplicate column name 'deletedAt'") {
+ console.log('Migration has already run… ignoring.')
+ } else {
+ throw error
+ }
+ })
},
down: function (queryInterface, Sequelize) {
diff --git a/lib/migrations/20161201050312-support-email-signin.js b/lib/migrations/20161201050312-support-email-signin.js
index d33225f1..4653e67a 100644
--- a/lib/migrations/20161201050312-support-email-signin.js
+++ b/lib/migrations/20161201050312-support-email-signin.js
@@ -2,7 +2,19 @@
module.exports = {
up: function (queryInterface, Sequelize) {
return queryInterface.addColumn('Users', 'email', Sequelize.TEXT).then(function () {
- return queryInterface.addColumn('Users', 'password', Sequelize.TEXT)
+ return queryInterface.addColumn('Users', 'password', Sequelize.TEXT).catch(function (error) {
+ if (error.message === "ER_DUP_FIELDNAME: Duplicate column name 'password'") {
+ console.log('Migration has already run… ignoring.')
+ } else {
+ throw error
+ }
+ })
+ }).catch(function (error) {
+ if (error.message === "ER_DUP_FIELDNAME: Duplicate column name 'email'") {
+ console.log('Migration has already run… ignoring.')
+ } else {
+ throw error
+ }
})
},
diff --git a/lib/models/note.js b/lib/models/note.js
index ec7e2b13..0e8dd4dd 100644
--- a/lib/models/note.js
+++ b/lib/models/note.js
@@ -227,7 +227,11 @@ module.exports = function (sequelize, DataTypes) {
var id = LZString.decompressFromBase64(noteId)
if (id && Note.checkNoteIdValid(id)) { return callback(null, id) } else { return _callback(null, null) }
} catch (err) {
- logger.error(err)
+ if (err.message === 'Cannot read property \'charAt\' of undefined') {
+ logger.warning('Looks like we can not decode "' + noteId + '" with LZString. Can be ignored.')
+ } else {
+ logger.error(err)
+ }
return _callback(null, null)
}
},
diff --git a/lib/response.js b/lib/response.js
index 3a31c511..37211998 100644
--- a/lib/response.js
+++ b/lib/response.js
@@ -573,11 +573,11 @@ function gitlabActionProjects (req, res, note) {
}
}).then(function (user) {
if (!user) { return response.errorNotFound(res) }
- var ret = { baseURL: config.gitlab.baseURL }
+ var ret = { baseURL: config.gitlab.baseURL, version: config.gitlab.version }
ret.accesstoken = user.accessToken
ret.profileid = user.profileid
request(
- config.gitlab.baseURL + '/api/v3/projects?access_token=' + user.accessToken,
+ config.gitlab.baseURL + '/api/' + config.gitlab.version + '/projects?access_token=' + user.accessToken,
function (error, httpResponse, body) {
if (!error && httpResponse.statusCode === 200) {
ret.projects = JSON.parse(body)