From 610951fe99ec29db02d2ce70f49e67b007aa1283 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Fri, 2 Jun 2017 20:56:33 -0700 Subject: [PATCH 1/4] cleaned up promises --- helpers/lbryApi.js | 34 +++--------- helpers/routeHelpers.js | 0 helpers/socketHelpers.js | 55 +++++++++++++++++++ public/{ => assets/img}/favicon.ico | Bin public/assets/js/upload.js | 2 + public/eagle.jpg | Bin 21792 -> 0 bytes public/index.html | 61 ++++++++++++++------- routes/html-routes.js | 79 +++++++++++----------------- routes/sockets-routes.js | 49 ++--------------- 9 files changed, 139 insertions(+), 141 deletions(-) create mode 100644 helpers/routeHelpers.js create mode 100644 helpers/socketHelpers.js rename public/{ => assets/img}/favicon.ico (100%) create mode 100644 public/assets/js/upload.js delete mode 100644 public/eagle.jpg diff --git a/helpers/lbryApi.js b/helpers/lbryApi.js index 6170d83e..4c6ae364 100644 --- a/helpers/lbryApi.js +++ b/helpers/lbryApi.js @@ -57,9 +57,9 @@ function getClaimWithUri(uri, resolve, reject){ */ resolve(getUriResponse.data.result.download_path); }).catch(function(getUriError){ - console.log(">> 'get' error:", getUriError.response.data); + console.log(">> 'get' error:", getUriError); // reject the promise with an error message - reject(getUriError.response.data.error.message); + reject(getUriError); return; }); } @@ -82,16 +82,10 @@ module.exports = { console.log(">> 'publish' success"); // return the claim we got resolve(response.data); - return; }).catch(function(error){ // receive response from LBRY console.log(">> 'publish' error"); - if (error.response.data.error){ - reject(error.response.data.error); - } else { - reject(error); - } - return; + reject(error); }) }) return deferred; @@ -134,16 +128,8 @@ module.exports = { getClaimWithUri(freePublicClaimUri, resolve, reject); }) .catch(function(error){ - console.log(">> 'claim_list' error:", error); - // reject the promise with an approriate message - if (error.code === "ECONNREFUSED"){ - reject("Connection refused. The daemon may not be running.") - } else if (error.response.data.error) { - reject(error.response.data.error); - } else { - reject(error); - }; - return; + console.log(">> 'claim_list' error."); + reject(error); }); }); // 3. return the promise @@ -200,14 +186,8 @@ module.exports = { */ resolve(orderedPublicClaims); }).catch(function(error){ - console.log(">> 'claim_list' error:", error); - if (error.code === "ECONNREFUSED"){ - reject("Connection refused. The daemon may not be running.") - } else if (error.response.data.error) { - reject(error.response.data.error); - } else { - reject(error); - }; + console.log(">> 'claim_list' error"); + reject(error); }) }); return deferred; diff --git a/helpers/routeHelpers.js b/helpers/routeHelpers.js new file mode 100644 index 00000000..e69de29b diff --git a/helpers/socketHelpers.js b/helpers/socketHelpers.js new file mode 100644 index 00000000..b08dd941 --- /dev/null +++ b/helpers/socketHelpers.js @@ -0,0 +1,55 @@ +//var fs = require('fs'); +var lbryApi = require('../helpers/lbryApi.js'); + +function handlePublishError(error) { + if (error.code === "ECONNREFUSED"){ + return "Connection refused. The daemon may not be running."; + } else if (error.response.data.error) { + return error.response.data.error; + } else { + return error; + }; +} +function createPublishParams(name, filepath, license, nsfw) { + var publishParams = { + "name": name, + "file_path": filepath, + "bid": 0.1, + "metadata": { + "description": name + " published via spee.ch", + "title": name, + "author": "spee.ch", + "language": "en", + "license": license, + "nsfw": (nsfw.toLowerCase() === "true") + } + }; + return publishParams; +} +function deleteTemporaryFile(filepath, name){ + fs.unlink(filepath, function(err){ + if (err) throw err; + console.log('successfully deleted ' + name); + }); +} + +module.exports = { + publish: function(name, filepath, license, nsfw, socket) { + // update the client + socket.emit("publish-status", "Your image is being published (this might take a second)..."); + // create the publish object + var publishParams = createPublishParams(name, filepath, license, nsfw); + // get a promise to publish + lbryApi.publishClaim(publishParams) + .then(function(data){ + console.log("publish promise success. Tx info:", data) + socket.emit("publish-complete", data); + deleteTemporaryFile(filepath, name); + }) + .catch(function(error){ + console.log("error:", error); + socket.emit("publish-status", handlePublishError(error)); + deleteTemporaryFile(filepath, name); + }); + } +} \ No newline at end of file diff --git a/public/favicon.ico b/public/assets/img/favicon.ico similarity index 100% rename from public/favicon.ico rename to public/assets/img/favicon.ico diff --git a/public/assets/js/upload.js b/public/assets/js/upload.js new file mode 100644 index 00000000..139597f9 --- /dev/null +++ b/public/assets/js/upload.js @@ -0,0 +1,2 @@ + + diff --git a/public/eagle.jpg b/public/eagle.jpg deleted file mode 100644 index cb7367384cc4e8e315aea84409233a015b970132..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 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{@?Kb?DxS1 zfMX;0pWFYx$=lBVVf+AqnlS+IpE>=n*8h91{@aH0^kE1>4{K5U-?q1f0D$P#gFWfL zZPu9pKyx$zK)v+eHr9LqfGi3CXqvF`@$~(#J^-{2_Ytfi92>lpN6tjQp2z_8o(sP? z<4h8ymPk>?)AKVwadwB}#nd8$DxJOrPxl`1|NHlE8K3~b!^bChOh8CPL`XvVkSQsi zJfWbZ2R?ns^xV&xoK_KCHN07ENs7rf9rbwQI{tPFkyc(E0vHl~pNjn!qK5iqTTk@OVMog6qrL?~^REvg$J zC~Kw!Z)nqDL+^$0mY3S7rfb!noPeNmP~&peI0z~pLtLnZYj~Xg^gGPg-qv3XHHkd9 z3?)2-B2Syilkca)LbL_A z^M!u`l{-!3GR9^cetg2syCJVGJQm(}-6U-KsT^35AS1qPJPGh6>rJ*Op=;xJYBj$h zOV2KeZcX4Pj{T!dc?qoW-76n+7F>?zu{KDQLl)8Ze|-I1ey<*zdls_LNcN)E9N@0y z(kI@;_2}|ei3a@F%OKWqfEgtP!tS>F(Z@&iyS$4fZpKrm)~nfXDvXg;TV=3|(F0iy z)fHgUyPwLHfl};$CM1shVerm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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!

spee.ch

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

-

Examples:

+ +

Examples:

-

Publish Your Own

+ +

Publish Your Own

@@ -38,15 +40,14 @@
-

-

Help Wanted!

+

Help Wanted!

If you would like to help make spee.ch amazing, join our slack channel.

We are currently in need of a designer to help with styling spee.ch's front end, but all help is welcome!

-

Help

-

Site Navigation

+

Documentation

+

Site Navigation

-

API

+

API

Note: these are being used for testing durring spee.ch development and may not be maintained

  • A GET request to spee.ch/claim_list/<the name of the claim> @@ -86,10 +87,29 @@ diff --git a/routes/html-routes.js b/routes/html-routes.js index 6253e54f..0c191a2b 100644 --- a/routes/html-routes.js +++ b/routes/html-routes.js @@ -6,36 +6,37 @@ var multipartMiddleware = multipart(); var lbryApi = require('../helpers/lbryApi.js'); var queueApi = require('../helpers/queueApi.js'); + +function handleRequestError(error, res) { + if ((error === "NO_CLAIMS") || (error === "NO_FREE_PUBLIC_CLAIMS")){ + res.status(307).sendFile(path.join(__dirname, '../public', 'noClaims.html')); + } else if (error === "Invalid URI") { + res.status(400).sendFile(path.join(__dirname, '../public', 'invalidUri.html')); + } else { + res.status(400).send(error); + }; +} + // routes to export module.exports = function(app){ // route to fetch one free public claim app.get("/favicon.ico", function(req, res){ console.log(" >> GET request on favicon.ico"); - res.sendFile(path.join(__dirname, '../public', 'favicon.ico')); + res.sendFile(path.join(__dirname, '../public/assets/img', 'favicon.ico')); }); // route to fetch one free public claim app.get("/:name/all", function(req, res){ - var name = req.params.name; - console.log(">> GET request on /" + name + " (all)"); + console.log(">> GET request on /" + req.params.name + " (all)"); // create promise - var promise = lbryApi.getAllClaims(name); - // handle the promise resolve - promise.then(function(orderedFreePublicClaims){ - console.log("/name/all promise success.") + lbryApi.getAllClaims(req.params.name) + .then(function(orderedFreePublicClaims){ + console.log("/:name/all success.") res.status(200).send(orderedFreePublicClaims); return; }) - // handle the promise rejection .catch(function(error){ - console.log("/name/all/ promise error:", error); - // handle the error - if ((error === "NO_CLAIMS") || (error === "NO_FREE_PUBLIC_CLAIMS")){ - res.status(307).sendFile(path.join(__dirname, '../public', 'noClaims.html')); - return; - } else { - res.status(400).send(error); - return; - }; + console.log("/:name/all error:", error); + handleRequestError(error, res); }) }); // route to fetch one free public claim @@ -43,48 +44,28 @@ module.exports = function(app){ var uri = req.params.name + "#" + req.params.claim_id; console.log(">> GET request on /" + uri); // create promise - var promise = lbryApi.getClaimBasedOnUri(uri); - // handle the promise resolve - promise.then(function(filePath){ - console.log("/name/claim_id promise success - filepath:", filePath) + lbryApi.getClaimBasedOnUri(uri) + .then(function(filePath){ + console.log("/:name/:claim_id success."); res.status(200).sendFile(filePath); - return; }) - // handle the promise rejection .catch(function(error){ - console.log("/name/claim_id/ promise error:", error) - // handle the error - if (error === "Invalid URI") { - res.status(400).sendFile(path.join(__dirname, '../public', 'invalidUri.html')); - return; - } else { - res.status(400).send(error); - return; - }; + console.log("/:name/:claim_id error.") + handleRequestError(error, res); }); }); // route to fetch one free public claim app.get("/:name", function(req, res){ - var name = req.params.name; - console.log(">> GET request on /" + name); + console.log(">> GET request on /" + req.params.name); // create promise - var promise = lbryApi.getClaimBasedOnNameOnly(name); - // handle the promise resolve - promise.then(function(filePath){ - console.log("/name promise success - filepath:", filePath) + lbryApi.getClaimBasedOnNameOnly(req.params.name) + .then(function(filePath){ + console.log("/:name success.") res.status(200).sendFile(filePath); - return; - }) - // handle the promise rejection - .catch(function(error){ - console.log("/name/ promise error:", error); - // handle the error - if ((error === "NO_CLAIMS") || (error === "NO_FREE_PUBLIC_CLAIMS")){ - res.status(307).sendFile(path.join(__dirname, '../public', 'noClaims.html')); - return; - }; - res.status(400).send(error); + }).catch(function(error){ + console.log("/:name error."); + handleRequestError(error, res); }); }); diff --git a/routes/sockets-routes.js b/routes/sockets-routes.js index edd1d4a9..6cf7c9d8 100644 --- a/routes/sockets-routes.js +++ b/routes/sockets-routes.js @@ -6,56 +6,14 @@ module.exports = function(app) { var lbryApi = require('../helpers/lbryApi.js'); var queueApi = require('../helpers/queueApi.js'); var siofu = require("socketio-file-upload"); - - // functions to create a publishing object - function createPublishParams(name, filepath, license, nsfw){ - var publishParams = { - "name": name, - "file_path": filepath, - "bid": 0.1, - "metadata": { - "description": name + " published via spee.ch", - "title": name, - "author": "spee.ch", - "language": "en", - "license": license, - "nsfw": (nsfw.toLowerCase() === "true") - } - }; - return publishParams; - } - // publish an image to lbry - function publish(name, filepath, license, nsfw, socket){ - // update the client - socket.emit("publish-status", "Your image is being published (this might take a second)..."); - // create the publish object - var publishParams = createPublishParams(name, filepath, license, nsfw); - // get a promise to publish - var promise = lbryApi.publishClaim(publishParams); - // handle promise - promise.then(function(data){ - console.log("publish promise success. Tx info:", data) - socket.emit("publish-complete", data); - /* - note: remember to delete the local file - */ - }) - .catch(function(error){ - console.log("error:", error); - socket.emit("publish-status", "publish failed"); - /* - note: remember to delete the local file - */ - }); - }; + var socketHelpers = require('../helpers/socketHelpers.js'); io.on('connection', function(socket){ console.log('a user connected'); - // listener for uploader + // attach upload listeners var uploader = new siofu(); uploader.dir = path.join(__dirname, '../../Uploads'); uploader.listen(socket); - // attach upload listeners uploader.on("error", function(event){ console.log("an error occured while uploading", event.error); socket.emit("publish-status", event.error) @@ -64,12 +22,11 @@ module.exports = function(app) { console.log("saved " + event.file.name); if (event.file.success){ socket.emit("publish-status", "file upload successfully completed"); - publish(event.file.meta.name, event.file.pathName, event.file.meta.license,event.file.meta.nsfw, socket) + socketHelpers.publish(event.file.meta.name, event.file.pathName, event.file.meta.license,event.file.meta.nsfw, socket) } else { socket.emit("publish-status", "file saved, but with errors") }; }); - // handle disconnect socket.on('disconnect', function(){ console.log('user disconnected'); From bb5e67ade5fb6b8e642f2af9d80bcda4e51d993a Mon Sep 17 00:00:00 2001 From: bill bittner Date: Fri, 2 Jun 2017 22:19:47 -0700 Subject: [PATCH 2/4] covered daemon 500 code errors --- helpers/lbryApi.js | 6 +++--- helpers/socketHelpers.js | 12 ++++++------ routes/html-routes.js | 6 +++--- routes/sockets-routes.js | 4 +--- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/helpers/lbryApi.js b/helpers/lbryApi.js index 4c6ae364..09ed8498 100644 --- a/helpers/lbryApi.js +++ b/helpers/lbryApi.js @@ -46,8 +46,8 @@ function getClaimWithUri(uri, resolve, reject){ ).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"); + if (getUriResponse.data.result.error){ + reject(getUriResponse.data.result.error); } console.log(">> response data:", getUriResponse.data); console.log(">> dl path =", getUriResponse.data.result.download_path) @@ -57,7 +57,7 @@ function getClaimWithUri(uri, resolve, reject){ */ resolve(getUriResponse.data.result.download_path); }).catch(function(getUriError){ - console.log(">> 'get' error:", getUriError); + console.log(">> 'get' error."); // reject the promise with an error message reject(getUriError); return; diff --git a/helpers/socketHelpers.js b/helpers/socketHelpers.js index b08dd941..bb8a7547 100644 --- a/helpers/socketHelpers.js +++ b/helpers/socketHelpers.js @@ -1,4 +1,4 @@ -//var fs = require('fs'); +var fs = require('fs'); var lbryApi = require('../helpers/lbryApi.js'); function handlePublishError(error) { @@ -26,10 +26,10 @@ function createPublishParams(name, filepath, license, nsfw) { }; return publishParams; } -function deleteTemporaryFile(filepath, name){ - fs.unlink(filepath, function(err){ +function deleteTemporaryFile(filepath) { + fs.unlink(filepath, function(err) { if (err) throw err; - console.log('successfully deleted ' + name); + console.log('successfully deleted ' + filepath); }); } @@ -44,12 +44,12 @@ module.exports = { .then(function(data){ console.log("publish promise success. Tx info:", data) socket.emit("publish-complete", data); - deleteTemporaryFile(filepath, name); + deleteTemporaryFile(filepath); }) .catch(function(error){ console.log("error:", error); socket.emit("publish-status", handlePublishError(error)); - deleteTemporaryFile(filepath, name); + deleteTemporaryFile(filepath); }); } } \ No newline at end of file diff --git a/routes/html-routes.js b/routes/html-routes.js index 0c191a2b..c9674f10 100644 --- a/routes/html-routes.js +++ b/routes/html-routes.js @@ -10,10 +10,10 @@ var queueApi = require('../helpers/queueApi.js'); function handleRequestError(error, res) { if ((error === "NO_CLAIMS") || (error === "NO_FREE_PUBLIC_CLAIMS")){ res.status(307).sendFile(path.join(__dirname, '../public', 'noClaims.html')); - } else if (error === "Invalid URI") { - res.status(400).sendFile(path.join(__dirname, '../public', 'invalidUri.html')); + } else if (error.response.status === 500) { + res.status(400).send(error.response.data.error.message); } else { - res.status(400).send(error); + res.status(400).send(error.toString()); }; } diff --git a/routes/sockets-routes.js b/routes/sockets-routes.js index 6cf7c9d8..45857c20 100644 --- a/routes/sockets-routes.js +++ b/routes/sockets-routes.js @@ -1,10 +1,8 @@ module.exports = function(app) { var http = require('http').Server(app); var io = require('socket.io')(http); - var fs = require('fs'); + //var fs = require('fs'); var path = require('path'); - var lbryApi = require('../helpers/lbryApi.js'); - var queueApi = require('../helpers/queueApi.js'); var siofu = require("socketio-file-upload"); var socketHelpers = require('../helpers/socketHelpers.js'); From 57ae1612cceef29d59d4b975786d15284e91aadd Mon Sep 17 00:00:00 2001 From: bill bittner Date: Sat, 3 Jun 2017 00:41:02 -0700 Subject: [PATCH 3/4] added urls on publish completion --- helpers/lbryApi.js | 7 +- helpers/queueApi.js | 22 ----- helpers/routeHelpers.js | 13 +++ helpers/socketHelpers.js | 6 +- package.json | 2 - public/assets/css/style.css | 0 public/assets/js/upload.js | 2 - public/claimPlus.html | 36 ------- public/index.html | 191 ++++++++++++++++++++---------------- routes/api-routes.js | 6 +- routes/html-routes.js | 27 +---- routes/sockets-routes.js | 3 +- worker.js | 31 ------ 13 files changed, 132 insertions(+), 214 deletions(-) delete mode 100644 helpers/queueApi.js create mode 100644 public/assets/css/style.css delete mode 100644 public/assets/js/upload.js delete mode 100644 public/claimPlus.html delete mode 100644 worker.js diff --git a/helpers/lbryApi.js b/helpers/lbryApi.js index 09ed8498..a9314401 100644 --- a/helpers/lbryApi.js +++ b/helpers/lbryApi.js @@ -1,10 +1,7 @@ -// 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; }; @@ -14,7 +11,7 @@ function filterForFreePublicClaims(claimsListArray){ }); 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') && @@ -24,7 +21,7 @@ function isFreePublicClaim(claim){ return false; } } -// helper function to order a set of claims + function orderTopClaims(claimsListArray){ console.log(">> orderTopClaims, claimsListArray:"); claimsListArray.sort(function(claimA, claimB){ diff --git a/helpers/queueApi.js b/helpers/queueApi.js deleted file mode 100644 index 6f8c5fef..00000000 --- a/helpers/queueApi.js +++ /dev/null @@ -1,22 +0,0 @@ -// require amqp library -var amqp = require('amqplib/callback_api'); - -module.exports = { - addNewTaskToQueue: function(task){ - // connect to RabbitMQ server - amqp.connect('amqp://localhost', function(err, conn) { - // create a channel - conn.createChannel(function(err, ch) { - var q = 'task_queue2'; // declaring a que is idempotent (it will only be created if it doesnt already exist) - var msg = task || "request received with no task!"; - // declare a queue - ch.assertQueue(q, {durable: true}); - // publish a message to the queue - ch.sendToQueue(q, new Buffer.from(msg), {persistent: true}); - console.log(` [x] Sent '${msg}' to ${q}`); - }); - // close the connection and exit - setTimeout(function() {conn.close() }, 500); - }); - } -} \ No newline at end of file diff --git a/helpers/routeHelpers.js b/helpers/routeHelpers.js index e69de29b..e86bb1b6 100644 --- a/helpers/routeHelpers.js +++ b/helpers/routeHelpers.js @@ -0,0 +1,13 @@ +var path = require('path'); + +module.exports = { + handleRequestError: function(error, res) { + if ((error === "NO_CLAIMS") || (error === "NO_FREE_PUBLIC_CLAIMS")){ + res.status(307).sendFile(path.join(__dirname, '../public', 'noClaims.html')); + } else if (error.response.status === 500) { + res.status(400).send(error.response.data.error.message); + } else { + res.status(400).send(error.toString()); + }; + } +} diff --git a/helpers/socketHelpers.js b/helpers/socketHelpers.js index bb8a7547..0a4f41fe 100644 --- a/helpers/socketHelpers.js +++ b/helpers/socketHelpers.js @@ -10,6 +10,7 @@ function handlePublishError(error) { return error; }; } + function createPublishParams(name, filepath, license, nsfw) { var publishParams = { "name": name, @@ -26,6 +27,7 @@ function createPublishParams(name, filepath, license, nsfw) { }; return publishParams; } + function deleteTemporaryFile(filepath) { fs.unlink(filepath, function(err) { if (err) throw err; @@ -43,12 +45,12 @@ module.exports = { lbryApi.publishClaim(publishParams) .then(function(data){ console.log("publish promise success. Tx info:", data) - socket.emit("publish-complete", data); + socket.emit("publish-complete", {name: name, result: data.result}); deleteTemporaryFile(filepath); }) .catch(function(error){ console.log("error:", error); - socket.emit("publish-status", handlePublishError(error)); + socket.emit("publish-failure", handlePublishError(error)); deleteTemporaryFile(filepath); }); } diff --git a/package.json b/package.json index a3ef74fd..2300bd02 100644 --- a/package.json +++ b/package.json @@ -23,10 +23,8 @@ }, "homepage": "https://github.com/billbitt/spee.ch-backend#readme", "dependencies": { - "amqplib": "^0.5.1", "axios": "^0.16.1", "body-parser": "^1.17.1", - "connect-multiparty": "^2.0.0", "express": "^4.15.2", "nodemon": "^1.11.0", "socket.io": "^2.0.1", diff --git a/public/assets/css/style.css b/public/assets/css/style.css new file mode 100644 index 00000000..e69de29b diff --git a/public/assets/js/upload.js b/public/assets/js/upload.js deleted file mode 100644 index 139597f9..00000000 --- a/public/assets/js/upload.js +++ /dev/null @@ -1,2 +0,0 @@ - - diff --git a/public/claimPlus.html b/public/claimPlus.html deleted file mode 100644 index 678eedd9..00000000 --- a/public/claimPlus.html +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - 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

    -
    - - - - diff --git a/public/index.html b/public/index.html index 44d5a6c5..775aed4c 100644 --- a/public/index.html +++ b/public/index.html @@ -5,85 +5,102 @@ Spee.ch +

    spee.ch

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

    - -

    Examples:

    - - -

    Publish Your Own

    -
    -
    - -
    - Image preview... -
    - Name: -
    - License: -
    - NSFW: -
    - -
    -
    - -

    Help Wanted!

    -

    If you would like to help make spee.ch amazing, join our slack channel.

    -

    We are currently in need of a designer to help with styling spee.ch's front end, but all help is welcome!

    - -

    Documentation

    -

    Site Navigation

    - -

    API

    -

    Note: these are being used for testing durring spee.ch development and may not be maintained

    -
      -
    • A GET request to spee.ch/claim_list/<the name of the claim> - -
    • -
    - +
    +

    Examples:

    + +
    +
    +

    Publish Your Own

    +
    +
    + +
    + Image preview... +
    + Name: +
    + License: +
    + NSFW: +
    + +
    +
    +
    +
    +

    Help Wanted!

    +

    If you would like to help make spee.ch amazing, join our slack channel.

    +

    We are currently in need of a designer to help with styling spee.ch's front end, but all help is welcome!

    +
    +
    +

    Documentation

    +

    Site Navigation

    + +

    API

    +

    Note: these are being used for testing durring spee.ch development and may not be maintained

    +
      +
    • A GET request to spee.ch/claim_list/<the name of the claim> + +
    • +
    +
    +
    +

    Links

    + github + lbry + slack +
    +
    +

    Bugs

    +

    Spee.ch is young and under continuous development so it will have bugs. Please leave an issue on our github if you experience a problem or have suggestions.

    +
     .w. +
    (o|o) +
      `'` +