From 9a93b3cc8df4da022717c425c86abffa643c5a3b Mon Sep 17 00:00:00 2001 From: bill bittner Date: Fri, 15 Dec 2017 11:02:04 -0800 Subject: [PATCH] tested basic client scenarios --- helpers/publishHelpers.js | 14 +++++--------- public/assets/js/publishFileFunctions.js | 11 +++++++---- routes/api-routes.js | 1 + 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/helpers/publishHelpers.js b/helpers/publishHelpers.js index 7e0cd904..65370250 100644 --- a/helpers/publishHelpers.js +++ b/helpers/publishHelpers.js @@ -58,19 +58,15 @@ module.exports = { }, parsePublishApiChannel ({channelName, channelPassword}, user) { logger.debug('publish api parser input:', {channelName, channelPassword, user}); - // if no channel name provided, publish will be anonymous // if anonymous or '' provided, publish will be anonymous (even if client is logged in) - if (channelName === 'anonymous' || channelName === '') { - channelName = null; - } // if a channel name is provided... if (channelName) { - // make sure a password was provided - if (!channelPassword) { - throw new Error('Channel name provided without password'); + // make sure a password was provided if no user token is provided + if (!user && !channelPassword) { + throw new Error('Unauthenticated channel name provided without password'); } - // if request comes from the client and is logged in - // ensure it is the same channel and get the password + // if request comes from the client with a token + // ensure this publish uses that channel name if (user) { channelName = user.channelName; } ; diff --git a/public/assets/js/publishFileFunctions.js b/public/assets/js/publishFileFunctions.js index 15a4c5a9..f1255d70 100644 --- a/public/assets/js/publishFileFunctions.js +++ b/public/assets/js/publishFileFunctions.js @@ -78,17 +78,20 @@ const publishFileFunctions = { const licenseInput = document.getElementById('publish-license'); const nsfwInput = document.getElementById('publish-nsfw'); const thumbnailInput = document.getElementById('claim-thumbnail-input'); - - return { + const channelName = this.returnNullOrChannel(); + let metadata = { name: nameInput.value.trim(), - channelName: this.returnNullOrChannel(), title: titleInput.value.trim(), description: descriptionInput.value.trim(), license: licenseInput.value.trim(), nsfw: nsfwInput.checked, type: stagedFiles[0].type, thumbnail: thumbnailInput.value.trim(), + }; + if (channelName) { + metadata['channelName'] = channelName; } + return metadata; }, appendDataToFormData: function (file, metadata) { var fd = new FormData(); @@ -143,7 +146,7 @@ const publishFileFunctions = { publishStagedFile: function (event) { event.preventDefault(); // prevent default so this script can handle submission const metadata = this.createMetadata(); - const that = this; // note: necessary ? + const that = this; const fileSelectionInputError = document.getElementById('input-error-file-selection'); const claimNameError = document.getElementById('input-error-claim-name'); const channelSelectError = document.getElementById('input-error-channel-select'); diff --git a/routes/api-routes.js b/routes/api-routes.js index 57414bcf..9df1bcb9 100644 --- a/routes/api-routes.js +++ b/routes/api-routes.js @@ -125,6 +125,7 @@ module.exports = (app) => { }); // route to run a publish request on the daemon app.post('/api/claim-publish', multipartMiddleware, ({ body, files, ip, originalUrl, user }, res) => { + logger.debug('api/claim-publish body:', body); let name, fileName, filePath, fileType, nsfw, license, title, description, thumbnail, channelName, channelPassword; // validate the body and files of the request try {