2017-10-24 22:39:06 +02:00
<div class="row row--tall flex-container flex-container--column">
2017-10-11 22:33:56 +02:00
<form>
<input class="input-file" type="file" id="siofu_input" name="siofu_input" accept="video/*,image/*" onchange="previewAndStageFile(event.target.files[0])" enctype="multipart/form-data"/>
</form>
2017-10-24 22:39:06 +02:00
<div id="primary-dropzone" class="dropzone row row--margined row--padded row--tall flex-container flex-container--column flex-container--center" 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)">
2017-10-23 22:07:05 +02:00
<div id="primary-dropzone-instructions">
2017-10-24 00:10:49 +02:00
<div class="info-message-placeholder">
2017-10-23 22:07:05 +02:00
<div class="info-message info-message--failure" id="input-error-file-selection" hidden="true"></div>
2017-10-02 20:47:12 +02:00
</div>
2017-10-24 00:10:49 +02:00
<p>Drag & drop image or video here to publish</p>
2017-10-24 07:29:20 +02:00
<p class="fine-print">OR</p>
<p class="blue-underlined-pointer">CHOOSE FILE</p>
</div>
<div id="dropbzone-dragover" class="hidden">
<p class="blue">Drop it.</p>
2017-10-02 20:47:12 +02:00
</div>
2017-09-29 23:24:53 +02:00
</div>
2017-10-23 22:07:05 +02:00
<div id="publish-form" class="hidden">
2017-10-03 02:36:25 +02:00
<div class="column column--10">
<!-- title input -->
2017-10-24 22:39:06 +02:00
<div class="row row--padded row--no-bottom">
<input type="text" id="publish-title" class="input-text input-text--large input-text--full-width" placeholder="Give your post a title...">
</div>
2017-10-03 02:36:25 +02:00
</div>
2017-10-25 00:34:05 +02:00
<div class="column column--5 column--med-10" >
2017-10-03 02:36:25 +02:00
<!-- preview -->
2017-10-24 22:39:06 +02:00
<div class="row row--margined">
<div id="asset-preview-holder" class="dropzone row--margined" ondrop="drop_handler(event);" ondragover="dragover_handler(event);" ondragend="dragend_handler(event)" onmouseenter="showInstructions()" onmouseleave="hideInstructions()" onclick="triggerFileChooser('siofu_input', event)">
2017-10-03 23:52:50 +02:00
<div id="asset-preview-target"></div>
2017-10-24 00:10:49 +02:00
<div id="preview-dropzone-instructions" class="hidden">
<p>Drag & drop image or video here</p>
2017-10-24 07:29:20 +02:00
<p class="fine-print">OR</p>
<p class="blue-underlined-pointer">CHOOSE FILE</p>
2017-10-03 23:52:50 +02:00
</div>
</div>
2017-10-03 02:36:25 +02:00
</div>
2017-10-25 00:34:05 +02:00
</div><div class="column column--5 column--med-10 align-content-top">
2017-10-24 22:39:06 +02:00
<div id="publish-active-area" class="row row--margined">
2017-10-10 19:14:43 +02:00
{{ > publishForm-Channel }}
{{ > publishForm-Url }}
{{ > publishForm-Thumbnail }}
{{ > publishForm-Details }}
{{ > publishForm-Submit }}
</div>
2017-09-30 00:56:13 +02:00
</div>
2017-09-29 23:24:53 +02:00
</div>
2017-10-24 00:10:49 +02:00
<div id="publish-status" class="hidden">
2017-10-24 22:39:06 +02:00
<div class="row row--margined">
<div id="publish-update" class="row align-content-center"></div>
<div id="publish-progress-bar" class="row align-content-center"></div>
<div id="upload-percent" class="row align-content-center"></div>
</div>
2017-10-12 22:10:44 +02:00
</div>
2017-09-29 23:24:53 +02:00
</div>
2017-06-10 01:46:57 +02:00
2017-10-02 20:47:12 +02:00
2017-06-10 01:46:57 +02:00
<script src="/socket.io/socket.io.js"></script>
<script src="/siofu/client.js"></script>
2017-07-23 00:09:58 +02:00
<script typ="text/javascript">
2017-10-03 23:52:50 +02:00
2017-10-07 01:42:19 +02:00
checkCookie();
2017-10-12 22:10:44 +02:00
const socket = io();
const uploader = new SocketIOFileUpload(socket);
let stagedFiles = null;
2017-10-23 22:07:05 +02:00
const publishFormWrapper = document.getElementById('publish-form');
2017-10-12 22:10:44 +02:00
const publishStatus = document.getElementById('publish-status');
2017-10-24 00:10:49 +02:00
const publishUpdate = document.getElementById('publish-update');
2017-10-12 22:10:44 +02:00
const publishProgressBar = document.getElementById('publish-progress-bar');
const uploadPercent = document.getElementById('upload-percent');
2017-10-03 19:05:09 +02:00
2017-07-23 00:09:58 +02:00
/* socketio-file-upload listeners */
uploader.addEventListener('start', function(event) {
2017-10-10 03:29:40 +02:00
console.log('starting upload');
2017-10-12 22:10:44 +02:00
addInputValuesToFileMetaData(event)
// hide the publish tool
hidePublishTools();
2017-09-30 00:56:13 +02:00
// show the progress status and animation
2017-10-12 22:10:44 +02:00
showPublishStatus();
showPublishProgressBar();
2017-07-23 00:09:58 +02:00
});
uploader.addEventListener('progress', function(event) {
var percent = event.bytesLoaded / event.file.size * 100;
2017-10-24 00:10:49 +02:00
updatePublishStatus('<p>File is loading to server</p>')
2017-10-24 19:46:46 +02:00
updateUploadPercent(`<p class="blue">$ { percent.toFixed(2)}%</p>`)
2017-07-23 00:09:58 +02:00
});
/* socket.io message listeners */
2017-10-24 00:10:49 +02:00
socket.on('publish-update', function(msg) {
updatePublishStatus(`<p>$ { msg}</p>`);
2017-10-25 18:17:47 +02:00
updateUploadPercent(`<p>Curious what magic is happening here? <a class="link--primary" target="blank" href="https://lbry.io/faq/what-is-lbry">Learn more.</a></p>`);
2017-07-23 00:09:58 +02:00
});
socket.on('publish-failure', function(msg) {
2017-10-25 18:17:47 +02:00
updatePublishStatus('<p> --(✖╭╮✖)→ </p><p>' + JSON.stringify(msg) + '</p><strong>For help, post the above error text in the #speech channel on the <a class="link--primary" href="https://discord.gg/YjYbwhS" target="_blank">lbry discord</a></strong>');
2017-10-12 22:10:44 +02:00
hidePublishProgressBar();
hideUploadPercent();
2017-07-23 00:09:58 +02:00
});
socket.on('publish-complete', function(msg) {
2017-10-12 22:10:44 +02:00
const showUrl = msg.result.claim_id + "/" + msg.name;
2017-09-30 00:56:13 +02:00
// update status
2017-10-24 00:10:49 +02:00
updatePublishStatus('<p>Your publish is complete! You are being redirected to it now.</p>');
2017-10-25 18:17:47 +02:00
updateUploadPercent('<p><a class="link--primary" target="_blank" href="\' + showUrl + \'">If you do not get redirected, click here.</a></p>')
2017-09-30 00:56:13 +02:00
// redirect the user
2017-07-23 00:09:58 +02:00
window.location.href = showUrl;
});
2017-10-12 22:10:44 +02:00
function hidePublishTools() {
2017-10-24 00:10:49 +02:00
publishFormWrapper.setAttribute('class', 'hidden');
2017-10-12 22:10:44 +02:00
}
// publish status functions
function showPublishStatus() {
2017-10-24 21:14:58 +02:00
publishStatus.setAttribute('class', 'row row--tall flex-container flex-container--column flex-container--center');
2017-10-12 22:10:44 +02:00
}
function updatePublishStatus(msg) {
2017-10-24 00:10:49 +02:00
publishUpdate.innerHTML = msg;
2017-10-12 22:10:44 +02:00
}
// progress bar functions
function showPublishProgressBar() {
createProgressBar(publishProgressBar, 12);
}
function hidePublishProgressBar() {
publishProgressBar.hidden = true;
}
// upload percent functions
function updateUploadPercent(msg) {
uploadPercent.innerHTML = msg;
}
function hideUploadPercent() {
uploadPercent.hidden = true;
}
function addInputValuesToFileMetaData(event) {
// get values from inputs
2017-10-24 19:46:46 +02:00
const name = document.getElementById('claim-name-input').value.trim();
const title = document.getElementById('publish-title').value.trim();
const description = document.getElementById('publish-description').value.trim();
const license = document.getElementById('publish-license').value.trim();
2017-10-12 22:10:44 +02:00
const nsfw = document.getElementById('publish-nsfw').checked;
const anonymous = document.getElementById('anonymous-select').checked;
2017-10-24 19:46:46 +02:00
const channel = document.getElementById('channel-name-select').value.trim();
const thumbnail = document.getElementById('claim-thumbnail-input').value.trim();
2017-10-12 22:10:44 +02:00
// 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;
}
}
2017-07-23 00:09:58 +02:00
</script>