diff --git a/helpers/lbryApi.js b/helpers/lbryApi.js index 68e05c83..4d14d7d3 100644 --- a/helpers/lbryApi.js +++ b/helpers/lbryApi.js @@ -1,4 +1,5 @@ var axios = require('axios'); +var db = require("../models"); module.exports = { publishClaim: function(publishParams){ @@ -33,7 +34,18 @@ module.exports = { /* note: put in a check to make sure we do not resolve until the download is actually complete (response.data.completed === true) */ - resolve(getResponse.data); + // save a record of the file to the Files table + db.File.create({ + name: getResponse.data.result.file_name, + path: getResponse.data.result.download_path, + file_type: getResponse.data.result.mime_type, + claim_id: getResponse.data.result.claim_id, + nsfw: getResponse.data.result.metadata.stream.metadata.nsfw, + }).catch(function(error){ + console.log('an error occurred when writing to the MySQL database. Check the logs.'); + }); + // resolve the promise + resolve(getResponse.data); //to do: return the result }).catch(function(getUriError){ console.log(">> 'get' error"); // reject the promise with an error message diff --git a/helpers/lbryHelpers.js b/helpers/lbryHelpers.js index 2b1496cf..9f431ed0 100644 --- a/helpers/lbryHelpers.js +++ b/helpers/lbryHelpers.js @@ -87,7 +87,7 @@ module.exports = { // check to see if the file is available locally db.File.findOne({where: { claim_id: claimId }}) .then(function(claim){ - console.log("asset found locally >>", claim) + console.log(">> Asset was found locally"); // if a record is found, return it if (claim){ var fileInfo = { @@ -126,15 +126,14 @@ module.exports = { // check locally for the claim db.File.findOne({where: { claim_id: claimId }}) .then(function(claim){ - console.log("asset found locally >>", claim) + console.log(">> Asset was found locally"); // if a record is found, return it if (claim){ - var fileInfo = { + resolve({ file_name: claim.dataValues.name, download_path: claim.dataValues.path, content_type: claim.dataValues.file_type - } - resolve(fileInfo); + }); // ... otherwise use daemon to retrieve it } else { // get the claim info via 'resolve'