2017-10-23 22:07:05 +02:00
<div class="row row--tall row--padded flex-container">
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-23 22:07:05 +02:00
<div id="primary-dropzone" class="dropzone row row--tall flex-container 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)">
<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-23 22:07:05 +02:00
<p>OR</p>
2017-10-24 00:10:49 +02:00
<p><label class="input-file-label">CHOOSE FILE</label></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-17 17:47:00 +02:00
<input type="text" id="publish-title" class="input-text input-text--large input-text--full-width" placeholder="Give your post a title...">
2017-10-03 02:36:25 +02:00
</div>
2017-10-23 22:07:05 +02:00
<div class="column column--5 column--med-10" >
2017-10-03 02:36:25 +02:00
<!-- preview -->
2017-10-23 22:07:05 +02:00
<div class="row row--padded">
2017-10-10 20:52:34 +02:00
<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)">
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>
<p>OR</p>
<label class="input-file-label">CHOOSE FILE</label>
2017-10-03 23:52:50 +02:00
</div>
</div>
2017-10-03 02:36:25 +02:00
</div>
2017-10-04 01:26:43 +02:00
</div><div class="column column--5 column--med-10 align-content-top">
2017-10-10 19:14:43 +02:00
<div id="publish-active-area">
{{ > 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-23 22:07:05 +02:00
2017-10-24 00:10:49 +02:00
<div id="publish-status" class="hidden">
<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>
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>')
updateUploadPercent(`<p>$ { 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-21 02:24:54 +02:00
updateUploadPercent(`<p>Curious what magic is happening here? <a 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-12 22:10:44 +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 href="https://lbry.slack.com/" target="_blank">lbry slack</a></strong>');
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>');
updateUploadPercent('<p><a 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 00:10:49 +02:00
publishStatus.setAttribute('class', 'row row--tall flex-container 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
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;
const channel = document.getElementById('channel-name-select').value;
const thumbnail = document.getElementById('claim-thumbnail-input').value;
// 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>