From d7a35bed780cb4954466e61b866405b91529e7e5 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Fri, 16 Jun 2017 19:31:31 -0700 Subject: [PATCH] fixed publish issues --- config/default.json | 2 +- config/development.json | 3 ++- config/production.json | 2 +- config/test.json | 2 +- controllers/publishController.js | 21 +++++++++++---------- controllers/showController.js | 2 +- helpers/functions/isFreePublicClaim.js | 2 +- helpers/libraries/lbryApi.js | 6 +++--- routes/show-routes.js | 2 +- routes/sockets-routes.js | 5 +++-- server.js | 2 +- views/allClaims.handlebars | 2 +- 12 files changed, 27 insertions(+), 24 deletions(-) diff --git a/config/default.json b/config/default.json index cabec5e8..5691ff63 100644 --- a/config/default.json +++ b/config/default.json @@ -7,6 +7,6 @@ }, "Database": { "MySqlConnectionUri": "none", - "DownloadAddress": "C:\\lbry\\speech\\hosted_content" + "PublishUploadPath": "none" } } \ No newline at end of file diff --git a/config/development.json b/config/development.json index b1bac598..a673979c 100644 --- a/config/development.json +++ b/config/development.json @@ -6,6 +6,7 @@ "googleId": "UA-100747990-1" }, "Database": { - "MySqlConnectionUri": "none" + "MySqlConnectionUri": "none", + "PublishUploadPath": "C:\\lbry\\speech\\hosted_content" } } \ No newline at end of file diff --git a/config/production.json b/config/production.json index c2ced7e9..4f815ce7 100644 --- a/config/production.json +++ b/config/production.json @@ -7,6 +7,6 @@ }, "Database": { "MySqlConnectionUri": "none", - "DownloadAddress": "~/Downloads/" + "PublishUploadPath": "~/Downloads/" } } \ No newline at end of file diff --git a/config/test.json b/config/test.json index 7c18d6eb..8d0379c2 100644 --- a/config/test.json +++ b/config/test.json @@ -7,6 +7,6 @@ }, "Database": { "MySqlConnectionUri": "none", - "DownloadAddress": "~/Downloads/" + "PublishUploadPath": "~/Downloads/" } } \ No newline at end of file diff --git a/controllers/publishController.js b/controllers/publishController.js index 03564076..9bf8f5e4 100644 --- a/controllers/publishController.js +++ b/controllers/publishController.js @@ -5,21 +5,22 @@ var errorHandlers = require("../helpers/libraries/errorHandlers.js"); var walledAddress = config.get('WalletConfig.lbryAddress'); -function createPublishParams(name, filePath, license, nsfw) { +function createPublishParams(claim, filePath, license, nsfw) { + console.log("nsfw:", nsfw, typeof nsfw); var publishParams = { - "name": name, + "name": claim, "file_path": filePath, "bid": 0.01, "metadata": { - "description": name + " published via spee.ch", - "title": name, + "description": claim + " published via spee.ch", + "title": claim, "author": "spee.ch", "language": "en", "license": license, - "nsfw": (nsfw.toLowerCase() === "true") + "nsfw": (nsfw.toLowerCase() === "on") }, "claim_address": walledAddress, - "change_address": walledAddress //requires daemon 0.12.2rc1 or above + "change_address": walledAddress }; return publishParams; } @@ -32,19 +33,19 @@ function deleteTemporaryFile(filePath) { } module.exports = { - publish: function(name, filePath, fileType, license, nsfw, socket, visitor) { + publish: function(claim, fileName, filePath, fileType, license, nsfw, socket, visitor) { // update the client socket.emit("publish-status", "Your image is being published (this might take a second)..."); // send to analytics visitor.event("Publish Route", "Publish Request", filePath).send(); // create the publish object - var publishParams = createPublishParams(name, filePath, license, nsfw); + var publishParams = createPublishParams(claim, filePath, license, nsfw); // get a promise to publish - lbryApi.publishClaim(publishParams, fileType) + lbryApi.publishClaim(publishParams, fileName, fileType) .then(function(result){ visitor.event("Publish Route", "Publish Success", filePath).send(); console.log("publish promise success. Tx info:", result) - socket.emit("publish-complete", {name: name, result: result}); + socket.emit("publish-complete", {name: claim, result: result}); }) .catch(function(error){ visitor.event("Publish Route", "Publish Failure", filePath).send(); diff --git a/controllers/showController.js b/controllers/showController.js index 04d81f0e..78adc0f9 100644 --- a/controllers/showController.js +++ b/controllers/showController.js @@ -2,6 +2,6 @@ var getAllFreePublicClaims = require("../helpers/functions/getAllFreePublicClaim module.exports = { getAllClaims: function(claimName){ - return getAllFreePublicClaims(claimName); // to-do: does this need to be returned? + return getAllFreePublicClaims(claimName); } } \ No newline at end of file diff --git a/helpers/functions/isFreePublicClaim.js b/helpers/functions/isFreePublicClaim.js index 3915b564..5103635e 100644 --- a/helpers/functions/isFreePublicClaim.js +++ b/helpers/functions/isFreePublicClaim.js @@ -1,6 +1,6 @@ module.exports = function(claim){ - console.log(">> isFreePublicClaim? claim:", claim); + console.log(">> check: isFreePublicClaim?"); if (((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.amount === 0)) { diff --git a/helpers/libraries/lbryApi.js b/helpers/libraries/lbryApi.js index 56962725..82466a51 100644 --- a/helpers/libraries/lbryApi.js +++ b/helpers/libraries/lbryApi.js @@ -2,20 +2,20 @@ var axios = require('axios'); var db = require("../../models"); module.exports = { - publishClaim: function(publishParams, fileType){ + publishClaim: function(publishParams, fileName, fileType){ var deferred = new Promise(function(resolve, reject){ console.log(">> lbryApi >> publishClaim:", publishParams); axios.post('http://localhost:5279/lbryapi', { "method": "publish", "params": publishParams }).then(function (response) { - console.log(">> 'publish' success"); + console.log(">> 'publish' success", response); var result = response.data.result; db.File.create({ name: publishParams.name, claim_id: result.claim_id, outpoint: result.txid + ":" + result.nout, - file_name: "test", + file_name: fileName, file_path: publishParams.file_path, file_type: fileType, nsfw: publishParams.metadata.nsfw, diff --git a/routes/show-routes.js b/routes/show-routes.js index 623f7c60..a705271a 100644 --- a/routes/show-routes.js +++ b/routes/show-routes.js @@ -1,5 +1,5 @@ var errorHandlers = require("../helpers/libraries/errorHandlers.js"); -var showController = require("../controllers/serveController.js"); +var showController = require("../controllers/showController.js"); module.exports = function(app, ua, googleAnalyticsId){ // route to fetch all free public claims diff --git a/routes/sockets-routes.js b/routes/sockets-routes.js index 98997ee8..4a476f02 100644 --- a/routes/sockets-routes.js +++ b/routes/sockets-routes.js @@ -23,12 +23,13 @@ module.exports = function(app, siofu, hostedContentPath, ua, googleAnalyticsId) socket.emit("publish-status", event.error) }); uploader.on("saved", function(event){ - console.log("saved ", event.file.name, "deets:", event.file); + console.log("uploaded ", event.file.name); if (event.file.success){ socket.emit("publish-status", "file upload successfully completed"); - publishController.publish(event.file.meta.name, event.file.pathName, event.file.meta.type, event.file.meta.license, event.file.meta.nsfw, socket, visitor) + publishController.publish(event.file.meta.name, event.file.name, event.file.pathName, event.file.meta.type, event.file.meta.license, event.file.meta.nsfw, socket, visitor) } else { socket.emit("publish-failure", "file uploaded, but with errors") + // to-do: remove the file }; }); // handle disconnect diff --git a/server.js b/server.js index 158b9fb7..c56bbadd 100644 --- a/server.js +++ b/server.js @@ -10,7 +10,7 @@ var config = require('config'); var ua = require('universal-analytics'); var googleAnalyticsId = config.get('AnalyticsConfig.googleId'); -var hostedContentPath = config.get('Database.DownloadAddress'); +var hostedContentPath = config.get('Database.PublishUploadPath'); // set port var PORT = 3000; diff --git a/views/allClaims.handlebars b/views/allClaims.handlebars index 28abbad4..75b5eb20 100644 --- a/views/allClaims.handlebars +++ b/views/allClaims.handlebars @@ -8,7 +8,7 @@

claim_id: {{this.claim_id}}

-

direct link here

+

direct link here

author: {{this.value.stream.metadata.author}}

description: {{this.value.stream.metadata.description}}

license: {{this.value.stream.metadata.license}}