mirror of https://github.com/xwiki-labs/cryptpad
formatting and lint compliance
This commit is contained in:
parent
480b499d7b
commit
118ceef2f2
|
@ -9,6 +9,7 @@ www/scratch
|
|||
www/common/toolbar.js
|
||||
www/common/hyperscript.js
|
||||
www/common/tippy.min.js
|
||||
www/common/onlyoffice/*
|
||||
|
||||
www/pad/wysiwygarea-plugin.js
|
||||
www/pad/mediatag-plugin.js
|
||||
|
@ -17,3 +18,4 @@ www/pad/mediatag-plugin-dialog.js
|
|||
www/common/media-tag-nacl.min.js
|
||||
|
||||
customize/
|
||||
|
||||
|
|
201
ooserver.js
201
ooserver.js
|
@ -1,6 +1,7 @@
|
|||
/* jshint esversion: 6 */
|
||||
|
||||
const sockjs = require('sockjs');
|
||||
const co = require('co');
|
||||
var config;
|
||||
try {
|
||||
config = require('./config');
|
||||
} catch (e) {
|
||||
|
@ -9,109 +10,107 @@ try {
|
|||
}
|
||||
var origin = config.httpUnsafeOrigin || 'http://localhost:3000/';
|
||||
|
||||
exports.install = function(server, callbackFunction) {
|
||||
var sockjs_opts = {sockjs_url: ""},
|
||||
sockjs_echo = sockjs.createServer(sockjs_opts),
|
||||
urlParse = new RegExp("^/common/onlyoffice/doc/([0-9-.a-zA-Z_=]*)/c.+", 'i');
|
||||
module.exports.install = function(server, callbackFunction) {
|
||||
var sockjs_opts = {sockjs_url: ""},
|
||||
sockjs_echo = sockjs.createServer(sockjs_opts);
|
||||
//urlParse = new RegExp("^/common/onlyoffice/doc/([0-9-.a-zA-Z_=]*)/c.+", 'i');
|
||||
|
||||
console.log("Start ooserver");
|
||||
console.log("Port " + sockjs_echo.port);
|
||||
console.log("Start ooserver");
|
||||
console.log("Port " + sockjs_echo.port);
|
||||
|
||||
function getBaseUrl(protocol, hostHeader, forwardedProtoHeader, forwardedHostHeader) {
|
||||
var url = '';
|
||||
if (forwardedProtoHeader) {
|
||||
url += forwardedProtoHeader;
|
||||
} else if (protocol) {
|
||||
url += protocol;
|
||||
} else {
|
||||
url += 'http';
|
||||
}
|
||||
url += '://';
|
||||
if (forwardedHostHeader) {
|
||||
url += forwardedHostHeader;
|
||||
} else if (hostHeader) {
|
||||
url += hostHeader;
|
||||
} else {
|
||||
url += origin.slice(0, -1);
|
||||
}
|
||||
return url;
|
||||
}
|
||||
function getBaseUrlByConnection(conn) {
|
||||
return getBaseUrl('', conn.headers['host'], conn.headers['x-forwarded-proto'], conn.headers['x-forwarded-host']);
|
||||
}
|
||||
|
||||
function sendData(conn, data) {
|
||||
conn.write(JSON.stringify(data));
|
||||
}
|
||||
function sendDataWarning(conn, msg) {
|
||||
sendData(conn, {type: "warning", message: msg});
|
||||
}
|
||||
function sendDataMessage(conn, msg) {
|
||||
sendData(conn, {type: "message", messages: msg});
|
||||
}
|
||||
|
||||
sockjs_echo.on('connection', function(conn) {
|
||||
console.log("ooserver in connection");
|
||||
if (null == conn) {
|
||||
console.log("null == conn");
|
||||
return;
|
||||
}
|
||||
conn.baseUrl = getBaseUrlByConnection(conn);
|
||||
console.log("BaseUrl: " + conn.baseUrl);
|
||||
conn.sessionIsSendWarning = false;
|
||||
conn.sessionTimeConnect = conn.sessionTimeLastAction = new Date().getTime();
|
||||
console.log("ooserver setting handlers");
|
||||
conn.on('data', function(message) {
|
||||
console.log("In data");
|
||||
return co(function* () {
|
||||
try {
|
||||
console.log("Received: " + message);
|
||||
var data = JSON.parse(message);
|
||||
switch (data.type) {
|
||||
case 'auth':
|
||||
console.log("Response auth");
|
||||
var fileUrl = origin + "oodoc/test.bin";
|
||||
if (data.openCmd.format=="xlsx")
|
||||
fileUrl = origin + "oocell/test.bin"
|
||||
else if (data.openCmd.format=="pptx")
|
||||
fileUrl = origin + "ooslide/test.bin"
|
||||
sendData(conn, {"type":"auth","result":1,"sessionId":"08e77705-dc5c-477d-b73a-b1a7cbca1e9b","sessionTimeConnect":1494226099270,"participants":[]});
|
||||
sendData(conn, {"type":"documentOpen","data":{"type":"open","status":"ok","data":{"Editor.bin":fileUrl}}});
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} catch (e) {
|
||||
console.log("error receiving response: docId = %s type = %s\r\n%s", docId, (data && data.type) ? data.type : 'null', e.stack);
|
||||
function getBaseUrl(protocol, hostHeader, forwardedProtoHeader, forwardedHostHeader) {
|
||||
var url = '';
|
||||
if (forwardedProtoHeader) {
|
||||
url += forwardedProtoHeader;
|
||||
} else if (protocol) {
|
||||
url += protocol;
|
||||
} else {
|
||||
url += 'http';
|
||||
}
|
||||
});
|
||||
});
|
||||
conn.on('error', function() {
|
||||
console.log("On error");
|
||||
});
|
||||
conn.on('close', function() {
|
||||
return co(function* () {
|
||||
console.log("On close");
|
||||
});
|
||||
});
|
||||
console.log("ooserver sending welcome message");
|
||||
sendData(conn, {
|
||||
type: 'license',
|
||||
license: {
|
||||
type: 3,
|
||||
light: false,
|
||||
trial: false,
|
||||
rights: 1,
|
||||
buildVersion: "4.3.3",
|
||||
buildNumber: 4,
|
||||
branding: false
|
||||
}
|
||||
});
|
||||
});
|
||||
url += '://';
|
||||
if (forwardedHostHeader) {
|
||||
url += forwardedHostHeader;
|
||||
} else if (hostHeader) {
|
||||
url += hostHeader;
|
||||
} else {
|
||||
url += origin.slice(0, -1);
|
||||
}
|
||||
return url;
|
||||
}
|
||||
function getBaseUrlByConnection(conn) {
|
||||
return getBaseUrl('', conn.headers['host'], conn.headers['x-forwarded-proto'], conn.headers['x-forwarded-host']);
|
||||
}
|
||||
|
||||
sockjs_echo.installHandlers(server, {prefix: '/common/onlyoffice/doc/[0-9-.a-zA-Z_=]*/c', log: function(severity, message) {
|
||||
console.log(message);
|
||||
}});
|
||||
function sendData(conn, data) {
|
||||
conn.write(JSON.stringify(data));
|
||||
}
|
||||
//function sendDataWarning(conn, msg) { sendData(conn, {type: "warning", message: msg}); }
|
||||
//function sendDataMessage(conn, msg) { sendData(conn, {type: "message", messages: msg}); }
|
||||
|
||||
callbackFunction();
|
||||
sockjs_echo.on('connection', function(conn) {
|
||||
console.log("ooserver in connection");
|
||||
if (null === conn) {
|
||||
console.log("null == conn");
|
||||
return;
|
||||
}
|
||||
conn.baseUrl = getBaseUrlByConnection(conn);
|
||||
console.log("BaseUrl: " + conn.baseUrl);
|
||||
conn.sessionIsSendWarning = false;
|
||||
conn.sessionTimeConnect = conn.sessionTimeLastAction = new Date().getTime();
|
||||
console.log("ooserver setting handlers");
|
||||
conn.on('data', function(message) {
|
||||
console.log("In data");
|
||||
var data;
|
||||
try {
|
||||
console.log("Received: " + message);
|
||||
data = JSON.parse(message);
|
||||
switch (data.type) {
|
||||
case 'auth':
|
||||
console.log("Response auth");
|
||||
var fileUrl = origin + "oodoc/test.bin";
|
||||
|
||||
if (data.openCmd) {
|
||||
if (data.openCmd.format === "xlsx") {
|
||||
fileUrl = origin + "oocell/test.bin";
|
||||
} else if (data.openCmd.format === "pptx") {
|
||||
fileUrl = origin + "ooslide/test.bin";
|
||||
}
|
||||
}
|
||||
sendData(conn, {"type":"auth","result":1,"sessionId":"08e77705-dc5c-477d-b73a-b1a7cbca1e9b","sessionTimeConnect":1494226099270,"participants":[]});
|
||||
sendData(conn, {"type":"documentOpen","data":{"type":"open","status":"ok","data":{"Editor.bin":fileUrl}}});
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
//console.log("error receiving response: docId = %s type = %s\r\n%s", docId, (data && data.type) ? data.type : 'null', e.stack);
|
||||
}
|
||||
});
|
||||
conn.on('error', function() {
|
||||
console.log("On error");
|
||||
});
|
||||
conn.on('close', function() {
|
||||
console.log("On close");
|
||||
});
|
||||
console.log("ooserver sending welcome message");
|
||||
sendData(conn, {
|
||||
type: 'license',
|
||||
license: {
|
||||
type: 3,
|
||||
light: false,
|
||||
trial: false,
|
||||
rights: 1,
|
||||
buildVersion: "4.3.3",
|
||||
buildNumber: 4,
|
||||
branding: false
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
sockjs_echo.installHandlers(server, {prefix: '/common/onlyoffice/doc/[0-9-.a-zA-Z_=]*/c', log: function(severity, message) {
|
||||
console.log(message);
|
||||
}});
|
||||
|
||||
callbackFunction();
|
||||
};
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
"stream-to-pull-stream": "^1.7.2",
|
||||
"tweetnacl": "~0.12.2",
|
||||
"ws": "^1.0.1",
|
||||
"co": "^4.6.0",
|
||||
"sockjs": "^0.3.18"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
config = {
|
||||
/* globals DocsAPI */
|
||||
window.config = {
|
||||
"document": {
|
||||
"fileType": "xlsx",
|
||||
"key": "Khirz6zTPdfd7",
|
||||
|
@ -26,8 +27,8 @@ config = {
|
|||
}
|
||||
console.log("in change (remote)");
|
||||
},
|
||||
"onReady": function(evt) { console.log("in onReady"); },
|
||||
"onAppReady": function(evt) { console.log("in onAppReady"); },
|
||||
"onReady": function(/*evt*/) { console.log("in onReady"); },
|
||||
"onAppReady": function(/*evt*/) { console.log("in onAppReady"); },
|
||||
}
|
||||
};
|
||||
window.onbeforeunload = function () {
|
||||
|
@ -35,6 +36,5 @@ window.onbeforeunload = function () {
|
|||
if (ifr) { ifr.remove(); }
|
||||
};
|
||||
|
||||
|
||||
var docEditor = new DocsAPI.DocEditor("placeholder", config);
|
||||
window.docEditor = new DocsAPI.DocEditor("placeholder", window.config);
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
config = {
|
||||
/* globals DocsAPI */
|
||||
window.config = {
|
||||
"document": {
|
||||
"fileType": "docx",
|
||||
"key": "Khirz6zTPdfd7",
|
||||
|
@ -13,12 +14,11 @@ config = {
|
|||
}
|
||||
},
|
||||
"events": {
|
||||
"onDocumentStateChange": function(evt) { console.log("in change"); },
|
||||
"onReady": function(evt) { console.log("in onReady"); }
|
||||
"onDocumentStateChange": function (/* evt */) { console.log("in change"); },
|
||||
"onReady": function (/* evt */) { console.log("in onReady"); }
|
||||
}
|
||||
};
|
||||
window.onbeforeunload = null;
|
||||
|
||||
|
||||
var docEditor = new DocsAPI.DocEditor("placeholder", config);
|
||||
window.docEditor = new DocsAPI.DocEditor("placeholder", window.config);
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
config = {
|
||||
/* globals DocsAPI */
|
||||
window.config = {
|
||||
"document": {
|
||||
"fileType": "pptx",
|
||||
"key": "Khirz6zTPdfd7",
|
||||
|
@ -13,12 +14,12 @@ config = {
|
|||
}
|
||||
},
|
||||
"events": {
|
||||
"onDocumentStateChange": function(evt) { console.log("in change"); },
|
||||
"onReady": function(evt) { console.log("in onReady"); }
|
||||
"onDocumentStateChange": function (/* evt */) { console.log("in change"); },
|
||||
"onReady": function (/* evt */) { console.log("in onReady"); }
|
||||
}
|
||||
};
|
||||
window.onbeforeunload = null;
|
||||
|
||||
|
||||
var docEditor = new DocsAPI.DocEditor("placeholder", config);
|
||||
window.docEditor = new DocsAPI.DocEditor("placeholder", window.config);
|
||||
|
||||
|
|
Loading…
Reference in New Issue