added creation of db record when files are retrieved via daemon

This commit is contained in:
bill bittner 2017-06-15 15:03:40 -07:00
parent 6b2b397b85
commit 50d65de6a4
2 changed files with 17 additions and 6 deletions

View file

@ -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

View file

@ -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'