mirror of
https://github.com/cryptpad/cryptpad.git
synced 2026-09-14 11:05:41 +05:00
wip
This commit is contained in:
parent
5607094429
commit
958d0df5b9
File diff suppressed because one or more lines are too long
@ -1 +1 @@
|
||||
I1M7/VtyN5OGut+vhPCtxW2sxbuyZ8vWkoORdeqG6DD4hY7HutC3iyYPJkk6G+m6vhgQPRQqMdUNIzCuFoIPAls4LCJKMkp5c0l2QmRWZFBweVdWSWNvYkc0SXJIZWozYmU0a3lhWDV3UE1ORFlnPSJd
|
||||
Rhh17W2AanNizL7Vj3CEMUHsjvXxva7xUw+oBe15lWneW2plyLPxflW68Cb0XNcOdF1EpgbLR9REmQQVWVHxAVsxNSwiMWxnZDZSTjI4YURUaUl2MngxNm96WTQzSW1MS01OYUl6VzJ5V2M5UlczMD0iXQ==
|
||||
@ -1,8 +1,7 @@
|
||||
// This is stage 1, it can be changed but you must bump the version of the project.
|
||||
define([
|
||||
'/common/requireconfig.js',
|
||||
'/api/config'
|
||||
], function (RequireConfig, ApiConfig) {
|
||||
'/common/requireconfig.js'
|
||||
], function (RequireConfig) {
|
||||
require.config(RequireConfig());
|
||||
|
||||
// most of CryptPad breaks if you don't support isArray
|
||||
@ -27,14 +26,6 @@ define([
|
||||
Number.MAX_SAFE_INTEGER = 9007199254740991;
|
||||
}
|
||||
|
||||
if (!ApiConfig.httpSafeOrigin) {
|
||||
if (ApiConfig.httpSafePort) {
|
||||
ApiConfig.httpSafeOrigin =
|
||||
window.location.origin.replace(/\:[0-9]+$/, ':' + ApiConfig.httpSafePort);
|
||||
}
|
||||
ApiConfig.httpSafeOrigin = window.location.origin;
|
||||
}
|
||||
|
||||
var failStore = function () {
|
||||
console.error(new Error('wut'));
|
||||
require(['jquery'], function ($) {
|
||||
|
||||
24
www/common/config.js
Normal file
24
www/common/config.js
Normal file
@ -0,0 +1,24 @@
|
||||
/*@flow*/
|
||||
/*::const define = (x)=>{};*/
|
||||
(function () {
|
||||
var apiConf = window.CRYPTPAD_APICONF;
|
||||
var manHash = window.CRYPTPAD_MANIFEST_HASH;
|
||||
if (!apiConf) {
|
||||
return void define(['/api/config'], function (x) { return x; });
|
||||
}
|
||||
define(function () {
|
||||
console.log('x');
|
||||
apiConf = apiConf || window.CRYPTPAD_APICONF;
|
||||
manHash = manHash || window.CRYPTPAD_MANIFEST_HASH;
|
||||
var cfg = JSON.parse(apiConf);
|
||||
cfg.manifestHash = cfg.manifestHash || manHash;
|
||||
if (!cfg.httpSafeOrigin) {
|
||||
if (cfg.httpSafePort) {
|
||||
cfg.httpSafeOrigin =
|
||||
window.location.origin.replace(/\:[0-9]+$/, ':' + cfg.httpSafePort);
|
||||
}
|
||||
cfg.httpSafeOrigin = window.location.origin;
|
||||
}
|
||||
return cfg;
|
||||
});
|
||||
}());
|
||||
@ -1,5 +1,5 @@
|
||||
define([
|
||||
'/api/config'
|
||||
'/common/config.js'
|
||||
], function (ApiConfig) {
|
||||
var out = {
|
||||
// fix up locations so that relative urls work.
|
||||
|
||||
@ -51,6 +51,8 @@
|
||||
node.setAttribute('integrity', 'sha256-' + hash);
|
||||
};
|
||||
window.require.config(Config.requireConf);
|
||||
|
||||
// TODO: this is crap
|
||||
window.define('/api/config', function () { return JSON.parse(ConfigS); });
|
||||
window.require(['/common/boot2.js']);
|
||||
}
|
||||
@ -58,6 +60,7 @@
|
||||
};
|
||||
var two = function () {
|
||||
if (!(Nacl && ConfigS)) { return; }
|
||||
window.CRYPTPAD_APICONF = ConfigS;
|
||||
Config = JSON.parse(ConfigS);
|
||||
var key = Nacl.util.decodeBase64(PUBLIC_KEY);
|
||||
var buf = Nacl.util.decodeBase64(Config.versionSig);
|
||||
@ -72,7 +75,8 @@
|
||||
}
|
||||
localStorage['CRYPTPAD_SBOOT_VERSION'] = data[0];
|
||||
window.defineManifest = three;
|
||||
script("/customize/manifest.js?ver=" + encodeURIComponent(data[1]), data[1]);
|
||||
var manifestHash = window.CRYPTPAD_MANIFEST_HASH = data[1];
|
||||
script("/customize/manifest.js?ver=" + encodeURIComponent(manifestHash), manifestHash);
|
||||
};
|
||||
script(
|
||||
'/bower_components/tweetnacl/nacl-fast.min.js?ver=' + encodeURIComponent(NACL_HASH),
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
// Load #1, load as little as possible because we are in a race to get the loading screen up.
|
||||
define([
|
||||
'/bower_components/nthen/index.js',
|
||||
'/api/config',
|
||||
'/common/config.js',
|
||||
'/common/dom-ready.js',
|
||||
'/common/requireconfig.js',
|
||||
'/common/sframe-common-outer.js'
|
||||
@ -14,7 +14,8 @@ define([
|
||||
var req = {
|
||||
cfg: requireConfig,
|
||||
req: [ '/common/loading.js' ],
|
||||
pfx: window.location.origin
|
||||
pfx: window.location.origin,
|
||||
apiConfS: JSON.stringify(ApiConfig)
|
||||
};
|
||||
window.rc = requireConfig;
|
||||
window.apiconf = ApiConfig;
|
||||
|
||||
101
www/common/sframe-sboot.js
Normal file
101
www/common/sframe-sboot.js
Normal file
@ -0,0 +1,101 @@
|
||||
// Stage 0, this gets cached which means we can't change it. boot2-sframe.js is changable.
|
||||
// Note that this file is meant to be executed only inside of a sandbox iframe.
|
||||
//
|
||||
// IF YOU EDIT THIS FILE, bump the version (replace 1.3 in the following command with the next version.)
|
||||
// grep -nr '/common/sframe-boot.js?ver=' | sed 's/:.*$//' | grep -v 'sframe-boot.js' | while read x; do \
|
||||
// sed -i -e 's@/common/sframe-boot.js?ver=[^"]*@/common/sframe-boot.js?ver=1.3@' $x; done
|
||||
;(function () {
|
||||
var afterLoaded = function (req) {
|
||||
req.cfg = req.cfg || {};
|
||||
window.CRYPTPAD_APICONF = req.apiConfS;
|
||||
var apiConfig = JSON.parse(req.apiConfS);
|
||||
window.CRYPTPAD_MANIFEST_HASH = apiConfig.manifestHash;
|
||||
var manifest = { files: { customize: { "manifest.js": apiConfig.manifestHash } } };
|
||||
req.cfg.onNodeCreated = function (node /*, config, module, path*/) {
|
||||
var src = node.getAttribute('src');
|
||||
var hash = manifest.files;
|
||||
var path = src.replace(/\?.*$/, '').split('/');
|
||||
path.shift(); // leading /
|
||||
for (var i = 0; i < path.length; i++) {
|
||||
var next = hash[path[i]];
|
||||
if (!next) { throw new Error("no entry in manifest for " + src); }
|
||||
hash = next;
|
||||
}
|
||||
if (typeof(hash) !== 'string') { throw new Error("no entry in manifest for " + src); }
|
||||
var newSrc = src.replace(/([\?\&])ver=[^\?\&]*([\?\&])?/, function (all, begin, end) {
|
||||
return begin + 'ver=' + encodeURIComponent(hash) + (end || '');
|
||||
});
|
||||
if (req.pfx) { newSrc = req.pfx + newSrc; }
|
||||
node.setAttribute('src', newSrc);
|
||||
node.setAttribute('integrity', 'sha256-' + hash);
|
||||
};
|
||||
require.config(req.cfg);
|
||||
var txid = Math.random().toString(16).replace('0.', '');
|
||||
var intr;
|
||||
var ready = function () {
|
||||
intr = setInterval(function () {
|
||||
if (typeof(txid) !== 'string') { return; }
|
||||
window.parent.postMessage(JSON.stringify({ q: 'READY', txid: txid }), '*');
|
||||
}, 1);
|
||||
};
|
||||
require(['/customize/manifest.js'], function (m) {
|
||||
manifest = m;
|
||||
if (req.req) { require(req.req, ready); } else { ready(); }
|
||||
});
|
||||
var onReply = function (msg) {
|
||||
var data = JSON.parse(msg.data);
|
||||
if (data.txid !== txid) { return; }
|
||||
clearInterval(intr);
|
||||
txid = {};
|
||||
window.removeEventListener('message', onReply);
|
||||
data.cache = data.cache || {};
|
||||
var updated = {};
|
||||
window.cryptpadCache = {
|
||||
get: function (k, cb) {
|
||||
setTimeout(function () { cb(data.cache[k]); });
|
||||
},
|
||||
put: function (k, v, cb) {
|
||||
cb = cb || function () { };
|
||||
updated[k] = v;
|
||||
setTimeout(function () { data.cache[k] = v; cb(); });
|
||||
},
|
||||
updated: updated,
|
||||
cache: data.cache
|
||||
};
|
||||
data.localStore = data.localStore || {};
|
||||
var lsUpdated = {};
|
||||
window.cryptpadStore = {
|
||||
get: function (k, cb) {
|
||||
setTimeout(function () { cb(data.localStore[k]); });
|
||||
},
|
||||
getAll: function (cb) {
|
||||
setTimeout(function () {
|
||||
cb(JSON.parse(JSON.stringify(data.localStore)));
|
||||
});
|
||||
},
|
||||
put: function (k, v, cb) {
|
||||
cb = cb || function () { };
|
||||
lsUpdated[k] = v;
|
||||
setTimeout(function () { data.localStore[k] = v; cb(); });
|
||||
},
|
||||
updated: lsUpdated,
|
||||
store: data.localStore
|
||||
};
|
||||
window.cryptpadLanguage = data.language;
|
||||
require(['/common/sframe-boot2.js'], function () { });
|
||||
};
|
||||
window.addEventListener('message', onReply);
|
||||
};
|
||||
|
||||
var load0 = function () {
|
||||
try {
|
||||
var req = JSON.parse(decodeURIComponent(window.location.hash.substring(1)));
|
||||
afterLoaded(req);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
setTimeout(load0, 100);
|
||||
}
|
||||
};
|
||||
load0();
|
||||
|
||||
}());
|
||||
Loading…
Reference in New Issue
Block a user