diff --git a/helpers/publishHelpers.js b/helpers/publishHelpers.js index a14ce408..186fabec 100644 --- a/helpers/publishHelpers.js +++ b/helpers/publishHelpers.js @@ -135,7 +135,6 @@ module.exports = { // find any records where the name is used db.User.findAll({ where: { channelName: name } }) .then(result => { - logger.debug('sequelize result:', result); if (result.length >= 1) { return resolve(false); } diff --git a/public/assets/js/generalFunctions.js b/public/assets/js/generalFunctions.js index 4e5ba82c..0841822d 100644 --- a/public/assets/js/generalFunctions.js +++ b/public/assets/js/generalFunctions.js @@ -35,26 +35,6 @@ function createProgressBar(element, size){ setInterval(addOne, 300); } -function dataURItoBlob(dataURI) { - // convert base64/URLEncoded data component to raw binary data held in a string - var byteString; - if (dataURI.split(',')[0].indexOf('base64') >= 0) - byteString = atob(dataURI.split(',')[1]); - else - byteString = unescape(dataURI.split(',')[1]); - - // separate out the mime component - var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0]; - - // write the bytes of the string to a typed array - var ia = new Uint8Array(byteString.length); - for (var i = 0; i < byteString.length; i++) { - ia[i] = byteString.charCodeAt(i); - } - - return new Blob([ia], {type:mimeString}); -} - // Create new error objects, that prototypically inherit from the Error constructor function FileError(message) { this.name = 'FileError'; @@ -70,4 +50,12 @@ function NameError(message) { this.stack = (new Error()).stack; } NameError.prototype = Object.create(Error.prototype); -NameError.prototype.constructor = NameError; \ No newline at end of file +NameError.prototype.constructor = NameError; + +function ChannelError(message) { + this.name = 'ChannelError'; + this.message = message || 'Default Message'; + this.stack = (new Error()).stack; +} +ChannelError.prototype = Object.create(Error.prototype); +ChannelError.prototype.constructor = ChannelError; \ No newline at end of file diff --git a/public/assets/js/publishFunctions.js b/public/assets/js/publishFunctions.js index 552ecd0d..cef074eb 100644 --- a/public/assets/js/publishFunctions.js +++ b/public/assets/js/publishFunctions.js @@ -19,7 +19,7 @@ function previewAndStageFile(selectedFile){ showError('input-error-file-selection', error.message); return; } - // set the image preview, if a preview was provided + // set the image preview, if an image was provided if (selectedFile.type !== 'video/mp4') { previewReader.readAsDataURL(selectedFile); previewReader.onloadend = function () { @@ -41,18 +41,22 @@ function previewAndStageFile(selectedFile){ // Validate the publish submission and then trigger publishing. function publishSelectedImage(event) { event.preventDefault(); - var name = document.getElementById('claim-name-input').value; - validateSubmission(stagedFiles, name) + var claimName = document.getElementById('claim-name-input').value; + var channelName = document.getElementById('channel-name-select').value; + validateSubmission(stagedFiles, claimName, channelName) .then(function() { uploader.submitFiles(stagedFiles); }) .catch(function(error) { - if (error.name === 'FileError'){ - showError('input-error-file-selection', error.message); + if (error.name === 'FileError') { + showError(document.getElementById('input-error-file-selection'), error.message); } else if (error.name === 'NameError') { - showError('input-error-claim-name', error.message); + showError(document.getElementById('input-error-claim-name'), error.message); + } else if (error.name === 'ChannelError'){ + console.log(error); + showError(document.getElementById('input-error-channel-select'), error.message); } else { - showError('input-error-publish-submit', error.message); + showError(document.getElementById('input-error-publish-submit'), error.message); } return; }) diff --git a/public/assets/js/validationFunctions.js b/public/assets/js/validationFunctions.js index 2f180822..cfd0c780 100644 --- a/public/assets/js/validationFunctions.js +++ b/public/assets/js/validationFunctions.js @@ -113,39 +113,44 @@ function checkAvailability(name, successDisplayElement, errorDisplayElement, isN } function checkClaimName(name){ - const successDisplayElement = document.getElementById('claim-name-success'); - const errorDisplayElement = document.getElementById('claim-name-error'); + const successDisplayElement = document.getElementById('input-success-claim-name'); + const errorDisplayElement = document.getElementById('input-error-claim-name'); checkAvailability(name, successDisplayElement, errorDisplayElement, isNameAvailable, '/api/isClaimAvailable/'); } function checkChannelName(name){ - const successDisplayElement = document.getElementById('channel-name-success'); - const errorDisplayElement = document.getElementById('channel-name-error'); + const successDisplayElement = document.getElementById('input-success-channel-name'); + const errorDisplayElement = document.getElementById('input-error-channel-name'); checkAvailability(name, successDisplayElement, errorDisplayElement, isNameAvailable, '/api/isChannelAvailable/'); } // validation function which checks all aspects of the publish submission -function validateSubmission(stagedFiles, name){ +function validateSubmission(stagedFiles, claimName, channelName){ return new Promise(function (resolve, reject) { - // make sure only 1 file was selected + // 1. make sure only 1 file was selected if (!stagedFiles) { reject(new FileError("Please select a file")); } else if (stagedFiles.length > 1) { reject(new FileError("Only one file is allowed at a time")); } - // validate the file's name, type, and size + // 2. validate the file's name, type, and size try { validateFile(stagedFiles[0]); } catch (error) { reject(error); } - // make sure the claim name has not already been used + // 3. validate that a channel was chosen + if (channelName === 'new') { + reject(new ChannelError("Please select a valid channel")); + }; + // 4. validate the claim name try { - validateClaimName(name); + validateClaimName(claimName); // validate the formatting } catch (error) { reject(error); } - isNameAvailable(name) + console.log(claimName); + isNameAvailable(claimName, '/api/isClaimAvailable/') // validate the availability .then(function() { resolve(); }) diff --git a/views/index.handlebars b/views/index.handlebars index 5a78a2b1..7607a81a 100644 --- a/views/index.handlebars +++ b/views/index.handlebars @@ -24,12 +24,14 @@ var description = document.getElementById('publish-description').value; var license = document.getElementById('publish-license').value; var nsfw = document.getElementById('publish-nsfw').checked; + var channel = document.getElementById('channel-name-select').value; event.file.meta.name = name; event.file.meta.title = title; event.file.meta.description = description; event.file.meta.license = license; event.file.meta.nsfw = nsfw; event.file.meta.type = stagedFiles[0].type; + event.file.meta.channel = channel; // re-set the html in the publish area document.getElementById('publish-active-area').innerHTML = '
'; // start a progress animation @@ -54,7 +56,7 @@ }); socket.on('publish-complete', function(msg){ var publishResults; - var showUrl = msg.name + '/' + msg.result.claim_id; + var showUrl = msg.result.claim_id + "/" + msg.name; // build new publish area publishResults = '

Your publish is complete! You are being redirected to it now.

'; publishResults += '

If you do not get redirected, click here.

'; diff --git a/views/partials/publishChannel.handlebars b/views/partials/publishChannel.handlebars index cd3b2356..f5e33615 100644 --- a/views/partials/publishChannel.handlebars +++ b/views/partials/publishChannel.handlebars @@ -1,8 +1,8 @@
- +

- - {{#if user}} {{/if}} @@ -12,23 +12,19 @@

-