fixed call-stack-exceeded error issue

This commit is contained in:
bill bittner 2017-10-12 13:10:44 -07:00
parent 3e1427a314
commit 8856ee5d0e
5 changed files with 114 additions and 67 deletions

View file

@ -8,7 +8,7 @@ module.exports = {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let publishResults = {}; let publishResults = {};
// 1. publish the file // 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) // 2. upsert File record (update is in case the claim has been published before by this daemon)
.then(tx => { .then(tx => {
logger.info(`Successfully published ${fileName}`, tx); logger.info(`Successfully published ${fileName}`, tx);
@ -67,6 +67,7 @@ module.exports = {
resolve(publishResults); // resolve the promise with the result from lbryApi.publishClaim; resolve(publishResults); // resolve the promise with the result from lbryApi.publishClaim;
}) })
.catch(error => { .catch(error => {
logger.error('publishController.publish, error', error);
publishHelpers.deleteTemporaryFile(publishParams.file_path); // delete the local file publishHelpers.deleteTemporaryFile(publishParams.file_path); // delete the local file
reject(error); reject(error);
}); });

View file

@ -152,7 +152,10 @@ module.exports = {
}, },
deleteTemporaryFile (filePath) { deleteTemporaryFile (filePath) {
fs.unlink(filePath, err => { fs.unlink(filePath, err => {
if (err) throw err; if (err) {
logger.error(`error deleting temporary file ${filePath}`);
throw err;
}
logger.debug(`successfully deleted ${filePath}`); logger.debug(`successfully deleted ${filePath}`);
}); });
}, },

View file

@ -202,7 +202,8 @@ h3 {
} }
/* ALIGNMENT */ /* ALIGNMENT */
.align-content-left { .
align-content-left {
text-align: left; text-align: left;
} }
@ -222,6 +223,14 @@ h3 {
vertical-align: bottom; vertical-align: bottom;
} }
.align-content-vcenter-hcenter {
position: absolute;
top: 40%;
left: 50%;
transform: translateX(-50%) translateY(-40%);
}
/* ERROR MESSAGES */ /* ERROR MESSAGES */
. info-message { . info-message {
@ -473,10 +482,10 @@ table {
} }
#primary-dropzone-instructions, #preview-dropzone-instructions { #primary-dropzone-instructions, #preview-dropzone-instructions {
position: absolute; /*position: absolute;*/
top: 40%; /*top: 40%;*/
left: 50%; /*left: 50%;*/
transform: translateX(-50%) translateY(-40%); /*transform: translateX(-50%) translateY(-40%);*/
} }
#asset-preview { #asset-preview {

View file

@ -58,17 +58,14 @@ module.exports = (app, siofu, hostedContentPath) => {
publish(publishParams, file.name, file.meta.type) publish(publishParams, file.name, file.meta.type)
.then(result => { .then(result => {
socket.emit('publish-complete', { name: publishParams.name, result }); socket.emit('publish-complete', { name: publishParams.name, result });
postToStats('PUBLISH', '/', null, null, null, 'success');
}) })
.catch(error => { .catch(error => {
socket.emit('publish-failure', error);
logger.error('Publish Error:', useObjectPropertiesIfNoKeys(error)); logger.error('Publish Error:', useObjectPropertiesIfNoKeys(error));
postToStats('PUBLISH', '/', null, null, null, error); socket.emit('publish-failure', error.message);
}); });
} else { } else {
socket.emit('publish-failure', 'File uploaded, but with errors'); socket.emit('publish-failure', 'File uploaded, but with errors');
logger.error(`An error occurred in uploading the client's file`); 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 // to-do: remove the file, if not done automatically
} }
}); });

View file

@ -4,9 +4,9 @@
</form> </form>
<div id="primary-dropzone-wrapper"> <div id="primary-dropzone-wrapper">
<div id="primary-dropzone" class="dropzone" ondrop="drop_handler(event);" ondragover="dragover_handler(event);" ondragend="dragend_handler(event)" ondragenter="dragenter_handler(event)" ondragleave="dragexit_handler(event)" onclick="triggerFileChooser('siofu_input', event)"> <div id="primary-dropzone" class="dropzone" ondrop="drop_handler(event);" ondragover="dragover_handler(event);" ondragend="dragend_handler(event)" ondragenter="dragenter_handler(event)" ondragleave="dragexit_handler(event)" onclick="triggerFileChooser('siofu_input', event)">
<div id="primary-dropzone-instructions"> <div id="primary-dropzone-instructions" class="align-content-vcenter-hcenter">
<div class="info-message-placeholder"> <div class="info-message-placeholder align-content-center">
<div class="info-message-placeholder"><div class="info-message info-message--failure" id="input-error-file-selection" hidden="true"></div></div> <div class="info-message info-message--failure" id="input-error-file-selection" hidden="true"></div>
</div> </div>
<div class="row"> <div class="row">
<p>Drag & drop image or video here</p> <p>Drag & drop image or video here</p>
@ -26,7 +26,7 @@
<div class="row"> <div class="row">
<div id="asset-preview-holder" class="dropzone" ondrop="drop_handler(event);" ondragover="dragover_handler(event);" ondragend="dragend_handler(event)" onmouseenter="showInstructions()" onmouseleave="hideInstructions()" onclick="triggerFileChooser('siofu_input', event)"> <div id="asset-preview-holder" class="dropzone" ondrop="drop_handler(event);" ondragover="dragover_handler(event);" ondragend="dragend_handler(event)" onmouseenter="showInstructions()" onmouseleave="hideInstructions()" onclick="triggerFileChooser('siofu_input', event)">
<div id="asset-preview-target"></div> <div id="asset-preview-target"></div>
<div id="preview-dropzone-instructions" hidden="true"> <div id="preview-dropzone-instructions" class="align-content-vcenter-hcenter" hidden="true">
<div class="row"> <div class="row">
<p>Drag & drop image or video here</p> <p>Drag & drop image or video here</p>
<p>OR</p> <p>OR</p>
@ -37,8 +37,6 @@
</div> </div>
</div> </div>
</div><div class="column column--5 column--med-10 align-content-top"> </div><div class="column column--5 column--med-10 align-content-top">
<div id="publish-status" class="row" hidden="true"></div>
<div id="publish-progress-bar" class="row" hidden="true"></div>
<div id="publish-active-area"> <div id="publish-active-area">
{{> publishForm-Channel}} {{> publishForm-Channel}}
{{> publishForm-Url}} {{> publishForm-Url}}
@ -48,6 +46,11 @@
</div> </div>
</div> </div>
</div> </div>
<div class="align-content-vcenter-hcenter">
<div id="publish-status" class="row align-content-center" hidden="true"></div>
<div id="publish-progress-bar" class="row align-content-center" hidden="true"></div>
<div id="upload-percent" class="row align-content-center" hidden="true"></div>
</div>
</div> </div>
@ -57,70 +60,104 @@
checkCookie(); checkCookie();
var socket = io(); const socket = io();
var uploader = new SocketIOFileUpload(socket); const uploader = new SocketIOFileUpload(socket);
var stagedFiles = null; 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 */ /* socketio-file-upload listeners */
function updatePublishStatus(msg){
document.getElementById('publish-status').innerHTML = msg;
}
uploader.addEventListener('start', function(event){ uploader.addEventListener('start', function(event){
console.log('starting upload'); 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('<p> --(✖╭╮✖)→ </p><p>' + JSON.stringify(msg) + '</p><strong>For help, post the above error text in the #speech channel on the <a href="https://lbry.slack.com/" target="_blank">lbry slack</a></strong>');
hidePublishProgressBar();
hideUploadPercent();
});
socket.on('publish-complete', function(msg){
const showUrl = msg.result.claim_id + "/" + msg.name;
// update status
updatePublishStatus('<p>Your publish is complete! You are being redirected to it now.</p><p><a target="_blank" href="' + showUrl + '">If you do not get redirected, click here.</a></p>');
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 name = document.getElementById('claim-name-input').value;
const title = document.getElementById('publish-title').value; const title = document.getElementById('publish-title').value;
const description = document.getElementById('publish-description').value; const description = document.getElementById('publish-description').value;
const license = document.getElementById('publish-license').value; const license = document.getElementById('publish-license').value;
const nsfw = document.getElementById('publish-nsfw').checked; const nsfw = document.getElementById('publish-nsfw').checked;
const anonymous = document.getElementById('anonymous-select').checked; const anonymous = document.getElementById('anonymous-select').checked;
console.log('anonymous?', anonymous);
const channel = document.getElementById('channel-name-select').value; const channel = document.getElementById('channel-name-select').value;
console.log('channel:', channel);
const thumbnail = document.getElementById('claim-thumbnail-input').value; const thumbnail = document.getElementById('claim-thumbnail-input').value;
event.file.meta.name = name; // set values on file meta data
event.file.meta.title = title; event.file.meta.name = name;
event.file.meta.description = description; event.file.meta.title = title;
event.file.meta.license = license; event.file.meta.description = description;
event.file.meta.nsfw = nsfw; event.file.meta.license = license;
event.file.meta.type = stagedFiles[0].type; event.file.meta.nsfw = nsfw;
if (!anonymous) { event.file.meta.type = stagedFiles[0].type;
event.file.meta.channel = channel; console.log('anonymous?', anonymous);
if (!anonymous) {
console.log('channel:', channel);
event.file.meta.channel = channel;
} }
if (thumbnail && (thumbnail.trim !== '')){ if (thumbnail && (thumbnail.trim !== '')){
event.file.meta.thumbnail = thumbnail; 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('<p> --(✖╭╮✖)→ </p><p>' + JSON.stringify(msg) + '</p><strong>For help, post the above error text in the #speech channel on the <a href="https://lbry.slack.com/" target="_blank">lbry slack</a></strong>');
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('<p>Your publish is complete! You are being redirected to it now.</p><p><a target="_blank" href="' + showUrl + '">If you do not get redirected, click here.</a></p>');
document.getElementById('publish-progress-bar').hidden = true;
// redirect the user
window.location.href = showUrl;
});
</script> </script>