2017-05-24 20:07:43 +02:00
|
|
|
var axios = require('axios');
|
|
|
|
|
|
|
|
module.exports = {
|
2017-06-01 04:48:09 +02:00
|
|
|
publishClaim: function(publishParams){
|
|
|
|
var deferred = new Promise(function(resolve, reject){
|
2017-06-14 21:53:55 +02:00
|
|
|
console.log(">> lbryApi >> publishClaim:", publishParams);
|
2017-06-01 04:48:09 +02:00
|
|
|
axios.post('http://localhost:5279/lbryapi', {
|
|
|
|
"method": "publish",
|
|
|
|
"params": publishParams
|
2017-06-14 02:13:38 +02:00
|
|
|
}).then(function (response) {
|
2017-06-01 04:48:09 +02:00
|
|
|
console.log(">> 'publish' success");
|
|
|
|
resolve(response.data);
|
|
|
|
}).catch(function(error){
|
|
|
|
console.log(">> 'publish' error");
|
2017-06-03 05:56:33 +02:00
|
|
|
reject(error);
|
2017-06-14 02:13:38 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
return deferred;
|
|
|
|
},
|
2017-06-14 02:52:29 +02:00
|
|
|
getClaim: function(uri){
|
2017-06-14 02:13:38 +02:00
|
|
|
var deferred = new Promise(function(resolve, reject){
|
2017-06-14 21:53:55 +02:00
|
|
|
console.log(">> lbryApi >> getClaim:", uri);
|
2017-06-14 02:13:38 +02:00
|
|
|
axios.post('http://localhost:5279/lbryapi', {
|
|
|
|
"method": "get",
|
2017-06-14 21:53:55 +02:00
|
|
|
"params": { "uri": uri, "timeout": 20}
|
2017-06-14 02:13:38 +02:00
|
|
|
}).then(function (getResponse) {
|
2017-06-14 21:53:55 +02:00
|
|
|
console.log(">> 'get' success");
|
2017-06-14 02:52:29 +02:00
|
|
|
//check to make sure the daemon didn't just time out (or otherwise send an error that appears to be a success response)
|
|
|
|
if (getResponse.data.result.error){
|
|
|
|
reject(getResponse.data.result.error);
|
|
|
|
}
|
2017-06-14 02:13:38 +02:00
|
|
|
// resolve the promise with the download path for the claim we got
|
|
|
|
/*
|
2017-06-14 02:52:29 +02:00
|
|
|
note: put in a check to make sure we do not resolve until the download is actually complete (response.data.completed === true)
|
2017-06-14 02:13:38 +02:00
|
|
|
*/
|
|
|
|
resolve(getResponse.data);
|
|
|
|
}).catch(function(getUriError){
|
2017-06-14 21:53:55 +02:00
|
|
|
console.log(">> 'get' error");
|
2017-06-14 02:13:38 +02:00
|
|
|
// reject the promise with an error message
|
|
|
|
reject(getUriError);
|
|
|
|
return;
|
|
|
|
});
|
|
|
|
});
|
2017-06-01 04:48:09 +02:00
|
|
|
return deferred;
|
2017-05-24 20:07:43 +02:00
|
|
|
},
|
2017-06-14 00:39:38 +02:00
|
|
|
getClaimsList: function(claimName){
|
|
|
|
var deferred = new Promise(function(resolve, reject){
|
2017-06-14 21:53:55 +02:00
|
|
|
console.log(">> lbryApi >> getClaimList:", claimName);
|
2017-06-01 05:54:56 +02:00
|
|
|
axios.post('http://localhost:5279/lbryapi', {
|
2017-06-14 00:39:38 +02:00
|
|
|
method: "claim_list",
|
|
|
|
params: { name: claimName }
|
|
|
|
}).then(function (response) {
|
2017-06-14 21:53:55 +02:00
|
|
|
console.log(">> 'claim_list' success");
|
2017-06-14 00:39:38 +02:00
|
|
|
resolve(response.data);
|
|
|
|
}).catch(function(error){
|
2017-06-14 21:53:55 +02:00
|
|
|
console.log(">> 'claim_list' error");
|
2017-06-03 05:56:33 +02:00
|
|
|
reject(error);
|
2017-05-25 09:59:22 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
return deferred;
|
2017-05-24 20:07:43 +02:00
|
|
|
},
|
2017-06-14 00:39:38 +02:00
|
|
|
resolveUri: function(uri){
|
2017-06-01 01:44:45 +02:00
|
|
|
var deferred = new Promise(function(resolve, reject){
|
2017-06-14 22:07:30 +02:00
|
|
|
console.log(">> lbryApi >> resolveUri:", uri);
|
2017-06-01 01:44:45 +02:00
|
|
|
axios.post('http://localhost:5279/lbryapi', {
|
2017-06-14 00:39:38 +02:00
|
|
|
"method": "resolve",
|
|
|
|
"params": { "uri": uri}
|
|
|
|
}).then(function(response){
|
2017-06-14 21:53:55 +02:00
|
|
|
console.log(">> 'resolve' success");
|
2017-06-14 00:39:38 +02:00
|
|
|
resolve(response.data);
|
2017-06-01 01:44:45 +02:00
|
|
|
}).catch(function(error){
|
2017-06-14 00:39:38 +02:00
|
|
|
console.log(">> 'resolve' error");
|
2017-06-03 05:56:33 +02:00
|
|
|
reject(error);
|
2017-06-14 00:39:38 +02:00
|
|
|
});
|
2017-06-01 01:44:45 +02:00
|
|
|
});
|
2017-06-01 02:00:13 +02:00
|
|
|
return deferred;
|
2017-05-24 20:07:43 +02:00
|
|
|
}
|
|
|
|
}
|