mirror of
https://github.com/cryptpad/cryptpad.git
synced 2026-09-12 19:49:59 +05:00
Fix issues with the store on NodeJS
This commit is contained in:
parent
c7d8750bc0
commit
0f74469b52
7
package-lock.json
generated
7
package-lock.json
generated
@ -4189,9 +4189,10 @@
|
||||
}
|
||||
},
|
||||
"node_modules/netflux-websocket": {
|
||||
"version": "1.2.1",
|
||||
"resolved": "https://registry.npmjs.org/netflux-websocket/-/netflux-websocket-1.2.1.tgz",
|
||||
"integrity": "sha512-8oQOyEyh0MCnifNIfyvkNXpEELlVRzDleRivRgsDGh+5ZDG109axweVZ0RIOIpkQmTZk4/xVsBk/oLXpMSWEOw=="
|
||||
"version": "1.2.2",
|
||||
"resolved": "https://registry.npmjs.org/netflux-websocket/-/netflux-websocket-1.2.2.tgz",
|
||||
"integrity": "sha512-sroG7pBW4QctLtgW55eYNLfzXTbwHBTp7jMXBcY2Dk043PFBL+dpymVgJJWvb2EEbxGFFoaoqc6a8M9w1hIYMQ==",
|
||||
"license": "LGPL-2.1"
|
||||
},
|
||||
"node_modules/node-releases": {
|
||||
"version": "2.0.18",
|
||||
|
||||
@ -36,7 +36,8 @@ getApi('config', ApiConfig => {
|
||||
Messages,
|
||||
Broadcast
|
||||
}).then((store) => {
|
||||
console.log(store);
|
||||
console.log('API added to global "CP"');
|
||||
globalThis.CP = store.api;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -14,7 +14,7 @@ const factory = (ApiConfig = {}) => {
|
||||
var path = ApiConfig.websocketPath || '/cryptpad_websocket';
|
||||
if (/^ws{1,2}:\/\//.test(path)) { return path; }
|
||||
|
||||
var l = new URL(origin || self?.location?.href);
|
||||
var l = new URL(origin || globalThis?.location?.href || ApiConfig.httpUnsafeOrigin);
|
||||
if (origin) {
|
||||
l.href = origin;
|
||||
}
|
||||
|
||||
@ -3,12 +3,53 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
(() => {
|
||||
const factory = function () {
|
||||
const factory = function (Channel, NodeWS) {
|
||||
let USE_MIN = false;
|
||||
|
||||
let path = '/common/worker.bundle.js?';
|
||||
if (USE_MIN) { path = '/common/worker.bundle.min.js?'; }
|
||||
|
||||
|
||||
const commands = {
|
||||
pad: {
|
||||
join: 'JOIN_PAD',
|
||||
leave: 'LEAVE_PAD',
|
||||
sendMsg: 'SEND_PAD_MSG',
|
||||
destroy: 'REMOVE_OWNED_CHANNEL',
|
||||
setMetadata: 'SET_PAD_METADATA',
|
||||
getMetadata: 'GET_PAD_METADATA'
|
||||
}
|
||||
};
|
||||
|
||||
const makeApi = (postMsg, msgEv, cb) => {
|
||||
Channel.create(msgEv, postMsg, chan => {
|
||||
const postMessage = (cmd, data, cb, opts) => {
|
||||
cb ||= () => {};
|
||||
chan.query(cmd, data, (err, res) => {
|
||||
if (err) { return void cb ({error: err}); }
|
||||
cb(res);
|
||||
}, opts);
|
||||
};
|
||||
const api = {};
|
||||
const make = (base, cmd) => {
|
||||
Object.keys(cmd).forEach(k => {
|
||||
const v = cmd[k];
|
||||
if (!v) { return; }
|
||||
if (typeof(v) === "string") {
|
||||
base[k] = (data, cb, opts) => {
|
||||
postMessage(v, data, cb, opts);
|
||||
};
|
||||
return;
|
||||
}
|
||||
base[k] = {};
|
||||
make(base[k], v);
|
||||
});
|
||||
};
|
||||
make(api, commands);
|
||||
cb(api);
|
||||
});
|
||||
};
|
||||
|
||||
let create = function (cfg = {}) {
|
||||
let { noWorker, noSharedWorker, AppConfig,
|
||||
ApiConfig, Messages, Broadcast } = cfg;
|
||||
@ -138,7 +179,12 @@ const factory = function () {
|
||||
Messages,
|
||||
Broadcast
|
||||
});
|
||||
resolve({postMsg, msgEv});
|
||||
|
||||
globalThis.WebSocket = NodeWS.WebSocket;
|
||||
|
||||
makeApi(postMsg, msgEv, api => {
|
||||
resolve({api});
|
||||
});
|
||||
};
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
@ -182,8 +228,11 @@ const factory = function () {
|
||||
|
||||
|
||||
if (typeof(module) !== 'undefined' && module.exports) {
|
||||
module.exports = factory();
|
||||
module.exports = factory(
|
||||
require('../../src/common/events-channel'),
|
||||
require('ws')
|
||||
);
|
||||
} else if ((typeof(define) !== 'undefined' && define !== null) && (define.amd !== null)) {
|
||||
define([], factory);
|
||||
define(['/common/events-channel.js'], factory);
|
||||
}
|
||||
})();
|
||||
|
||||
2
www/common/worker.bundle.min.js
vendored
2
www/common/worker.bundle.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user