added local search to /name route
This commit is contained in:
parent
6f7d9af768
commit
6b2b397b85
1 changed files with 34 additions and 14 deletions
|
@ -77,22 +77,42 @@ module.exports = {
|
||||||
getClaimBasedOnNameOnly: function(claimName){
|
getClaimBasedOnNameOnly: function(claimName){
|
||||||
var deferred = new Promise(function (resolve, reject){
|
var deferred = new Promise(function (resolve, reject){
|
||||||
console.log(">> lbryHelpers >> getClaim BasedOnNameOnly:", claimName);
|
console.log(">> lbryHelpers >> getClaim BasedOnNameOnly:", claimName);
|
||||||
// promise to get all free public claims
|
// get all free public claims
|
||||||
getAllFreePublicClaims(claimName)
|
getAllFreePublicClaims(claimName)
|
||||||
.then(function(freePublicClaimList){
|
.then(function(freePublicClaimList){
|
||||||
var freePublicClaimUri = freePublicClaimList[0].name + "#" + freePublicClaimList[0].claim_id;
|
var claimName = freePublicClaimList[0].name;
|
||||||
console.log(">> successfully received free public claim URI:", freePublicClaimUri);
|
var claimId = freePublicClaimList[0].claim_id;
|
||||||
|
var freePublicClaimUri = claimName + "#" + claimId;
|
||||||
|
console.log(">> Decided on public claim URI:", freePublicClaimUri);
|
||||||
|
// 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)
|
||||||
|
// if a record is found, return it
|
||||||
|
if (claim){
|
||||||
|
var fileInfo = {
|
||||||
|
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 {
|
||||||
// promise to get the chosen uri
|
// promise to get the chosen uri
|
||||||
lbryApi.getClaim(freePublicClaimUri)
|
lbryApi.getClaim(freePublicClaimUri)
|
||||||
.then(function(data){
|
.then(function(data){
|
||||||
resolve({
|
resolve({
|
||||||
fileName: data.result.file_name,
|
file_name: data.result.file_name,
|
||||||
directory: data.result.download_directory,
|
download_path: data.result.download_path,
|
||||||
contentType: data.result.metadata.stream.source.contentType
|
content_type: data.result.metadata.stream.source.contentType
|
||||||
});
|
});
|
||||||
}).catch(function(error){
|
}).catch(function(error){
|
||||||
reject(error)
|
reject(error)
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
}).catch(function(error){
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
}).catch(function(error){
|
}).catch(function(error){
|
||||||
reject(error);
|
reject(error);
|
||||||
});
|
});
|
||||||
|
@ -142,7 +162,7 @@ module.exports = {
|
||||||
}
|
}
|
||||||
}).catch(function(error){
|
}).catch(function(error){
|
||||||
reject(error);
|
reject(error);
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
return deferred;
|
return deferred;
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue