From 329d03743151602e3014932ff16585c8a9f80132 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Mon, 12 Apr 2021 17:57:44 -0400 Subject: [PATCH] Simplify read-only pad ID checks --- src/node/db/ReadOnlyManager.js | 4 ++-- src/node/hooks/express/specialpages.js | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/node/db/ReadOnlyManager.js b/src/node/db/ReadOnlyManager.js index 5dabe2e06..0b8d29171 100644 --- a/src/node/db/ReadOnlyManager.js +++ b/src/node/db/ReadOnlyManager.js @@ -28,7 +28,7 @@ const randomString = require('../utils/randomstring'); * checks if the id pattern matches a read-only pad id * @param {String} the pad's id */ -exports.isReadOnlyId = (id) => id.indexOf('r.') === 0; +exports.isReadOnlyId = (id) => id.startsWith('r.'); /** * returns a read only id for a pad @@ -59,7 +59,7 @@ exports.getPadId = (readOnlyId) => db.get(`readonly2pad:${readOnlyId}`); * @param {String} padIdOrReadonlyPadId read only id or real pad id */ exports.getIds = async (id) => { - const readonly = (id.indexOf('r.') === 0); + const readonly = exports.isReadOnlyId(id); // Might be null, if this is an unknown read-only id const readOnlyPadId = readonly ? id : await exports.getReadOnlyId(id); diff --git a/src/node/hooks/express/specialpages.js b/src/node/hooks/express/specialpages.js index c1e3fec99..f55180888 100644 --- a/src/node/hooks/express/specialpages.js +++ b/src/node/hooks/express/specialpages.js @@ -46,8 +46,7 @@ exports.expressCreateServer = (hookName, args, cb) => { // serve pad.html under /p args.app.get('/p/:pad', (req, res, next) => { // The below might break for pads being rewritten - const isReadOnly = - req.url.indexOf('/p/r.') === 0 || !webaccess.userCanModify(req.params.pad, req); + const isReadOnly = !webaccess.userCanModify(req.params.pad, req); hooks.callAll('padInitToolbar', { toolbar,