mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
DRY up a bit
This commit is contained in:
parent
b796879c9f
commit
55c880e1dd
1 changed files with 12 additions and 22 deletions
|
@ -91,38 +91,28 @@ module.exports = WebsocketController =
|
||||||
return callback(error) if error?
|
return callback(error) if error?
|
||||||
DocumentUpdaterManager.getDocument project_id, doc_id, fromVersion, (error, lines, version, ranges, ops) ->
|
DocumentUpdaterManager.getDocument project_id, doc_id, fromVersion, (error, lines, version, ranges, ops) ->
|
||||||
return callback(error) if error?
|
return callback(error) if error?
|
||||||
|
|
||||||
# Encode any binary bits of data so it can go via WebSockets
|
# Encode any binary bits of data so it can go via WebSockets
|
||||||
# See http://ecmanaut.blogspot.co.uk/2006/07/encoding-decoding-utf8-in-javascript.html
|
# See http://ecmanaut.blogspot.co.uk/2006/07/encoding-decoding-utf8-in-javascript.html
|
||||||
|
encodeForWebsockets = (text) -> unescape(encodeURIComponent(text))
|
||||||
escapedLines = []
|
escapedLines = []
|
||||||
for line in lines
|
for line in lines
|
||||||
try
|
try
|
||||||
line = unescape(encodeURIComponent(line))
|
line = encodeForWebsockets(line)
|
||||||
catch err
|
catch err
|
||||||
logger.err {err, project_id, doc_id, fromVersion, line, client_id: client.id}, "error encoding line uri component"
|
logger.err {err, project_id, doc_id, fromVersion, line, client_id: client.id}, "error encoding line uri component"
|
||||||
return callback(err)
|
return callback(err)
|
||||||
escapedLines.push line
|
escapedLines.push line
|
||||||
if options.encodeRanges
|
if options.encodeRanges
|
||||||
if ranges.comments
|
try
|
||||||
escapedComments = []
|
for comment in ranges?.comments or []
|
||||||
for comment in ranges.comments
|
comment.op.c = encodeForWebsockets(comment.op.c)
|
||||||
try
|
for change in ranges?.changes or []
|
||||||
comment.op.c = unescape(encodeURIComponent(comment.op.c))
|
change.op.i = encodeForWebsockets(comment.op.i) if change.op.i
|
||||||
catch err
|
change.op.d = encodeForWebsockets(comment.op.d) if change.op.d
|
||||||
logger.err {err, project_id, doc_id, fromVersion, comment, client_id: client.id}, "error encoding comment uri component"
|
catch err
|
||||||
return callback(err)
|
logger.err {err, project_id, doc_id, fromVersion, ranges, client_id: client.id}, "error encoding range uri component"
|
||||||
escapedComments.push comment
|
return callback(err)
|
||||||
ranges.comments = escapedComments
|
|
||||||
if ranges.changes
|
|
||||||
escapedChanges = []
|
|
||||||
for change in ranges.changes
|
|
||||||
try
|
|
||||||
change.op.i = unescape(encodeURIComponent(change.op.i)) if change.op.i
|
|
||||||
change.op.d = unescape(encodeURIComponent(change.op.d)) if change.op.d
|
|
||||||
catch err
|
|
||||||
logger.err {err, project_id, doc_id, fromVersion, change, client_id: client.id}, "error encoding change uri component"
|
|
||||||
return callback(err)
|
|
||||||
escapedChanges.push change
|
|
||||||
ranges.changes = escapedChanges
|
|
||||||
|
|
||||||
AuthorizationManager.addAccessToDoc client, doc_id
|
AuthorizationManager.addAccessToDoc client, doc_id
|
||||||
client.join(doc_id)
|
client.join(doc_id)
|
||||||
|
|
Loading…
Reference in a new issue