converted to handlebars

This commit is contained in:
bill bittner 2017-06-09 16:46:57 -07:00
parent 87768dcc47
commit 23b9005fc2
19 changed files with 226 additions and 236 deletions

View file

@ -3,7 +3,7 @@ var path = require('path');
module.exports = { module.exports = {
handleRequestError: function(error, res) { handleRequestError: function(error, res) {
if ((error === "NO_CLAIMS") || (error === "NO_FREE_PUBLIC_CLAIMS")){ if ((error === "NO_CLAIMS") || (error === "NO_FREE_PUBLIC_CLAIMS")){
res.status(307).sendFile(path.join(__dirname, '../public', 'noClaims.html')); res.status(307).render('noClaims');
} else if (error.response){ } else if (error.response){
res.status(error.response.status).send(error.response.data.error.message); res.status(error.response.status).send(error.response.data.error.message);
} else if (error.code === "ECONNREFUSED") { } else if (error.code === "ECONNREFUSED") {

View file

@ -26,6 +26,7 @@
"axios": "^0.16.1", "axios": "^0.16.1",
"body-parser": "^1.17.1", "body-parser": "^1.17.1",
"express": "^4.15.2", "express": "^4.15.2",
"express-handlebars": "^3.0.0",
"nodemon": "^1.11.0", "nodemon": "^1.11.0",
"socket.io": "^2.0.1", "socket.io": "^2.0.1",
"socketio-file-upload": "^0.6.0" "socketio-file-upload": "^0.6.0"

View file

@ -0,0 +1,3 @@
.all-claims-img {
height: 200px;
}

View file

@ -1,14 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Four Oh Four</title>
</head>
<body>
<h1>spee.ch</h1>
<h3>404: Not Found</h3>
<p>That page does not exist. Return <a href="/">home</a>.</p>
</body>
</html>

View file

@ -1,196 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Spee.ch</title>
<link rel="stylesheet" type="text/css" href="/assets/css/style.css">
</head>
<body>
<h1>spee.ch</h1>
<p>spee.ch is a single-serving site that reads and publishes images to and from the <a href="https://lbry.io">LBRY</a> blockchain.</p>
<section>
<h2>Examples:</h2>
<ul>
<li><a href="/coconuts">spee.ch/coconuts</a></li>
<li><a href="/wood">spee.ch/wood</a></li>
<li><a href="/doitlive">spee.ch/doitlive</a></li>
<li><a href="/doitlive/all">spee.ch/doitlive/all</a></li>
<li><a href="/doitlive/ca3023187e901df9e9aabd95d6ae09b6cc69b3f0">spee.ch/doitlive/ca3023187e901df9e9aabd95d6ae09b6cc69b3f0</a></li>
</ul>
</section>
<section>
<h2>Publish Your Own</h2>
<div id="publish">
<form id="publish-form" action="" method="" enctype="multipart/form-data">
<input type="file" id="siofu_input" name="file" accept="video/*,image/*" onchange="previewFile()" enctype="multipart/form-data"/>
<br/>
<img id="image-preview" src="" height="200" alt="Image preview..."/>
<br/>
Name: <input type="text" id="publish-name" name="name" value="name"/>
<br/>
License: <select type="text" id="publish-license" name="license" value="license">
<option value="Public Domain">Public Domain</option>
<option value="Creative Commons">Creative Commons</option>
</select>
<br/>
NSFW: <select type="text" id="publish-nsfw" name="nsfw" value="false">
<option value="false">False</option>
<option value="true">True</option>
</select>
<p><i>By clicking 'Publish' I attest that I have read and agree to the <a href="https://lbry.io/termsofservice" target="_blank">LBRY terms of service</a>.</i></p>
<button id="publish-submit">Publish</button>
</form>
</div>
</section>
<section>
<h2>Help Wanted!</h2>
<p>If you would like to help make spee.ch amazing, join our slack channel.</p>
<p>We are currently in need of a designer to help with styling spee.ch's front end, but all help is welcome!</p>
</section>
<section>
<h2>Documentation</h2>
<h3>Site Navigation</h3>
<ul>
<li><strong><a href="/">spee.ch</a></strong>.
<ul>
<li>To publish a file, navigate to the homepage.</li>
</ul>
</li>
<li><strong>spee.ch/&ltthe name of the claim&gt</strong>
<ul>
<li>To view the file with the largest bid at a claim.</li>
<li>E.g. <a href="/doitlive">spee.ch/doitlive</a>.</li>
</ul>
</li>
<li><strong>spee.ch/&lt the name of the claim &gt/&lt the claim_id &gt</strong>
<ul>
<li>To view a specific file at a claim</li>
<li>E.g. <a href="/doitlive/c496c8c55ed79816fec39e36a78645aa4458edb5">spee.ch/doitlive/c496c8c55ed79816fec39e36a78645aa4458edb5</a></li>
</ul>
</li>
<li><strong>spee.ch/&ltthe name of the claim&gt/all</strong>
<ul>
<li>To view a batch of files at a claim</li>
<li>E.g. <a href="/doitlive/all">spee.ch/doitlive/all</a></li>
</ul>
</li>
</ul>
<h3>API</h3>
<p>Note: these are being used for testing durring spee.ch development and may not be maintained</p>
<ul>
<li>A GET request to <strong>spee.ch/claim_list/&ltthe name of the claim&gt</strong>
<ul>
<li>Will return the claim_list for the claim in json format. </li>
<li>E.g. <a href="/claim_list/doitlive">spee.ch/claim_list/doitlive</a></li>
</ul>
</li>
</ul>
</section>
<section>
<h2>Links</h2>
<a href="https://github.com/lbryio/spee.ch">github</a>
<a href="https://lbry.io/">lbry</a>
<a href="https://lbry.slack.com">slack</a>
</section>
<section>
<h2>Bugs</h2>
<p>Spee.ch is young and under continuous development so it will have bugs. Please leave an issue on our <a href="https://github.com/lbryio/spee.ch">github</a> if you experience a problem or have suggestions.</p>
<br>&nbsp;.w.
<br>(o|o)
<br>&nbsp;&nbsp;`'`
</section>
<script src="/socket.io/socket.io.js"></script>
<script src="/siofu/client.js"></script>
<script>
var socket = io();
var uploader = new SocketIOFileUpload(socket);
function createProgressBar(element, size){
var x = 1;
var adder = 1;
function addOne(){
var bars = '<p>|';
for (var i = 0; i < x; i++){
bars += ' | ';
}
bars += '</p>';
element.innerHTML = bars;
if (x === size){
adder = -1;
} else if ( x === 0){
adder = 1;
}
x += adder;
};
setInterval(addOne, 300);
}
function previewFile(){
var preview = document.querySelector('img'); //selects the query named img
var claimName = document.querySelector('input[name=name]');
var selectedFile = document.querySelector('input[name=file]').files[0];
var previewReader = new FileReader();
previewReader.onloadend = function () {
preview.src = previewReader.result;
};
if (selectedFile) {
previewReader.readAsDataURL(selectedFile); // reads the data and sets the img src
claimName.value = selectedFile.name.substring(0, selectedFile.name.indexOf('.'));
} else {
preview.src = '';
}
}
function updatePublishStatus(msg){
document.getElementById('publish-status').innerHTML = msg;
}
uploader.listenOnSubmit(document.getElementById('publish-submit'), document.getElementById('siofu_input'));
document.getElementById('publish-submit').addEventListener('click', function(event){
event.preventDefault();
})
uploader.addEventListener('start', function(event){
var name = document.getElementById('publish-name').value;
var license = document.getElementById('publish-license').value;
var nsfw = document.getElementById('publish-nsfw').value;
// set meta data
event.file.meta.name = name;
event.file.meta.license = license;
event.file.meta.nsfw = nsfw;
// set the html of the publish area
document.getElementById('publish').innerHTML = '<div id="publish-status"></div><div id="progress-bar"></div>';
// start the progress bar
createProgressBar(document.getElementById('progress-bar'), 12);
});
uploader.addEventListener('progress', function(event){
var percent = event.bytesLoaded / event.file.size * 100;
updatePublishStatus('File is ' + percent.toFixed(2) + '% loaded to the server');
})
socket.on('publish-status', function(msg){
updatePublishStatus(msg);
})
socket.on('publish-failure', function(msg){
document.getElementById('publish').innerHTML = '<p>' + msg + '</p><p> --(✖╭╮✖)→ </p>';
})
socket.on('publish-complete', function(msg){
var publishResults = '<p>Your publish is complete!</p>';
publishResults += '<p>Your Claim ID is: ' + msg.result.claim_id + '</p>';
publishResults += '<p>Your Transaction ID is: <a href="https://explorer.lbry.io/#!/transaction?id=' + msg.result.txid + '">' + msg.result.txid + '</a></p>';
publishResults += '<p>Here is a link to the claim where your asset was published: <a href="https://spee.ch/' + msg.name + '">spee.ch/' + msg.name + '</a></p>';
publishResults += '<p>Here is a direct link to your asset: <a href="https://spee.ch/' + msg.name + '/' + msg.result.claim_id + '">spee.ch/' + msg.name + '/' + msg.result.claim_id + '</a></p>';
publishResults += '<p><i>NOTE: the transaction still needs to be mined by the network before you can access it! This may take a few minutes. To to view the transaction on the blockchain explorer click the Transaction ID link above.</i></p>';
publishResults += '<p><a href="/">Reload to publish another asset</a></p>';
document.getElementById('publish').innerHTML = publishResults;
})
</script>
</body>
</html>

View file

@ -1,14 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>No Claims</title>
</head>
<body>
<h1>spee.ch</h1>
<h3>No Claims</h3>
<p>There are no free, public images at that claim. You should publish one at <a href="/">spee.ch</a>.</p>
</body>
</html>

View file

@ -14,8 +14,8 @@ module.exports = function(app){
// create promise // create promise
lbryApi.getAllClaims(req.params.name) lbryApi.getAllClaims(req.params.name)
.then(function(orderedFreePublicClaims){ .then(function(orderedFreePublicClaims){
console.log("/:name/all success.") console.log("/:name/all success.");
res.status(200).send(orderedFreePublicClaims); res.status(200).render('allClaims', { claims: orderedFreePublicClaims });
return; return;
}) })
.catch(function(error){ .catch(function(error){
@ -53,10 +53,10 @@ module.exports = function(app){
}); });
// route for the home page // route for the home page
app.get("/", function(req, res){ app.get("/", function(req, res){
res.status(200).sendFile(path.join(__dirname, '../public', 'index.html')); res.status(200).render('index');
}); });
// a catch-all route if someone visits a page that does not exist // a catch-all route if someone visits a page that does not exist
app.use("*", function(req, res){ app.use("*", function(req, res){
res.status(404).sendFile(path.join(__dirname, '../public', 'fourOhfour.html')); res.status(404).render('fourOhFour');
}); });
} }

View file

@ -3,6 +3,7 @@ var express = require('express');
var bodyParser = require('body-parser'); var bodyParser = require('body-parser');
var path = require('path'); var path = require('path');
var siofu = require("socketio-file-upload"); var siofu = require("socketio-file-upload");
var expressHandlebars = require("express-handlebars");
// set port // set port
var PORT = 3000; var PORT = 3000;
@ -18,12 +19,15 @@ app.use(bodyParser.json()); // for parsing application/json
app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded
app.use(siofu.router); app.use(siofu.router);
// configure handlebars
app.engine('handlebars', expressHandlebars({defaultLayout: 'main'}));
app.set('view engine', 'handlebars');
// require express routes // require express routes
require("./routes/api-routes.js")(app); require("./routes/api-routes.js")(app);
require("./routes/html-routes.js")(app); require("./routes/html-routes.js")(app);
// include socket.io functionality // wrap the server in socket.io to intercept incoming sockets requests
// this wraps the server in sockets, to intercept incoming sockets requests
var http = require("./routes/sockets-routes.js")(app); var http = require("./routes/sockets-routes.js")(app);
// start server // start server

View file

@ -0,0 +1,12 @@
<h3>All Claims</h3>
<p>These are all the free, public assets at that claim. You can publish more at <a href="/">spee.ch</a>.</p>
{{#each claims}}
<hr>
<img class="all-claims-img" src="https://spee.ch/{{this.name}}/{{this.claim_id}}" />
<p>claim_id: {{this.claim_id}}</p>
<p>direct link <a href="https://spee.ch/{{this.name}}/{{this.claim_id}}">here</a></p>
<p>author: {{this.value.stream.metadata.author}}</p>
<p>description: {{this.value.stream.metadata.description}}</p>
<p>license: {{this.value.stream.metadata.license}}</p>
{{/each}}

View file

@ -0,0 +1,3 @@
<h1>spee.ch</h1>
<h3>404: Not Found</h3>
<p>That page does not exist. Return <a href="/">home</a>.</p>

100
views/index.handlebars Normal file
View file

@ -0,0 +1,100 @@
<h1>spee.ch</h1>
<p>spee.ch is a single-serving site that reads and publishes images to and from the <a href="https://lbry.io">LBRY</a> blockchain.</p>
{{> examples}}
{{> publish}}
{{> links}}
{{> documentation}}
{{> bugs}}
{{> contribute}}
<script src="/socket.io/socket.io.js"></script>
<script src="/siofu/client.js"></script>
<script>
var socket = io();
var uploader = new SocketIOFileUpload(socket);
function createProgressBar(element, size){
var x = 1;
var adder = 1;
function addOne(){
var bars = '<p>|';
for (var i = 0; i < x; i++){
bars += ' | ';
}
bars += '</p>';
element.innerHTML = bars;
if (x === size){
adder = -1;
} else if ( x === 0){
adder = 1;
}
x += adder;
};
setInterval(addOne, 300);
}
function previewFile(){
var preview = document.querySelector('img'); //selects the query named img
var claimName = document.querySelector('input[name=name]');
var selectedFile = document.querySelector('input[name=file]').files[0];
var previewReader = new FileReader();
previewReader.onloadend = function () {
preview.src = previewReader.result;
};
if (selectedFile) {
previewReader.readAsDataURL(selectedFile); // reads the data and sets the img src
claimName.value = selectedFile.name.substring(0, selectedFile.name.indexOf('.'));
} else {
preview.src = '';
}
}
function updatePublishStatus(msg){
document.getElementById('publish-status').innerHTML = msg;
}
uploader.listenOnSubmit(document.getElementById('publish-submit'), document.getElementById('siofu_input'));
document.getElementById('publish-submit').addEventListener('click', function(event){
event.preventDefault();
})
uploader.addEventListener('start', function(event){
var name = document.getElementById('publish-name').value;
var license = document.getElementById('publish-license').value;
var nsfw = document.getElementById('publish-nsfw').value;
// set meta data
event.file.meta.name = name;
event.file.meta.license = license;
event.file.meta.nsfw = nsfw;
// set the html of the publish area
document.getElementById('publish').innerHTML = '<div id="publish-status"></div><div id="progress-bar"></div>';
// start the progress bar
createProgressBar(document.getElementById('progress-bar'), 12);
});
uploader.addEventListener('progress', function(event){
var percent = event.bytesLoaded / event.file.size * 100;
updatePublishStatus('File is ' + percent.toFixed(2) + '% loaded to the server');
})
socket.on('publish-status', function(msg){
updatePublishStatus(msg);
})
socket.on('publish-failure', function(msg){
document.getElementById('publish').innerHTML = '<p>' + msg + '</p><p> --(✖╭╮✖)→ </p>';
})
socket.on('publish-complete', function(msg){
var publishResults = '<p>Your publish is complete!</p>';
publishResults += '<p>Your Claim ID is: ' + msg.result.claim_id + '</p>';
publishResults += '<p>Your Transaction ID is: <a href="https://explorer.lbry.io/#!/transaction?id=' + msg.result.txid + '">' + msg.result.txid + '</a></p>';
publishResults += '<p>Here is a link to the claim where your asset was published: <a href="https://spee.ch/' + msg.name + '">spee.ch/' + msg.name + '</a></p>';
publishResults += '<p>Here is a direct link to your asset: <a href="https://spee.ch/' + msg.name + '/' + msg.result.claim_id + '">spee.ch/' + msg.name + '/' + msg.result.claim_id + '</a></p>';
publishResults += '<p><i>NOTE: the transaction still needs to be mined by the network before you can access it! This may take a few minutes. To to view the transaction on the blockchain explorer click the Transaction ID link above.</i></p>';
publishResults += '<p><a href="/">Reload to publish another asset</a></p>';
document.getElementById('publish').innerHTML = publishResults;
})
</script>

View file

@ -4,11 +4,10 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge"> <meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>No Claims</title> <link rel="stylesheet" href="/assets/css/style.css" type="text/css">
<title>Spee.ch</title>
</head> </head>
<body> <body>
<h1>spee.ch</h1> {{{ body }}}
<h3>Invalid URI</h3>
<p>There is no claim at that URI.</p>
</body> </body>
</html> </html>

View file

@ -0,0 +1,4 @@
<h1>spee.ch</h1>
<h3>No Claims</h3>
<p>There are no free, public images at that claim. You should publish one at <a href="/">spee.ch</a>.</p>
<p>NOTE: it is possible your claim was published, but it is still being processed by the blockchain</p>

View file

@ -0,0 +1,7 @@
<div id="bugs">
<h2>Bugs</h2>
<p>Spee.ch is young and under continuous development so it will have bugs. Please leave an issue on our <a href="https://github.com/lbryio/spee.ch">github</a> if you experience a problem or have suggestions.</p>
<br>&nbsp;.w.
<br>(o|o)
<br>&nbsp;&nbsp;`'`
</div>

View file

@ -0,0 +1,4 @@
<div id="contribute">
<h2>Contribute</h2>
<p>If you would like to help make spee.ch amazing, join our slack channel!</p>
</div>

View file

@ -0,0 +1,39 @@
<div id="documentation">
<h2>Documentation</h2>
<h3>Site Navigation</h3>
<ul>
<li><strong><a href="/">spee.ch</a></strong>.
<ul>
<li>To publish a file, navigate to the homepage.</li>
</ul>
</li>
<li><strong>spee.ch/&ltthe name of the claim&gt</strong>
<ul>
<li>To view the file with the largest bid at a claim.</li>
<li>E.g. <a href="/doitlive">spee.ch/doitlive</a>.</li>
</ul>
</li>
<li><strong>spee.ch/&lt the name of the claim &gt/&lt the claim_id &gt</strong>
<ul>
<li>To view a specific file at a claim</li>
<li>E.g. <a href="/doitlive/c496c8c55ed79816fec39e36a78645aa4458edb5">spee.ch/doitlive/c496c8c55ed79816fec39e36a78645aa4458edb5</a></li>
</ul>
</li>
<li><strong>spee.ch/&ltthe name of the claim&gt/all</strong>
<ul>
<li>To view a batch of files at a claim</li>
<li>E.g. <a href="/doitlive/all">spee.ch/doitlive/all</a></li>
</ul>
</li>
</ul>
<h3>API</h3>
<p>Note: these are being used for testing durring spee.ch development and may not be maintained</p>
<ul>
<li>A GET request to <strong>spee.ch/claim_list/&ltthe name of the claim&gt</strong>
<ul>
<li>Will return the claim_list for the claim in json format. </li>
<li>E.g. <a href="/claim_list/doitlive">spee.ch/claim_list/doitlive</a></li>
</ul>
</li>
</ul>
</div>

View file

@ -0,0 +1,10 @@
<div id="examples">
<h2>Examples:</h2>
<ul>
<li><a href="/coconuts">spee.ch/coconuts</a></li>
<li><a href="/wood">spee.ch/wood</a></li>
<li><a href="/doitlive">spee.ch/doitlive</a></li>
<li><a href="/doitlive/all">spee.ch/doitlive/all</a></li>
<li><a href="/doitlive/ca3023187e901df9e9aabd95d6ae09b6cc69b3f0">spee.ch/doitlive/ca3023187e901df9e9aabd95d6ae09b6cc69b3f0</a></li>
</ul>
</div>

View file

@ -0,0 +1,6 @@
<div id="links">
<h2>Links</h2>
<a href="https://github.com/lbryio/spee.ch">github</a>
<a href="https://lbry.io/">lbry</a>
<a href="https://lbry.slack.com">slack</a>
</div>

View file

@ -0,0 +1,22 @@
<div id="publish">
<h2>Publish Your Own</h2>
<form id="publish-form" action="" method="" enctype="multipart/form-data">
<input type="file" id="siofu_input" name="file" accept="video/*,image/*" onchange="previewFile()" enctype="multipart/form-data"/>
<br/>
<img id="image-preview" src="" height="200" alt="Image preview..."/>
<br/>
Name: <input type="text" id="publish-name" name="name" value="name"/>
<br/>
License: <select type="text" id="publish-license" name="license" value="license">
<option value="Public Domain">Public Domain</option>
<option value="Creative Commons">Creative Commons</option>
</select>
<br/>
NSFW: <select type="text" id="publish-nsfw" name="nsfw" value="false">
<option value="false">False</option>
<option value="true">True</option>
</select>
<p><i>By clicking 'Publish' I attest that I have read and agree to the <a href="https://lbry.io/termsofservice" target="_blank">LBRY terms of service</a>.</i></p>
<button id="publish-submit">Publish</button>
</form>
</div>