spee.ch/helpers/lbryApi.js

79 lines
2.4 KiB
JavaScript
Raw Normal View History

var axios = require('axios');
module.exports = {
2017-06-01 04:48:09 +02:00
publishClaim: function(publishParams){
var deferred = new Promise(function(resolve, reject){
console.log(">> lbryApi >> publishClaim:", publishParams);
2017-06-01 04:48:09 +02:00
axios.post('http://localhost:5279/lbryapi', {
"method": "publish",
"params": publishParams
}).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);
});
});
return deferred;
},
2017-06-14 02:52:29 +02:00
getClaim: function(uri){
var deferred = new Promise(function(resolve, reject){
console.log(">> lbryApi >> getClaim:", uri);
axios.post('http://localhost:5279/lbryapi', {
"method": "get",
"params": { "uri": uri, "timeout": 20}
}).then(function (getResponse) {
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);
}
// 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)
*/
resolve(getResponse.data);
}).catch(function(getUriError){
console.log(">> 'get' error");
// reject the promise with an error message
reject(getUriError);
return;
});
});
2017-06-01 04:48:09 +02:00
return deferred;
},
2017-06-14 00:39:38 +02:00
getClaimsList: function(claimName){
var deferred = new Promise(function(resolve, reject){
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) {
console.log(">> 'claim_list' success");
2017-06-14 00:39:38 +02:00
resolve(response.data);
}).catch(function(error){
console.log(">> 'claim_list' error");
2017-06-03 05:56:33 +02:00
reject(error);
});
});
return deferred;
},
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){
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;
}
}