diff options
author | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2021-02-23 12:35:58 +0300 |
---|---|---|
committer | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2021-03-17 19:17:52 +0300 |
commit | 24d06f86cfeea271483ea67629a1d57b46116c69 (patch) | |
tree | 982c6fb38f41282f408e4aeb0c73d458e5ff3761 /src | |
parent | 02db975e33afe5f077e9551805a7136315426fe3 (diff) |
Make sure we only load the public script on public pages
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/public.js | 7 | ||||
-rw-r--r-- | src/services/logger.js | 30 | ||||
-rw-r--r-- | src/utils/isPublicPage.js | 2 |
3 files changed, 36 insertions, 3 deletions
diff --git a/src/public.js b/src/public.js index 0fdc7cb..5d936a2 100644 --- a/src/public.js +++ b/src/public.js @@ -21,13 +21,14 @@ */ import { generateUrl } from '@nextcloud/router' +import logger from './services/logger' import canDownload from './utils/canDownload' import isPublicPage from './utils/isPublicPage' import isPdf from './utils/isPdf' import isSecureViewerAvailable from './utils/isSecureViewerAvailable' window.addEventListener('DOMContentLoaded', function() { - console.debug('Files_PDFViewer initialized for public page', { + logger.debug('Initializing for public page', { isPublicPage: isPublicPage(), canDownload: canDownload(), isSecureViewerAvailable: isSecureViewerAvailable(), @@ -56,7 +57,9 @@ window.addEventListener('DOMContentLoaded', function() { contentElmt.appendChild(viewerNode) footerElmt.style.display = 'none' } else { - console.error('Unable to inject the PDF Viewer') + logger.error('Unable to inject the PDF Viewer') } + } else { + logger.error('But this does not appear to be a public page') } }) diff --git a/src/services/logger.js b/src/services/logger.js new file mode 100644 index 0000000..47ef863 --- /dev/null +++ b/src/services/logger.js @@ -0,0 +1,30 @@ +/** + * @copyright Copyright (c) 2021 John Molakvoæ <skjnldsv@protonmail.com> + * + * @author John Molakvoæ <skjnldsv@protonmail.com> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +import { getLoggerBuilder } from '@nextcloud/logger' + +// Set up logger +const logger = getLoggerBuilder() + .setApp('Files_PDFViewer') + .detectUser() + .build() + +export default logger diff --git a/src/utils/isPublicPage.js b/src/utils/isPublicPage.js index 5ce9c89..4754d43 100644 --- a/src/utils/isPublicPage.js +++ b/src/utils/isPublicPage.js @@ -22,4 +22,4 @@ */ const isPublicElmt = document.getElementById('isPublic') -export default () => isPublicElmt && isPublicElmt.value === '1' +export default () => !!(isPublicElmt && isPublicElmt.value === '1') |