diff --git a/www/code/main.js b/www/code/main.js index 6e0270285..0686a61b9 100644 --- a/www/code/main.js +++ b/www/code/main.js @@ -173,7 +173,7 @@ define([ var titleCfg = { getHeadingText: CodeMirror.getHeadingText }; Title = Cryptpad.createTitle(titleCfg, config.onLocal, Cryptpad); - Metadata = Cryptpad.createMetadata(UserList, Title); + Metadata = Cryptpad.createMetadata(UserList, Title, null, Cryptpad); var configTb = { displayed: ['title', 'useradmin', 'spinner', 'lag', 'state', 'share', 'userlist', 'newpad', 'limit', 'upgrade'], @@ -308,7 +308,8 @@ define([ if(userDoc !== "") { var hjson = JSON.parse(userDoc); - if (typeof (hjson) !== 'object' || Array.isArray(hjson)) { + if (typeof (hjson) !== 'object' || Array.isArray(hjson) || + (typeof(hjson.type) !== 'undefined' && hjson.type !== 'code')) { var errorText = Messages.typeError; Cryptpad.errorLoadingScreen(errorText); throw new Error(errorText); diff --git a/www/common/common-metadata.js b/www/common/common-metadata.js index d5487901c..99115fac6 100644 --- a/www/common/common-metadata.js +++ b/www/common/common-metadata.js @@ -1,7 +1,7 @@ define(function () { var module = {}; - module.create = function (UserList, Title, cfg) { + module.create = function (UserList, Title, cfg, Cryptpad) { var exp = {}; exp.update = function (shjson) { @@ -15,6 +15,14 @@ define(function () { metadata = json.metadata; } if (typeof metadata === "object") { + if (Cryptpad) { + if (typeof(metadata.type) === 'undefined') { + // initialize pad type by location.pathname + metadata.type = Cryptpad.getAppType(); + } + } else { + console.log("Cryptpad should exist but it does not"); + } if (metadata.users) { var userData = metadata.users; // Update the local user data diff --git a/www/common/common-util.js b/www/common/common-util.js index 0bc53f5dd..242ae6fc8 100644 --- a/www/common/common-util.js +++ b/www/common/common-util.js @@ -139,5 +139,12 @@ define([], function () { return Math.floor(Math.random() * Number.MAX_SAFE_INTEGER); }; + Util.getAppType = function () { + var parts = window.location.pathname.split('/') + .filter(function (x) { return x; }); + if (!parts[0]) { return ''; } + return parts[0]; + }; + return Util; }); diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index fb19e0f52..424c5bf52 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -83,6 +83,7 @@ define([ common.fetch = Util.fetch; common.throttle = Util.throttle; common.createRandomInteger = Util.createRandomInteger; + common.getAppType = Util.getAppType; // import hash utilities for export var createRandomHash = common.createRandomHash = Hash.createRandomHash; @@ -906,18 +907,12 @@ define([ common.getPinnedUsage(todo); }; - var getAppSuffix = function () { - var parts = window.location.pathname.split('/') - .filter(function (x) { return x; }); - - if (!parts[0]) { return ''; } - return '_' + parts[0].toUpperCase(); - }; - var prepareFeedback = common.prepareFeedback = function (key) { if (typeof(key) !== 'string') { return $.noop; } + + var type = common.getAppType(); return function () { - feedback(key.toUpperCase() + getAppSuffix()); + feedback((key + (type? '_' + type: '')).toUpperCase()); }; }; diff --git a/www/pad/main.js b/www/pad/main.js index 6538f0222..7a9ea059f 100644 --- a/www/pad/main.js +++ b/www/pad/main.js @@ -306,7 +306,8 @@ define([ hjson[3] = { metadata: { users: UserList.userData, - defaultTitle: Title.defaultTitle + defaultTitle: Title.defaultTitle, + type: 'pad' } }; if (!initializing) { @@ -450,7 +451,7 @@ define([ var titleCfg = { getHeadingText: getHeadingText }; Title = Cryptpad.createTitle(titleCfg, realtimeOptions.onLocal, Cryptpad); - Metadata = Cryptpad.createMetadata(UserList, Title); + Metadata = Cryptpad.createMetadata(UserList, Title, null, Cryptpad); var configTb = { displayed: ['title', 'useradmin', 'spinner', 'lag', 'state', 'share', 'userlist', 'newpad', 'limit', 'upgrade'], diff --git a/www/poll/main.js b/www/poll/main.js index adfe60ec3..0948ec8b4 100644 --- a/www/poll/main.js +++ b/www/poll/main.js @@ -430,6 +430,7 @@ define([ }); proxy.version = 1; + proxy.type = 'poll'; }; /* @@ -475,6 +476,16 @@ var ready = function (info, userid, readOnly) { var userDoc = JSON.stringify(proxy); if (userDoc === "" || userDoc === "{}") { isNew = true; } + if (!isNew && typeof(proxy.type) !== 'undefined' && proxy.type !== 'poll') { + var errorText = Messages.typeError; + Cryptpad.errorLoadingScreen(errorText); + throw new Error(errorText); + } + + if (typeof(proxy.type) === 'undefined') { + proxy.type = 'poll'; + } + var uncommitted = APP.uncommitted = {}; prepareProxy(proxy, copyObject(Render.Example)); prepareProxy(uncommitted, copyObject(Render.Example)); diff --git a/www/slide/main.js b/www/slide/main.js index 9ea3925e9..6ac477e45 100644 --- a/www/slide/main.js +++ b/www/slide/main.js @@ -343,7 +343,7 @@ define([ }; Title = Cryptpad.createTitle(titleCfg, config.onLocal, Cryptpad); - Metadata = Cryptpad.createMetadata(UserList, Title, metadataCfg); + Metadata = Cryptpad.createMetadata(UserList, Title, metadataCfg, Cryptpad); var configTb = { displayed: ['title', 'useradmin', 'spinner', 'lag', 'state', 'share', 'userlist', 'newpad', 'limit', 'upgrade'], @@ -557,7 +557,8 @@ define([ var hjson = JSON.parse(userDoc); newDoc = hjson.content; - if (typeof (hjson) !== 'object' || Array.isArray(hjson)) { + if (typeof (hjson) !== 'object' || Array.isArray(hjson) || + (typeof(hjson.type) !== 'undefined' && hjson.type !== 'slide')) { var errorText = Messages.typeError; Cryptpad.errorLoadingScreen(errorText); throw new Error(errorText); diff --git a/www/whiteboard/main.js b/www/whiteboard/main.js index 1949549af..c399d5c3f 100644 --- a/www/whiteboard/main.js +++ b/www/whiteboard/main.js @@ -293,7 +293,7 @@ window.canvas = canvas; Title = Cryptpad.createTitle({}, config.onLocal, Cryptpad); - Metadata = Cryptpad.createMetadata(UserList, Title, metadataCfg); + Metadata = Cryptpad.createMetadata(UserList, Title, metadataCfg, Cryptpad); var configTb = { displayed: ['title', 'useradmin', 'spinner', 'lag', 'state', 'share', 'userlist', 'newpad', 'limit', 'upgrade'], @@ -384,7 +384,8 @@ window.canvas = canvas; metadata: { users: UserList.userData, palette: palette, - defaultTitle: Title.defaultTitle + defaultTitle: Title.defaultTitle, + type: 'whiteboard', } }; if (!initializing) { @@ -413,6 +414,14 @@ window.canvas = canvas; var isNew = false; var userDoc = module.realtime.getUserDoc(); if (userDoc === "" || userDoc === "{}") { isNew = true; } + else { + var hjson = JSON.parse(userDoc); + if (typeof(hjson) !== 'object' || Array.isArray(hjson) || + (typeof(hjson.type) !== 'undefined' && hjson.type !== whiteboard)) { + Cryptpad.errorLoadingScreen(Messages.typeError); + throw new Error(Messages.typeError); + } + } Cryptpad.removeLoadingScreen(); setEditable(true);