From 8856ee5d0eae4498c10dc251115ad2c493766a75 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Thu, 12 Oct 2017 13:10:44 -0700 Subject: [PATCH] fixed call-stack-exceeded error issue --- controllers/publishController.js | 3 +- helpers/publishHelpers.js | 5 +- public/assets/css/general.css | 19 ++-- routes/sockets-routes.js | 5 +- views/index.handlebars | 149 +++++++++++++++++++------------ 5 files changed, 114 insertions(+), 67 deletions(-) diff --git a/controllers/publishController.js b/controllers/publishController.js index 5b7eb94e..d98d0534 100644 --- a/controllers/publishController.js +++ b/controllers/publishController.js @@ -8,7 +8,7 @@ module.exports = { return new Promise((resolve, reject) => { let publishResults = {}; // 1. publish the file - lbryApi.publishClaim(publishParams) + return lbryApi.publishClaim(publishParams) // 2. upsert File record (update is in case the claim has been published before by this daemon) .then(tx => { logger.info(`Successfully published ${fileName}`, tx); @@ -67,6 +67,7 @@ module.exports = { resolve(publishResults); // resolve the promise with the result from lbryApi.publishClaim; }) .catch(error => { + logger.error('publishController.publish, error', error); publishHelpers.deleteTemporaryFile(publishParams.file_path); // delete the local file reject(error); }); diff --git a/helpers/publishHelpers.js b/helpers/publishHelpers.js index 00a42ff8..e889eb65 100644 --- a/helpers/publishHelpers.js +++ b/helpers/publishHelpers.js @@ -152,7 +152,10 @@ module.exports = { }, deleteTemporaryFile (filePath) { fs.unlink(filePath, err => { - if (err) throw err; + if (err) { + logger.error(`error deleting temporary file ${filePath}`); + throw err; + } logger.debug(`successfully deleted ${filePath}`); }); }, diff --git a/public/assets/css/general.css b/public/assets/css/general.css index 0fb6e166..c4219ddf 100644 --- a/public/assets/css/general.css +++ b/public/assets/css/general.css @@ -202,7 +202,8 @@ h3 { } /* ALIGNMENT */ -.align-content-left { +. +align-content-left { text-align: left; } @@ -222,6 +223,14 @@ h3 { vertical-align: bottom; } +.align-content-vcenter-hcenter { + position: absolute; + top: 40%; + left: 50%; + transform: translateX(-50%) translateY(-40%); +} + + /* ERROR MESSAGES */ . info-message { @@ -473,10 +482,10 @@ table { } #primary-dropzone-instructions, #preview-dropzone-instructions { - position: absolute; - top: 40%; - left: 50%; - transform: translateX(-50%) translateY(-40%); + /*position: absolute;*/ + /*top: 40%;*/ + /*left: 50%;*/ + /*transform: translateX(-50%) translateY(-40%);*/ } #asset-preview { diff --git a/routes/sockets-routes.js b/routes/sockets-routes.js index 116cdc0a..8f5a1316 100644 --- a/routes/sockets-routes.js +++ b/routes/sockets-routes.js @@ -58,17 +58,14 @@ module.exports = (app, siofu, hostedContentPath) => { publish(publishParams, file.name, file.meta.type) .then(result => { socket.emit('publish-complete', { name: publishParams.name, result }); - postToStats('PUBLISH', '/', null, null, null, 'success'); }) .catch(error => { - socket.emit('publish-failure', error); logger.error('Publish Error:', useObjectPropertiesIfNoKeys(error)); - postToStats('PUBLISH', '/', null, null, null, error); + socket.emit('publish-failure', error.message); }); } else { socket.emit('publish-failure', 'File uploaded, but with errors'); logger.error(`An error occurred in uploading the client's file`); - postToStats('PUBLISH', '/', null, null, null, 'File uploaded, but with errors'); // to-do: remove the file, if not done automatically } }); diff --git a/views/index.handlebars b/views/index.handlebars index f93ef216..26b5980e 100644 --- a/views/index.handlebars +++ b/views/index.handlebars @@ -4,9 +4,9 @@
-
-
-
+
+
+

Drag & drop image or video here

@@ -26,7 +26,7 @@
-
- -
{{> publishForm-Channel}} {{> publishForm-Url}} @@ -48,6 +46,11 @@
+
+ + + +
@@ -57,70 +60,104 @@ checkCookie(); - var socket = io(); - var uploader = new SocketIOFileUpload(socket); - var stagedFiles = null; + const socket = io(); + const uploader = new SocketIOFileUpload(socket); + let stagedFiles = null; + + const publishFormWrapper = document.getElementById('publish-form-wrapper'); + const publishStatus = document.getElementById('publish-status'); + const publishProgressBar = document.getElementById('publish-progress-bar'); + const uploadPercent = document.getElementById('upload-percent'); /* socketio-file-upload listeners */ - function updatePublishStatus(msg){ - document.getElementById('publish-status').innerHTML = msg; - } uploader.addEventListener('start', function(event){ console.log('starting upload'); + addInputValuesToFileMetaData(event) + // hide the publish tool + hidePublishTools(); + // show the progress status and animation + showPublishStatus(); + updatePublishStatus('File is loading to server') + showPublishProgressBar(); + showUploadPercent(); + }); + uploader.addEventListener('progress', function(event){ + var percent = event.bytesLoaded / event.file.size * 100; + updateUploadPercent(`${percent.toFixed(2)} %`) + }); + /* socket.io message listeners */ + socket.on('publish-status', function(msg){ + updatePublishStatus(msg); + hideUploadPercent(); + }); + socket.on('publish-failure', function(msg){ + updatePublishStatus('

--(✖╭╮✖)→

' + JSON.stringify(msg) + '

For help, post the above error text in the #speech channel on the lbry slack'); + hidePublishProgressBar(); + hideUploadPercent(); + }); + socket.on('publish-complete', function(msg){ + const showUrl = msg.result.claim_id + "/" + msg.name; + // update status + updatePublishStatus('

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

If you do not get redirected, click here.

'); + hidePublishProgressBar(); + hideUploadPercent(); + // redirect the user + window.location.href = showUrl; + }); + + function hidePublishTools() { + publishFormWrapper.hidden = true; + } + // publish status functions + function showPublishStatus() { + publishStatus.hidden = false; + } + function updatePublishStatus(msg){ + publishStatus.innerHTML = msg; + } + // progress bar functions + function showPublishProgressBar(){ + publishProgressBar.hidden = false; + createProgressBar(publishProgressBar, 12); + } + function hidePublishProgressBar(){ + publishProgressBar.hidden = true; + } + // upload percent functions + function showUploadPercent(){ + uploadPercent.hidden = false; + } + function updateUploadPercent(msg){ + uploadPercent.innerHTML = msg; + } + function hideUploadPercent(){ + uploadPercent.hidden = true; + } + + function addInputValuesToFileMetaData(event) { + // get values from inputs const name = document.getElementById('claim-name-input').value; const title = document.getElementById('publish-title').value; const description = document.getElementById('publish-description').value; const license = document.getElementById('publish-license').value; const nsfw = document.getElementById('publish-nsfw').checked; const anonymous = document.getElementById('anonymous-select').checked; - console.log('anonymous?', anonymous); const channel = document.getElementById('channel-name-select').value; - console.log('channel:', channel); const thumbnail = document.getElementById('claim-thumbnail-input').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; - if (!anonymous) { - event.file.meta.channel = channel; + // set values on file meta data + 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; + console.log('anonymous?', anonymous); + if (!anonymous) { + console.log('channel:', channel); + event.file.meta.channel = channel; } if (thumbnail && (thumbnail.trim !== '')){ event.file.meta.thumbnail = thumbnail; } - // hide the submit area - document.getElementById('publish-active-area').hidden = true; - // show the progress status and animation - document.getElementById('publish-status').hidden = false; - document.getElementById('publish-progress-bar').hidden = false; - createProgressBar(document.getElementById('publish-progress-bar'), 12); - // google analytics - ga('send', { - hitType: 'event', - eventCategory: 'publish', - eventAction: name - }); - }); - uploader.addEventListener('progress', function(event){ - var percent = event.bytesLoaded / event.file.size * 100; - updatePublishStatus('File is ' + percent.toFixed(2) + '% loaded to the server'); - }); - /* socket.io message listeners */ - socket.on('publish-status', function(msg){ - updatePublishStatus(msg); - }); - socket.on('publish-failure', function(msg){ - updatePublishStatus('

--(✖╭╮✖)→

' + JSON.stringify(msg) + '

For help, post the above error text in the #speech channel on the lbry slack'); - document.getElementById('publish-progress-bar').hidden = true; - }); - socket.on('publish-complete', function(msg){ - console.log(msg); - var showUrl = msg.result.claim_id + "/" + msg.name; - // update status - updatePublishStatus('

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

If you do not get redirected, click here.

'); - document.getElementById('publish-progress-bar').hidden = true; - // redirect the user - window.location.href = showUrl; - }); + }