mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-28 15:10:55 -05:00
Fix realtime on forbidden not clean up properly and handle on updating note which already been clean up
This commit is contained in:
parent
23c53f3d15
commit
725e98288b
1 changed files with 18 additions and 9 deletions
|
@ -80,6 +80,8 @@ var updater = setInterval(function () {
|
|||
if (note.server.isDirty) {
|
||||
if (config.debug) logger.info("updater found dirty note: " + key);
|
||||
updateNote(note, function(err, _note) {
|
||||
// handle when note already been clean up
|
||||
if (!notes[key] || !notes[key].server) return callback(null, null);
|
||||
if (!_note) {
|
||||
realtime.io.to(note.id).emit('info', {
|
||||
code: 404
|
||||
|
@ -89,7 +91,9 @@ var updater = setInterval(function () {
|
|||
if (err || !_note) {
|
||||
for (var i = 0, l = note.socks.length; i < l; i++) {
|
||||
var sock = note.socks[i];
|
||||
sock.disconnect(true);
|
||||
if (typeof sock !== 'undefined' && sock) {
|
||||
sock.disconnect(true);
|
||||
}
|
||||
}
|
||||
return callback(err, null);
|
||||
}
|
||||
|
@ -139,6 +143,7 @@ function updateNote(note, callback) {
|
|||
});
|
||||
}
|
||||
function finishUpdateNote(note, _note, callback) {
|
||||
if (!note || !note.server) return callback(null, null);
|
||||
var body = note.server.document;
|
||||
var title = models.Note.parseNoteTitle(body);
|
||||
title = LZString.compressToBase64(title);
|
||||
|
@ -329,6 +334,16 @@ function connectNextSocket() {
|
|||
startConnection(connectionSocketQueue[0]);
|
||||
}
|
||||
|
||||
function interruptConnection(socket, note, user) {
|
||||
if (note) delete note;
|
||||
if (user) delete user;
|
||||
if (socket)
|
||||
clearSocketQueue(connectionSocketQueue, socket);
|
||||
else
|
||||
connectionSocketQueue.shift();
|
||||
connectNextSocket();
|
||||
}
|
||||
|
||||
var isConnectionBusy = false;
|
||||
var connectionSocketQueue = [];
|
||||
var isDisconnectBusy = false;
|
||||
|
@ -337,20 +352,14 @@ var disconnectSocketQueue = [];
|
|||
function finishConnection(socket, note, user) {
|
||||
// if no valid info provided will drop the client
|
||||
if (!socket || !note || !user) {
|
||||
if (note) delete note;
|
||||
if (user) delete user;
|
||||
if (socket)
|
||||
clearSocketQueue(connectionSocketQueue, socket);
|
||||
else
|
||||
connectionSocketQueue.shift();
|
||||
connectNextSocket();
|
||||
return;
|
||||
return interruptConnection(socket, note, user);
|
||||
}
|
||||
//check view permission
|
||||
if (note.permission == 'private') {
|
||||
if (socket.request.user && socket.request.user.logged_in && socket.request.user.id == note.owner) {
|
||||
//na
|
||||
} else {
|
||||
interruptConnection(socket, note, user);
|
||||
return failConnection(403, 'connection forbidden', socket);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue