2017-06-19 18:37:35 +02:00
|
|
|
const axios = require('axios');
|
2017-06-20 00:25:14 +02:00
|
|
|
const logger = require('winston');
|
|
|
|
|
2017-05-24 20:07:43 +02:00
|
|
|
module.exports = {
|
2017-06-17 22:51:30 +02:00
|
|
|
publishClaim (publishParams, fileName, fileType) {
|
2017-06-20 04:34:34 +02:00
|
|
|
logger.debug(`Publishing claim for "${fileName}"`);
|
2017-06-17 22:51:30 +02:00
|
|
|
const deferred = new Promise((resolve, reject) => {
|
|
|
|
axios
|
|
|
|
.post('http://localhost:5279/lbryapi', {
|
|
|
|
method: 'publish',
|
|
|
|
params: publishParams,
|
|
|
|
})
|
|
|
|
.then(response => {
|
2017-06-19 18:37:35 +02:00
|
|
|
const result = response.data.result;
|
|
|
|
resolve(result);
|
2017-06-17 22:51:30 +02:00
|
|
|
})
|
|
|
|
.catch(error => {
|
2017-06-19 18:37:35 +02:00
|
|
|
reject(error);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return deferred;
|
2017-06-17 22:51:30 +02:00
|
|
|
},
|
|
|
|
getClaim (uri) {
|
2017-06-20 04:34:34 +02:00
|
|
|
logger.debug(`Getting Claim for "${uri}"`);
|
2017-06-17 22:51:30 +02:00
|
|
|
const deferred = new Promise((resolve, reject) => {
|
|
|
|
axios
|
|
|
|
.post('http://localhost:5279/lbryapi', {
|
|
|
|
method: 'get',
|
2017-06-20 00:25:14 +02:00
|
|
|
params: { uri, timeout: 30 },
|
2017-06-17 22:51:30 +02:00
|
|
|
})
|
|
|
|
.then(({ data }) => {
|
|
|
|
// check to make sure the daemon didn't just time out
|
2017-06-20 00:25:14 +02:00
|
|
|
if (!data.result) {
|
|
|
|
reject(JSON.stringify(data));
|
|
|
|
}
|
2017-06-17 22:51:30 +02:00
|
|
|
if (data.result.error) {
|
2017-06-19 18:37:35 +02:00
|
|
|
reject(data.result.error);
|
2017-06-17 22:51:30 +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-22 01:36:08 +02:00
|
|
|
resolve(data.result);
|
2017-06-17 22:51:30 +02:00
|
|
|
})
|
|
|
|
.catch(error => {
|
2017-06-19 18:37:35 +02:00
|
|
|
reject(error);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return deferred;
|
2017-06-17 22:51:30 +02:00
|
|
|
},
|
|
|
|
getClaimsList (claimName) {
|
2017-06-20 04:34:34 +02:00
|
|
|
logger.debug(`Getting Claim List for "${claimName}"`);
|
2017-06-17 22:51:30 +02:00
|
|
|
const deferred = new Promise((resolve, reject) => {
|
|
|
|
axios
|
|
|
|
.post('http://localhost:5279/lbryapi', {
|
|
|
|
method: 'claim_list',
|
|
|
|
params: { name: claimName },
|
|
|
|
})
|
|
|
|
.then(({ data }) => {
|
2017-06-19 18:37:35 +02:00
|
|
|
resolve(data.result);
|
2017-06-17 22:51:30 +02:00
|
|
|
})
|
|
|
|
.catch(error => {
|
2017-06-19 18:37:35 +02:00
|
|
|
reject(error);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return deferred;
|
2017-06-17 22:51:30 +02:00
|
|
|
},
|
|
|
|
resolveUri (uri) {
|
2017-06-20 04:34:34 +02:00
|
|
|
logger.debug(`Resolving URI for "${uri}"`);
|
2017-06-17 22:51:30 +02:00
|
|
|
const deferred = new Promise((resolve, reject) => {
|
|
|
|
axios
|
|
|
|
.post('http://localhost:5279/lbryapi', {
|
|
|
|
method: 'resolve',
|
|
|
|
params: { uri },
|
|
|
|
})
|
|
|
|
.then(({ data }) => {
|
2017-06-22 01:36:08 +02:00
|
|
|
// check for errors
|
|
|
|
if (data.result[uri].error) {
|
|
|
|
reject(data.result[uri].error);
|
|
|
|
return;
|
|
|
|
}
|
2017-06-19 18:37:35 +02:00
|
|
|
resolve(data.result);
|
2017-06-17 22:51:30 +02:00
|
|
|
})
|
|
|
|
.catch(error => {
|
2017-06-19 18:37:35 +02:00
|
|
|
reject(error);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return deferred;
|
2017-06-17 22:51:30 +02:00
|
|
|
},
|
2017-06-19 18:37:35 +02:00
|
|
|
};
|