From 2776e37c6dce1f7ef197b23282e61481f83ba240 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Wed, 24 May 2017 22:50:02 -0700 Subject: [PATCH 1/5] sockets.io with text-string test --- package.json | 3 ++- public/claim.html | 28 ++++++++++++++++++++++++++++ public/eagle.jpg | Bin 0 -> 21792 bytes public/index.html | 5 ++++- routes/html-routes.js | 7 +++---- routes/sockets-routes.js | 27 +++++++++++++++++++++++++++ server.js | 18 ++++++++++++++---- 7 files changed, 78 insertions(+), 10 deletions(-) create mode 100644 public/claim.html create mode 100644 public/eagle.jpg create mode 100644 routes/sockets-routes.js diff --git a/package.json b/package.json index c5793764..38ad5ab0 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "body-parser": "^1.17.1", "connect-multiparty": "^2.0.0", "express": "^4.15.2", - "nodemon": "^1.11.0" + "nodemon": "^1.11.0", + "socket.io": "^2.0.1" } } diff --git a/public/claim.html b/public/claim.html new file mode 100644 index 00000000..f7641fda --- /dev/null +++ b/public/claim.html @@ -0,0 +1,28 @@ + + + + + + + Spee.ch Claim + + +

spee.ch

+

spee.ch is a single-serving site that reads and publishes images to and from the LBRY blockchain.

+

Status:

+

your image is being retrieved

+ + + + \ No newline at end of file diff --git a/public/eagle.jpg b/public/eagle.jpg new file mode 100644 index 0000000000000000000000000000000000000000..cb7367384cc4e8e315aea84409233a015b970132 GIT binary patch literal 21792 zcmb@t1yEc;+b%eGf(Drc2o^MGupzj++YB&Ba2X`H3~osnToVR&hGB4*1PQLeJ-9=H zB|$=#@BX*$e`{;EYHN49PuF?s?YFx7>3(a@^mF?BTllvQc%rVXrVPNs!UCv1WWc{o zY&tasg*UqTI?8IAN)HtP05-9UjjI>-69B-~&D&F7MV`sn1jA>$0B``D05K~Y zFLyazT}{CMZTdC$;Qf%MdH>Va|E=5qbp@fVotMo+)!jp}uyObF1^}?k9x#!gxBGvv z;{&F$cK#nY=s(!=VSo?zr2k-t|H8%p!{@(n%m45()K_@$8GXRA4*wgr{@?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309P5|{ZVF=xj%Su?Nj)I?>3I0xPNu4Bdes8|_P^3Ak= zTIDZ%LSmelc{%xk>BVwa*VA1{WRUmZ4uX@F(Bl$Y3$qjYf-(8=UeTgl0!YaFwcx2; zzJ;r-4pvtHD)3M8q@+2m4&TJul0_2&!zUX@sjn20M=V&e$?sZvuB9dA#`fqqQSDhc z=Ap8ptcaVaG)CCZr8tl0NEU`selfUy6xZufLhTvPT6X-Co-92;D@rT2Eh@&GAk=sjMl_slSG3bjTzc$tobIB*a&cH zJXFkhrgCveLIH|Q;N%`@&BZVZ8WE_Pwfc+;i81M#rzOPF5?)4PeN9y~3J@fRitfA< z9_>w-jD?8j@vabbuJgk;OK7{WOUt;DJ0xQ``jb^1(5JEJ-XYY|+QEXb4n_b!t}DWC zZzZ^yq;r-(=M|x=YS$OChLG?$RUH7V6H|Rgm5uuyK*wybDZ!FlvGf({kz6cRv7%ss z$^L@8EE1#<+nUy!Si5n6+eSNk(^Ao*9CbUbPg!0;eo6d=aW|Tbl3*yn2S3nOKw^13 znn!LZxk@P!vl2-snr>+iS}6|4YvG%qvJ@wrf}*?KZu@1sasa{Ryk64f;F%;|s&iTz zj<0ce-!>I{D68hu#5nuKOPhl<#k+PM)ltnj4k{+=QPi`n@a^=mOvn$)Mt#T9y&CE^ zcwimgUVVTS@8t&oT|v*r4nB51U>6jFtvfW7x&a`?I4B~bJQ|f41wTVc_bCFiFG6WZsTU%n&nAF*rU=%zY?1j? z03VoDc%1IVTTE}oNqq<(txpzkYAHq-)8ahUSVWtMso`O?f_W8CoE%VCjzwy;A(iga z2R(CH_{C{E7L1GzwV%?9=u6y?3X}s(LsJ5J)V}4UCOP`mxIxWU&P83fIbp|InMi3G zeE`Vq$Kgy9!Vc^algRWnQd`+101yBNwKcJk#|$uk#+qK}UhIzH!cVzR%H1l! - + + \ No newline at end of file diff --git a/routes/html-routes.js b/routes/html-routes.js index 2f358a86..9df16a12 100644 --- a/routes/html-routes.js +++ b/routes/html-routes.js @@ -18,7 +18,7 @@ module.exports = function(app){ // receive the request console.log(" >> POST request on /publish"); //console.log(">> req.files:", req.files) - console.log(" >> req.body:", req.body) + //console.log(" >> req.body:", req.body) // build the data needed to publish the file var publishObject = { @@ -64,10 +64,9 @@ module.exports = function(app){ app.get("/:name", function(req, res){ var name = req.params.name; console.log(">> GET request on /" + name) - // publish a message to the cue - // queueApi.addNewTaskToQueue("return claim for " + req.params.name + " ...") // retrieve the claim - lbryApi.serveClaimBasedOnNameOnly(name, res); + //lbryApi.serveClaimBasedOnNameOnly(name, res); + res.status(200).sendFile(path.join(__dirname, '../public', 'claim.html')); }); // route for the home page app.get("/", function(req, res){ diff --git a/routes/sockets-routes.js b/routes/sockets-routes.js new file mode 100644 index 00000000..e66b7e96 --- /dev/null +++ b/routes/sockets-routes.js @@ -0,0 +1,27 @@ + +// routes to export +module.exports = function(app) { + var http = require("http").Server(app); + var io = require("socket.io")(http); + + io.on('connection', function(socket){ + console.log('a user connected'); + + // trying to serve an image file from the server + socket.on('image-request', function(data){ + // 1. retrieve the image from lbry via daemon + console.log("received image request for:", data) + // 2. emit updates as the image is being retrieved + + // 3. serve the image back once it is retrieved + socket.emit("image-send", "test string for: " + data); + }) + + // handle disconnect + socket.on('disconnect', function(){ + console.log('user disconnected'); + }); + }); + + return http; +} \ No newline at end of file diff --git a/server.js b/server.js index b812f4cb..5872b342 100644 --- a/server.js +++ b/server.js @@ -2,19 +2,29 @@ var express = require('express'); var bodyParser = require('body-parser'); var path = require('path'); + // set port var PORT = 3000; -// initialize express + +// initialize express app var app = express(); + // make express look in the public directory for assets (css/js/img) app.use(express.static(__dirname + '/public')); -// configure epress + +// configure express app app.use(bodyParser.json()); // for parsing application/json app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded -// require in routes + +// require express routes require("./routes/api-routes.js")(app); require("./routes/html-routes.js")(app); + +// include socket.io functionality +// this wraps the server in sockets, to intercept incoming sockets requests +var http = require("./routes/sockets-routes.js")(app); + // start server -app.listen(PORT, function() { +http.listen(PORT, function() { console.log("Listening on PORT " + PORT); }); -- 2.45.2 From fec251902e7168cd2b180bb03a7b3012591a29a3 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Thu, 25 May 2017 00:59:22 -0700 Subject: [PATCH 2/5] converted single-claim search to socket with promise --- helpers/lbryApi-old.js | 173 +++++++++++++++++++++++++++++++++++++++ helpers/lbryApi.js | 123 +++++++++++++++++----------- public/claim.html | 11 ++- routes/sockets-routes.js | 48 +++++++++-- 4 files changed, 298 insertions(+), 57 deletions(-) create mode 100644 helpers/lbryApi-old.js diff --git a/helpers/lbryApi-old.js b/helpers/lbryApi-old.js new file mode 100644 index 00000000..e1ca554e --- /dev/null +++ b/helpers/lbryApi-old.js @@ -0,0 +1,173 @@ +// load dependencies +var path = require('path'); +var axios = require('axios'); + +// helper function to filter an array of claims for only free, public claims +function filterForFreePublicClaims(claimsListArray){ + //console.log(">> filterForFreePublicClaims, claimsListArray:", claimsListArray); + if (!claimsListArray) { + return null; + }; + var freePublicClaims = claimsListArray.filter(function(claim){ + return (((claim.value.stream.metadata.license.indexOf('Public Domain') != -1) || (claim.value.stream.metadata.license.indexOf('Creative Commons') != -1)) && + (!claim.value.stream.metadata.fee || claim.value.stream.metadata.fee === 0)); + }); + return freePublicClaims; +} +// helper function to decide if a claim is free and public +function isFreePublicClaim(claim){ + console.log(">> isFreePublicClaim, claim:", claim); + if ((claim.value.stream.metadata.license === 'Public Domain' || claim.value.stream.metadata.license === 'Creative Commons') && + (!claim.value.stream.metadata.fee || claim.value.stream.metadata.fee.amount === 0)) { + return true; + } else { + return false; + } +} +// helper function to order a set of claims +function orderTopClaims(claimsListArray){ + console.log(">> orderTopClaims, claimsListArray:"); + claimsListArray.sort(function(claimA, claimB){ + if (claimA.amount === claimB.amount){ + return (claimA.height > claimB.height); + } else { + return (claimA.amount < claimB.amount); + } + }) + return claimsListArray; +} + +module.exports = { + publishClaim: function(publishObject){ + axios.post('http://localhost:5279/lbryapi', publishObject) + .then(function (response) { + // receive resonse from LBRY + // if successfull, (1) delete file (2) send response to the client + console.log(">> 'publish' success..."); + console.log(">> 'publish' response.data:", response.data); + console.log(" [x] Done"); + // return the claim we got + //res.status(200).send(JSON.stringify({msg: "you succsessfully published!", txData: response.data})); + }).catch(function(error){ + // receive response from LBRY + // if not successfull, (1) delete file and (2) send response to the client + console.log(">> 'publish' error.response.data:", error.response.data); + console.log(" [x] Done"); + //res.status(500).send(JSON.stringify({msg: "your file was not published", err: error.response.data.error.message})); + }) + }, + serveClaimBasedOnNameOnly: function(claimName, res){ + // make a call to the daemon to get the claims list + axios.post('http://localhost:5279/lbryapi', { + method: "claim_list", + params: { + name: claimName + } + } + ).then(function (response) { + console.log(">> Claim_list success"); + console.log(">> Number of claims:", response.data.result.claims.length) + // return early if no claims were found + if (response.data.result.claims.length === 0){ + res.status(200).sendFile(path.join(__dirname, '../public', 'noClaims.html')); + return; + } + // filter the claims to return free, public claims + var freePublicClaims = filterForFreePublicClaims(response.data.result.claims); + // return early if no free, public claims were found + if (!freePublicClaims || (freePublicClaims.length === 0)){ + res.status(200).sendFile(path.join(__dirname, '../public', 'noClaims.html')); + return; + } + // order the claims + var orderedPublcClaims = orderTopClaims(freePublicClaims); + // create the uri for the first (selected) claim + console.log(">> ordered free public claims", orderedPublcClaims); + var freePublicClaimUri = "lbry://" + orderedPublcClaims[0].name + "#" + orderedPublcClaims[0].claim_id; + console.log(">> your free public claim uri:", freePublicClaimUri); + // fetch the image to display + axios.post('http://localhost:5279/lbryapi', { + method: "get", + params: { + uri: freePublicClaimUri + } + } + ).then(function (getResponse) { + console.log(">> 'get claim' success..."); + console.log(">> response data:", getResponse.data); + console.log(">> dl path =", getResponse.data.result.download_path) + // return the claim we got + res.status(200).sendFile(getResponse.data.result.download_path); + }).catch(function(getError){ + console.log(">> /c/ 'get' error:", getError.response.data); + res.status(500).send(JSON.stringify({msg: "An error occurred while fetching the free, public claim by URI.", err: getError.response.data.error.message})); + }) + }).catch(function(error){ + console.log(">> /c/ error:", error.response.data); + res.status(500).send(JSON.stringify({msg: "An error occurred while getting the claim list.", err: error.response.data.error.message})); + }) + }, + serveClaimBasedOnUri: function(uri, res){ + /* + to do: need to pass the URI through a test (use 'resolve') to see if it is free and public. Right now it is jumping straight to 'get'ing and serving the asset. + */ + console.log(">> your uri:", uri); + // fetch the image to display + axios.post('http://localhost:5279/lbryapi', { // to do: abstract this code to a function that can be shared + method: "get", + params: { + uri: uri + } + } + ).then(function (getResponse) { + console.log(">> 'get claim' success..."); + console.log(">> response data:", getResponse.data); + console.log(">> dl path =", getResponse.data.result.download_path) + /* + to do: make sure the file has completed downloading before serving back the file + */ + // return the claim we got + res.status(200).sendFile(getResponse.data.result.download_path); + + /* delete the file after a certain amount of time? */ + + }).catch(function(error){ + console.log(">> /c/ 'get' error:", error.response.data); + res.status(500).send(JSON.stringify({msg: "an error occurred", err: error.response.data.error.message})); + }) + }, + serveAllClaims: function(claimName, res){ + // make a call to the daemon to get the claims list + axios.post('http://localhost:5279/lbryapi', { + method: "claim_list", + params: { + name: claimName + } + } + ).then(function (response) { + console.log(">> Claim_list success"); + console.log(">> Number of claims:", response.data.result.claims.length) + // return early if no claims were found + if (response.data.result.claims.length === 0){ + res.status(200).sendFile(path.join(__dirname, '../public', 'noClaims.html')); + return; + } + // filter the claims to return free, public claims + var freePublicClaims = filterForFreePublicClaims(response.data.result.claims); + // return early if no free, public claims were found + if (!freePublicClaims || (freePublicClaims.length === 0)){ + res.status(200).sendFile(path.join(__dirname, '../public', 'noClaims.html')); + return; + } + console.log(">> Number of free public claims:", freePublicClaims.length); + // order the claims + var orderedPublicClaims = orderTopClaims(freePublicClaims); + // serve the response + res.status(200).send(orderedPublicClaims); //to do: rather than returning json, serve a page of all these claims + }).catch(function(error){ + console.log(">> /c/ error:", error.response.data); + // serve the response + res.status(500).send(JSON.stringify({msg: "An error occurred while finding the claim list.", err: error.response.data.error.message})); + }) + } +} diff --git a/helpers/lbryApi.js b/helpers/lbryApi.js index e1ca554e..5f4687ce 100644 --- a/helpers/lbryApi.js +++ b/helpers/lbryApi.js @@ -56,56 +56,83 @@ module.exports = { //res.status(500).send(JSON.stringify({msg: "your file was not published", err: error.response.data.error.message})); }) }, - serveClaimBasedOnNameOnly: function(claimName, res){ - // make a call to the daemon to get the claims list - axios.post('http://localhost:5279/lbryapi', { - method: "claim_list", - params: { - name: claimName - } - } - ).then(function (response) { - console.log(">> Claim_list success"); - console.log(">> Number of claims:", response.data.result.claims.length) - // return early if no claims were found - if (response.data.result.claims.length === 0){ - res.status(200).sendFile(path.join(__dirname, '../public', 'noClaims.html')); - return; - } - // filter the claims to return free, public claims - var freePublicClaims = filterForFreePublicClaims(response.data.result.claims); - // return early if no free, public claims were found - if (!freePublicClaims || (freePublicClaims.length === 0)){ - res.status(200).sendFile(path.join(__dirname, '../public', 'noClaims.html')); - return; - } - // order the claims - var orderedPublcClaims = orderTopClaims(freePublicClaims); - // create the uri for the first (selected) claim - console.log(">> ordered free public claims", orderedPublcClaims); - var freePublicClaimUri = "lbry://" + orderedPublcClaims[0].name + "#" + orderedPublcClaims[0].claim_id; - console.log(">> your free public claim uri:", freePublicClaimUri); - // fetch the image to display + getClaimBasedOnNameOnly: function(claimName){ + // 1. create a promise + var deferred = new Promise(function (resolve, reject){ + // 2. code to resolve or reject the promise + // make a call to the daemon to get the claims list axios.post('http://localhost:5279/lbryapi', { - method: "get", - params: { - uri: freePublicClaimUri - } - } - ).then(function (getResponse) { - console.log(">> 'get claim' success..."); - console.log(">> response data:", getResponse.data); - console.log(">> dl path =", getResponse.data.result.download_path) - // return the claim we got - res.status(200).sendFile(getResponse.data.result.download_path); - }).catch(function(getError){ - console.log(">> /c/ 'get' error:", getError.response.data); - res.status(500).send(JSON.stringify({msg: "An error occurred while fetching the free, public claim by URI.", err: getError.response.data.error.message})); + method: "claim_list", + params: { name: claimName } }) - }).catch(function(error){ - console.log(">> /c/ error:", error.response.data); - res.status(500).send(JSON.stringify({msg: "An error occurred while getting the claim list.", err: error.response.data.error.message})); - }) + .then(function (response) { + console.log(">> Claim_list success"); + console.log(">> Number of claims:", response.data.result.claims.length) + // return early if no claims were found + if (response.data.result.claims.length === 0){ + reject({ + msg: "no claims", + err: "no claims" + }); + return; + } + // filter the claims to return free, public claims + var freePublicClaims = filterForFreePublicClaims(response.data.result.claims); + // return early if no free, public claims were found + if (!freePublicClaims || (freePublicClaims.length === 0)){ + reject({ + msg: "no free, public claims", + err: "no free, public claims" + }); + return; + } + // order the claims + var orderedPublcClaims = orderTopClaims(freePublicClaims); + // create the uri for the first (selected) claim + console.log(">> ordered free public claims", orderedPublcClaims); + var freePublicClaimUri = "lbry://" + orderedPublcClaims[0].name + "#" + orderedPublcClaims[0].claim_id; + console.log(">> your free public claim uri:", freePublicClaimUri); + // fetch the image to display + axios.post('http://localhost:5279/lbryapi', { + method: "get", + params: { uri: freePublicClaimUri } + } + ).then(function (getResponse) { + console.log(">> 'get claim' success..."); + console.log(">> response data:", getResponse.data); + console.log(">> dl path =", getResponse.data.result.download_path) + // resolve the promise with the download path for the claim we got + resolve(getResponse.data.result.download_path); + }).catch(function(getError){ + console.log(">> 'get' error:", getError.response.data); + // reject the promise with an error message + reject({ + msg: "An error occurred while fetching the free, public claim by URI.", + err: getError.response.data.error.message + }); + }); + }) + .catch(function(error){ + console.log(">> error:", error.response.data); + // check to see what kind of error came back from lbry + // reject the promise with an approriate message + if (error.response.data){ + reject({ + msg: "An error occurred while getting the claim list.", + err: error.response.data.error.message + }); + } else { + reject({ + msg: "An error occurred while getting the claim list.", + err: error.response + }); + } + + }); + }); + // 3. return the promise + return deferred; + }, serveClaimBasedOnUri: function(uri, res){ /* diff --git a/public/claim.html b/public/claim.html index f7641fda..5d76b38e 100644 --- a/public/claim.html +++ b/public/claim.html @@ -11,6 +11,7 @@

spee.ch is a single-serving site that reads and publishes images to and from the LBRY blockchain.

Status:

your image is being retrieved

+
diff --git a/routes/sockets-routes.js b/routes/sockets-routes.js index e66b7e96..fb6a107a 100644 --- a/routes/sockets-routes.js +++ b/routes/sockets-routes.js @@ -1,20 +1,52 @@ // routes to export module.exports = function(app) { - var http = require("http").Server(app); - var io = require("socket.io")(http); + var http = require('http').Server(app); + var io = require('socket.io')(http); + var fs = require('fs'); + var path = require('path'); + var lbryApi = require('../helpers/lbryApi.js'); + + function sendTheImage(socket, filePath){ + fs.readFile(filePath, function(err, buff){ + if (err) { + console.log("fs err", err); + return; + }; + //console.log("buff", buff); + socket.emit('image-send', { image: true, buffer: buff.toString('base64') }); + console.log('image file has been sent via sockets'); + }); + } io.on('connection', function(socket){ console.log('a user connected'); - // trying to serve an image file from the server - socket.on('image-request', function(data){ + // serve an image file from the server + socket.on('image-request', function(name){ // 1. retrieve the image from lbry via daemon - console.log("received image request for:", data) + console.log("received image request for:", name) + var promise = lbryApi.getClaimBasedOnNameOnly(name); + promise.then(function(data){ + console.log("socket-routes / image-request - success:", data) + // 3. serve the image back once it is retrieved + sendTheImage(socket, data); + }) + .catch(function(error){ + console.log("socket-routes / image-request - error:", error) + // handle the errors + if (error.msg === "no claims"){ + socket.emit("image-update", "no claims were found for " + name); + } else if (error.msg === "no free, public claims"){ + socket.emit("image-update", "no free, public claims were found for " + name); + } else { + socket.emit("image-update", "an unknown error occured with fetching claim"); + }; + return; + }); + // 2. emit updates as the image is being retrieved - - // 3. serve the image back once it is retrieved - socket.emit("image-send", "test string for: " + data); + socket.emit("image-update", "we are getting your image for " + name); }) // handle disconnect -- 2.45.2 From 654c95e7ed280b3dd512e685d455857f05f6fadb Mon Sep 17 00:00:00 2001 From: bill bittner Date: Fri, 26 May 2017 00:34:25 -0700 Subject: [PATCH 3/5] sockets work for /claim and /claim/claim_id --- helpers/lbryApi.js | 134 ++++++++++++++++++--------------------- public/claim.html | 6 +- routes/html-routes.js | 14 +--- routes/sockets-routes.js | 36 +++++------ 4 files changed, 84 insertions(+), 106 deletions(-) diff --git a/helpers/lbryApi.js b/helpers/lbryApi.js index 5f4687ce..681f17e3 100644 --- a/helpers/lbryApi.js +++ b/helpers/lbryApi.js @@ -37,7 +37,30 @@ function orderTopClaims(claimsListArray){ return claimsListArray; } +function getClaimWithUri(uri, resolve, reject){ + axios.post('http://localhost:5279/lbryapi', { + method: "get", + params: { uri: uri } + } + ).then(function (getUriResponse) { + console.log(">> 'get claim' success..."); + console.log(">> response data:", getUriResponse.data); + console.log(">> dl path =", getUriResponse.data.result.download_path) + // resolve the promise with the download path for the claim we got + /* note: do not resolve until the download is actually complete */ + resolve(getUriResponse.data.result.download_path); + }).catch(function(getUriError){ + console.log(">> 'get' error:", getUriError.response.data); + // reject the promise with an error message + reject({ + msg: "An error occurred while fetching the free, public claim by URI.", + err: getUriError.response.data.error.message + }); + }); +} + module.exports = { + publishClaim: function(publishObject){ axios.post('http://localhost:5279/lbryapi', publishObject) .then(function (response) { @@ -56,120 +79,82 @@ module.exports = { //res.status(500).send(JSON.stringify({msg: "your file was not published", err: error.response.data.error.message})); }) }, + getClaimBasedOnNameOnly: function(claimName){ // 1. create a promise var deferred = new Promise(function (resolve, reject){ // 2. code to resolve or reject the promise // make a call to the daemon to get the claims list - axios.post('http://localhost:5279/lbryapi', { - method: "claim_list", + axios.post('http://localhost:5279/lbryapi', { // receives a promise + method: "claim_list", params: { name: claimName } }) .then(function (response) { console.log(">> Claim_list success"); - console.log(">> Number of claims:", response.data.result.claims.length) + + var claimsList = response.data.result.claims; + console.log(">> Number of claims:", claimsList.length) + // return early if no claims were found - if (response.data.result.claims.length === 0){ - reject({ - msg: "no claims", - err: "no claims" - }); + if (claimsList.length === 0){ + reject("no claims were found"); + console.log("exiting due to lack of claims"); return; } - // filter the claims to return free, public claims - var freePublicClaims = filterForFreePublicClaims(response.data.result.claims); + + // filter the claims to return only free, public claims + var freePublicClaims = filterForFreePublicClaims(claimsList); + // return early if no free, public claims were found if (!freePublicClaims || (freePublicClaims.length === 0)){ - reject({ - msg: "no free, public claims", - err: "no free, public claims" - }); + reject("no free, public claims were found"); + console.log("exiting due to lack of free or public claims"); return; } + // order the claims var orderedPublcClaims = orderTopClaims(freePublicClaims); + // create the uri for the first (selected) claim console.log(">> ordered free public claims", orderedPublcClaims); var freePublicClaimUri = "lbry://" + orderedPublcClaims[0].name + "#" + orderedPublcClaims[0].claim_id; console.log(">> your free public claim uri:", freePublicClaimUri); + // fetch the image to display - axios.post('http://localhost:5279/lbryapi', { - method: "get", - params: { uri: freePublicClaimUri } - } - ).then(function (getResponse) { - console.log(">> 'get claim' success..."); - console.log(">> response data:", getResponse.data); - console.log(">> dl path =", getResponse.data.result.download_path) - // resolve the promise with the download path for the claim we got - resolve(getResponse.data.result.download_path); - }).catch(function(getError){ - console.log(">> 'get' error:", getError.response.data); - // reject the promise with an error message - reject({ - msg: "An error occurred while fetching the free, public claim by URI.", - err: getError.response.data.error.message - }); - }); + getClaimWithUri(freePublicClaimUri, resolve, reject); + }) .catch(function(error){ - console.log(">> error:", error.response.data); - // check to see what kind of error came back from lbry + console.log(">> error:", error); // reject the promise with an approriate message - if (error.response.data){ - reject({ - msg: "An error occurred while getting the claim list.", - err: error.response.data.error.message - }); - } else { - reject({ - msg: "An error occurred while getting the claim list.", - err: error.response - }); - } - + reject(error.response.data.error); + return; }); }); // 3. return the promise return deferred; }, - serveClaimBasedOnUri: function(uri, res){ + + getClaimBasedOnUri: function(uri){ /* to do: need to pass the URI through a test (use 'resolve') to see if it is free and public. Right now it is jumping straight to 'get'ing and serving the asset. */ - console.log(">> your uri:", uri); - // fetch the image to display - axios.post('http://localhost:5279/lbryapi', { // to do: abstract this code to a function that can be shared - method: "get", - params: { - uri: uri - } - } - ).then(function (getResponse) { - console.log(">> 'get claim' success..."); - console.log(">> response data:", getResponse.data); - console.log(">> dl path =", getResponse.data.result.download_path) - /* - to do: make sure the file has completed downloading before serving back the file - */ - // return the claim we got - res.status(200).sendFile(getResponse.data.result.download_path); + var deferred = new Promise(function (resolve, reject){ + console.log(">> your uri:", uri); - /* delete the file after a certain amount of time? */ + // fetch the image to display + getClaimWithUri(uri, resolve, reject); + }); + return deferred; - }).catch(function(error){ - console.log(">> /c/ 'get' error:", error.response.data); - res.status(500).send(JSON.stringify({msg: "an error occurred", err: error.response.data.error.message})); - }) }, + serveAllClaims: function(claimName, res){ // make a call to the daemon to get the claims list axios.post('http://localhost:5279/lbryapi', { method: "claim_list", - params: { - name: claimName - } + params: { name: claimName } } ).then(function (response) { console.log(">> Claim_list success"); @@ -190,7 +175,10 @@ module.exports = { // order the claims var orderedPublicClaims = orderTopClaims(freePublicClaims); // serve the response - res.status(200).send(orderedPublicClaims); //to do: rather than returning json, serve a page of all these claims + /* + to do: rather than returning json, serve a page of all these claims + */ + res.status(200).send(orderedPublicClaims); }).catch(function(error){ console.log(">> /c/ error:", error.response.data); // serve the response diff --git a/public/claim.html b/public/claim.html index 5d76b38e..6061eb8b 100644 --- a/public/claim.html +++ b/public/claim.html @@ -18,15 +18,15 @@ console.log(document.URL) var url = document.URL.substring(document.URL.indexOf('3000/') + 5); // get from the window? // request the image through the socket - socket.emit("image-request", url); + socket.emit("claim-request", url); - socket.on("image-update", function(data){ + socket.on("claim-update", function(data){ console.log("data:", data); document.getElementById("status").innerHTML = data; }) // receive the image through the socket - socket.on("image-send", function(data){ + socket.on("claim-send", function(data){ if (data.image) { var base64Image = 'data:image/jpeg;base64,' + data.buffer; document.getElementById("image").innerHTML = ''; diff --git a/routes/html-routes.js b/routes/html-routes.js index 9df16a12..f613c356 100644 --- a/routes/html-routes.js +++ b/routes/html-routes.js @@ -17,9 +17,6 @@ module.exports = function(app){ app.post("/publish", multipartMiddleware, function(req, res){ // receive the request console.log(" >> POST request on /publish"); - //console.log(">> req.files:", req.files) - //console.log(" >> req.body:", req.body) - // build the data needed to publish the file var publishObject = { "method":"publish", @@ -37,8 +34,6 @@ module.exports = function(app){ } } }; - //console.log(">> publishObject:", publishObject) - // post the task to the que queueApi.addNewTaskToQueue(JSON.stringify({ type: 'publish', @@ -46,7 +41,6 @@ module.exports = function(app){ })); // respond to the client that the task has been queued res.status(200).sendFile(path.join(__dirname, '../public', 'publishingClaim.html')); - }); // route to fetch one free public claim app.get("/:name/all", function(req, res){ @@ -56,16 +50,14 @@ module.exports = function(app){ }); // route to fetch one free public claim app.get("/:name/:claim_id", function(req, res){ - var uri = "lbry://" + req.params.name + "#" + req.params.claim_id; - console.log(">> GET request on /" + uri); - lbryApi.serveClaimBasedOnUri(uri, res); + console.log(">> GET request on /" + req.params.name + "#" + req.params.claim_id); + res.status(200).sendFile(path.join(__dirname, '../public', 'claim.html')); }); // route to fetch one free public claim app.get("/:name", function(req, res){ var name = req.params.name; console.log(">> GET request on /" + name) - // retrieve the claim - //lbryApi.serveClaimBasedOnNameOnly(name, res); + // send page (includes a socket to get the file) res.status(200).sendFile(path.join(__dirname, '../public', 'claim.html')); }); // route for the home page diff --git a/routes/sockets-routes.js b/routes/sockets-routes.js index fb6a107a..51bbbb0a 100644 --- a/routes/sockets-routes.js +++ b/routes/sockets-routes.js @@ -1,5 +1,3 @@ - -// routes to export module.exports = function(app) { var http = require('http').Server(app); var io = require('socket.io')(http); @@ -10,12 +8,12 @@ module.exports = function(app) { function sendTheImage(socket, filePath){ fs.readFile(filePath, function(err, buff){ if (err) { - console.log("fs err", err); + console.log("socket: fs err:", err); return; }; //console.log("buff", buff); - socket.emit('image-send', { image: true, buffer: buff.toString('base64') }); - console.log('image file has been sent via sockets'); + socket.emit('claim-send', { image: true, buffer: buff.toString('base64') }); + console.log('socket: the image file has been sent via sockets'); }); } @@ -23,30 +21,30 @@ module.exports = function(app) { console.log('a user connected'); // serve an image file from the server - socket.on('image-request', function(name){ + socket.on('claim-request', function(query){ // 1. retrieve the image from lbry via daemon - console.log("received image request for:", name) - var promise = lbryApi.getClaimBasedOnNameOnly(name); + console.log("socket: received claim request for:", query) + if (query.indexOf("/") === -1){ + var promise = lbryApi.getClaimBasedOnNameOnly(query) + } else { + var uri = query.replace("/", "#"); + var promise = lbryApi.getClaimBasedOnUri(uri) + } promise.then(function(data){ - console.log("socket-routes / image-request - success:", data) + console.log("socket: claim-request - success:", data) // 3. serve the image back once it is retrieved sendTheImage(socket, data); + return; }) .catch(function(error){ - console.log("socket-routes / image-request - error:", error) - // handle the errors - if (error.msg === "no claims"){ - socket.emit("image-update", "no claims were found for " + name); - } else if (error.msg === "no free, public claims"){ - socket.emit("image-update", "no free, public claims were found for " + name); - } else { - socket.emit("image-update", "an unknown error occured with fetching claim"); - }; + console.log("socket: claim-request - error:", error) + // handle the error + socket.emit("claim-update", error); return; }); // 2. emit updates as the image is being retrieved - socket.emit("image-update", "we are getting your image for " + name); + socket.emit("claim-update", "We are getting your claim for " + query); }) // handle disconnect -- 2.45.2 From 5d87fe7f5e16c0f5cbff3b519c61a81d9fbcfcaf Mon Sep 17 00:00:00 2001 From: bill bittner Date: Fri, 26 May 2017 00:49:29 -0700 Subject: [PATCH 4/5] added 'name' field to publish --- public/index.html | 8 +++++--- routes/html-routes.js | 41 ++++++++++++++++++++++++----------------- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/public/index.html b/public/index.html index eb7ff418..d5af3d08 100644 --- a/public/index.html +++ b/public/index.html @@ -23,9 +23,11 @@
Image preview...
+ Name: +
Title:
- Description: + Description:
Author:
@@ -36,9 +38,9 @@
- NSFW: + -
diff --git a/routes/html-routes.js b/routes/html-routes.js index f613c356..3f32294f 100644 --- a/routes/html-routes.js +++ b/routes/html-routes.js @@ -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')); -- 2.45.2 From 3d6620d27a977cc08cbc65bcc631ecc3f9096cf4 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Fri, 26 May 2017 01:25:07 -0700 Subject: [PATCH 5/5] handled case of lbry daemon 'get' timeout --- helpers/lbryApi-old.js | 173 ----------------------------------------- helpers/lbryApi.js | 18 +++-- public/claim.html | 21 +++-- 3 files changed, 21 insertions(+), 191 deletions(-) delete mode 100644 helpers/lbryApi-old.js diff --git a/helpers/lbryApi-old.js b/helpers/lbryApi-old.js deleted file mode 100644 index e1ca554e..00000000 --- a/helpers/lbryApi-old.js +++ /dev/null @@ -1,173 +0,0 @@ -// load dependencies -var path = require('path'); -var axios = require('axios'); - -// helper function to filter an array of claims for only free, public claims -function filterForFreePublicClaims(claimsListArray){ - //console.log(">> filterForFreePublicClaims, claimsListArray:", claimsListArray); - if (!claimsListArray) { - return null; - }; - var freePublicClaims = claimsListArray.filter(function(claim){ - return (((claim.value.stream.metadata.license.indexOf('Public Domain') != -1) || (claim.value.stream.metadata.license.indexOf('Creative Commons') != -1)) && - (!claim.value.stream.metadata.fee || claim.value.stream.metadata.fee === 0)); - }); - return freePublicClaims; -} -// helper function to decide if a claim is free and public -function isFreePublicClaim(claim){ - console.log(">> isFreePublicClaim, claim:", claim); - if ((claim.value.stream.metadata.license === 'Public Domain' || claim.value.stream.metadata.license === 'Creative Commons') && - (!claim.value.stream.metadata.fee || claim.value.stream.metadata.fee.amount === 0)) { - return true; - } else { - return false; - } -} -// helper function to order a set of claims -function orderTopClaims(claimsListArray){ - console.log(">> orderTopClaims, claimsListArray:"); - claimsListArray.sort(function(claimA, claimB){ - if (claimA.amount === claimB.amount){ - return (claimA.height > claimB.height); - } else { - return (claimA.amount < claimB.amount); - } - }) - return claimsListArray; -} - -module.exports = { - publishClaim: function(publishObject){ - axios.post('http://localhost:5279/lbryapi', publishObject) - .then(function (response) { - // receive resonse from LBRY - // if successfull, (1) delete file (2) send response to the client - console.log(">> 'publish' success..."); - console.log(">> 'publish' response.data:", response.data); - console.log(" [x] Done"); - // return the claim we got - //res.status(200).send(JSON.stringify({msg: "you succsessfully published!", txData: response.data})); - }).catch(function(error){ - // receive response from LBRY - // if not successfull, (1) delete file and (2) send response to the client - console.log(">> 'publish' error.response.data:", error.response.data); - console.log(" [x] Done"); - //res.status(500).send(JSON.stringify({msg: "your file was not published", err: error.response.data.error.message})); - }) - }, - serveClaimBasedOnNameOnly: function(claimName, res){ - // make a call to the daemon to get the claims list - axios.post('http://localhost:5279/lbryapi', { - method: "claim_list", - params: { - name: claimName - } - } - ).then(function (response) { - console.log(">> Claim_list success"); - console.log(">> Number of claims:", response.data.result.claims.length) - // return early if no claims were found - if (response.data.result.claims.length === 0){ - res.status(200).sendFile(path.join(__dirname, '../public', 'noClaims.html')); - return; - } - // filter the claims to return free, public claims - var freePublicClaims = filterForFreePublicClaims(response.data.result.claims); - // return early if no free, public claims were found - if (!freePublicClaims || (freePublicClaims.length === 0)){ - res.status(200).sendFile(path.join(__dirname, '../public', 'noClaims.html')); - return; - } - // order the claims - var orderedPublcClaims = orderTopClaims(freePublicClaims); - // create the uri for the first (selected) claim - console.log(">> ordered free public claims", orderedPublcClaims); - var freePublicClaimUri = "lbry://" + orderedPublcClaims[0].name + "#" + orderedPublcClaims[0].claim_id; - console.log(">> your free public claim uri:", freePublicClaimUri); - // fetch the image to display - axios.post('http://localhost:5279/lbryapi', { - method: "get", - params: { - uri: freePublicClaimUri - } - } - ).then(function (getResponse) { - console.log(">> 'get claim' success..."); - console.log(">> response data:", getResponse.data); - console.log(">> dl path =", getResponse.data.result.download_path) - // return the claim we got - res.status(200).sendFile(getResponse.data.result.download_path); - }).catch(function(getError){ - console.log(">> /c/ 'get' error:", getError.response.data); - res.status(500).send(JSON.stringify({msg: "An error occurred while fetching the free, public claim by URI.", err: getError.response.data.error.message})); - }) - }).catch(function(error){ - console.log(">> /c/ error:", error.response.data); - res.status(500).send(JSON.stringify({msg: "An error occurred while getting the claim list.", err: error.response.data.error.message})); - }) - }, - serveClaimBasedOnUri: function(uri, res){ - /* - to do: need to pass the URI through a test (use 'resolve') to see if it is free and public. Right now it is jumping straight to 'get'ing and serving the asset. - */ - console.log(">> your uri:", uri); - // fetch the image to display - axios.post('http://localhost:5279/lbryapi', { // to do: abstract this code to a function that can be shared - method: "get", - params: { - uri: uri - } - } - ).then(function (getResponse) { - console.log(">> 'get claim' success..."); - console.log(">> response data:", getResponse.data); - console.log(">> dl path =", getResponse.data.result.download_path) - /* - to do: make sure the file has completed downloading before serving back the file - */ - // return the claim we got - res.status(200).sendFile(getResponse.data.result.download_path); - - /* delete the file after a certain amount of time? */ - - }).catch(function(error){ - console.log(">> /c/ 'get' error:", error.response.data); - res.status(500).send(JSON.stringify({msg: "an error occurred", err: error.response.data.error.message})); - }) - }, - serveAllClaims: function(claimName, res){ - // make a call to the daemon to get the claims list - axios.post('http://localhost:5279/lbryapi', { - method: "claim_list", - params: { - name: claimName - } - } - ).then(function (response) { - console.log(">> Claim_list success"); - console.log(">> Number of claims:", response.data.result.claims.length) - // return early if no claims were found - if (response.data.result.claims.length === 0){ - res.status(200).sendFile(path.join(__dirname, '../public', 'noClaims.html')); - return; - } - // filter the claims to return free, public claims - var freePublicClaims = filterForFreePublicClaims(response.data.result.claims); - // return early if no free, public claims were found - if (!freePublicClaims || (freePublicClaims.length === 0)){ - res.status(200).sendFile(path.join(__dirname, '../public', 'noClaims.html')); - return; - } - console.log(">> Number of free public claims:", freePublicClaims.length); - // order the claims - var orderedPublicClaims = orderTopClaims(freePublicClaims); - // serve the response - res.status(200).send(orderedPublicClaims); //to do: rather than returning json, serve a page of all these claims - }).catch(function(error){ - console.log(">> /c/ error:", error.response.data); - // serve the response - res.status(500).send(JSON.stringify({msg: "An error occurred while finding the claim list.", err: error.response.data.error.message})); - }) - } -} diff --git a/helpers/lbryApi.js b/helpers/lbryApi.js index 681f17e3..8a09f13e 100644 --- a/helpers/lbryApi.js +++ b/helpers/lbryApi.js @@ -38,24 +38,29 @@ function orderTopClaims(claimsListArray){ } function getClaimWithUri(uri, resolve, reject){ + console.log(">> making get request to lbry daemon") axios.post('http://localhost:5279/lbryapi', { method: "get", params: { uri: uri } } ).then(function (getUriResponse) { console.log(">> 'get claim' success..."); + //check to make sure the daemon didn't just time out + if (getUriResponse.data.result.error === "Timeout"){ + reject("get request to lbry daemon timed out"); + } console.log(">> response data:", getUriResponse.data); console.log(">> dl path =", getUriResponse.data.result.download_path) // resolve the promise with the download path for the claim we got - /* note: do not resolve until the download is actually complete */ + /* + note: put in a check to make sure we do not resolve until the download is actually complete + */ resolve(getUriResponse.data.result.download_path); }).catch(function(getUriError){ console.log(">> 'get' error:", getUriError.response.data); // reject the promise with an error message - reject({ - msg: "An error occurred while fetching the free, public claim by URI.", - err: getUriError.response.data.error.message - }); + reject(getUriError.response.data.error.message); + return; }); } @@ -142,7 +147,6 @@ module.exports = { */ var deferred = new Promise(function (resolve, reject){ console.log(">> your uri:", uri); - // fetch the image to display getClaimWithUri(uri, resolve, reject); }); @@ -150,7 +154,7 @@ module.exports = { }, - serveAllClaims: function(claimName, res){ + serveAllClaims: function(claimName, res){ // note: work in progress // make a call to the daemon to get the claims list axios.post('http://localhost:5279/lbryapi', { method: "claim_list", diff --git a/public/claim.html b/public/claim.html index 6061eb8b..129b7fa4 100644 --- a/public/claim.html +++ b/public/claim.html @@ -7,25 +7,24 @@ Spee.ch Claim -

spee.ch

-

spee.ch is a single-serving site that reads and publishes images to and from the LBRY blockchain.

-

Status:

-

your image is being retrieved

-
+
+

spee.ch

+

spee.ch is a single-serving site that reads and publishes images to and from the LBRY blockchain.

+

Status:

+

Your image is being retrieved

+