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 cb736738..00000000 Binary files a/public/eagle.jpg and /dev/null differ diff --git a/public/index.html b/public/index.html index 579fc672..44d5a6c5 100644 --- a/public/index.html +++ b/public/index.html @@ -9,7 +9,8 @@

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