adding web sockets (part 1) #15

Merged
bones7242 merged 6 commits from master into master 2017-05-26 10:37:42 +02:00
2 changed files with 29 additions and 20 deletions
Showing only changes of commit 5d87fe7f5e - Show all commits

View file

@ -23,9 +23,11 @@
<br/>
<img src="" height="200" alt="Image preview..."/>
<br/>
Name: <input type="text" name="name" value="name"/>
<br/>
Title: <input type="text" name="title" value="title"/>
<br/>
Description: <input type="text" name="description" value="description"/>
Description: <input type="text" name="description" value="I love spee.ch!"/>
<br/>
Author: <input type="text" name="author" value="author"/>
<br/>
@ -36,9 +38,9 @@
<option value="Public Domain">Public Domain</option>
</select>
<br/>
NSFW: <select type="text" name="nsfw" value="nsfw">
NSFW: <select type="text" name="nsfw" value="false">
<option value="false">False</option>
<option value="true">True</option>
<option value="false">False</option>
</select>
<br/>
<button type="submit">Submit</button>

View file

@ -6,6 +6,27 @@ var multipartMiddleware = multipart();
var lbryApi = require('../helpers/lbryApi.js');
var queueApi = require('../helpers/queueApi.js');
// helper functions
function createPublishObject(req){
var publishObject = {
"method":"publish",
"params": {
"name": req.body.name,
"file_path": req.files.file.path,
"bid": 0.1,
"metadata": {
"description": req.body.description,
"title": req.body.title,
"author": req.body.author,
"language": req.body.language,
"license": req.body.license,
"nsfw": req.body.nsfw
}
}
};
return publishObject;
}
// routes to export
module.exports = function(app){
// route to fetch one free public claim
@ -15,25 +36,10 @@ module.exports = function(app){
});
// route to publish a new claim
app.post("/publish", multipartMiddleware, function(req, res){
// receive the request
console.log(" >> POST request on /publish");
// build the data needed to publish the file
var publishObject = {
"method":"publish",
"params": {
"name": req.body.title,
"file_path": req.files.file.path,
"bid": 0.1,
"metadata": {
"description": req.body.description,
"title": req.body.title,
"author": req.body.author,
"language": req.body.language,
"license": req.body.license,
"nsfw": req.body.nsfw.value
}
}
};
var publishObject = createPublishObject(req);
console.log("publish", publishObject);
// post the task to the que
queueApi.addNewTaskToQueue(JSON.stringify({
type: 'publish',
@ -64,6 +70,7 @@ module.exports = function(app){
app.get("/", function(req, res){
res.sendFile(path.join(__dirname, '../public', 'index.html'));
});
// a catch-all route if someone visits a page that does not exist
app.use("*", function(req, res){
res.sendFile(path.join(__dirname, '../public', 'fourOhfour.html'));