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-07-04 03:27:35 +02:00
|
|
|
getWalletList () {
|
2017-08-03 20:46:56 +02:00
|
|
|
logger.debug('lbryApi >> getting wallet list');
|
2017-08-03 19:42:02 +02:00
|
|
|
return new Promise((resolve, reject) => {
|
2017-07-04 03:27:35 +02:00
|
|
|
axios
|
|
|
|
.post('http://localhost:5279/lbryapi', {
|
|
|
|
method: 'wallet_list',
|
|
|
|
})
|
|
|
|
.then(response => {
|
|
|
|
const result = response.data.result;
|
|
|
|
resolve(result);
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
reject(error);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
2017-06-26 19:02:14 +02:00
|
|
|
publishClaim (publishParams) {
|
2017-08-03 20:46:56 +02:00
|
|
|
logger.debug(`lbryApi >> Publishing claim to "${publishParams.name}"`);
|
2017-08-03 19:42:02 +02:00
|
|
|
return new Promise((resolve, reject) => {
|
2017-06-17 22:51:30 +02:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|
2017-06-17 22:51:30 +02:00
|
|
|
},
|
|
|
|
getClaim (uri) {
|
2017-08-03 20:46:56 +02:00
|
|
|
logger.debug(`lbryApi >> Getting Claim for "${uri}"`);
|
2017-08-03 19:42:02 +02:00
|
|
|
return new Promise((resolve, reject) => {
|
2017-06-17 22:51:30 +02:00
|
|
|
axios
|
|
|
|
.post('http://localhost:5279/lbryapi', {
|
|
|
|
method: 'get',
|
2017-07-10 18:29:26 +02:00
|
|
|
params: { uri, timeout: 20 },
|
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
|
|
|
}
|
|
|
|
/*
|
2017-07-10 18:29:26 +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-17 22:51:30 +02:00
|
|
|
*/
|
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);
|
|
|
|
});
|
|
|
|
});
|
2017-06-17 22:51:30 +02:00
|
|
|
},
|
2017-08-15 22:48:42 +02:00
|
|
|
getClaimList (claimName) {
|
2017-08-04 20:32:21 +02:00
|
|
|
logger.debug(`lbryApi >> Getting claim_list for "${claimName}"`);
|
2017-08-03 19:42:02 +02:00
|
|
|
return new Promise((resolve, reject) => {
|
2017-06-17 22:51:30 +02:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|
2017-06-17 22:51:30 +02:00
|
|
|
},
|
|
|
|
resolveUri (uri) {
|
2017-08-03 20:46:56 +02:00
|
|
|
logger.debug(`lbryApi >> Resolving URI for "${uri}"`);
|
2017-08-16 03:24:15 +02:00
|
|
|
// console.log('resolving uri', uri);
|
2017-08-03 19:42:02 +02:00
|
|
|
return new Promise((resolve, reject) => {
|
2017-06-17 22:51:30 +02:00
|
|
|
axios
|
|
|
|
.post('http://localhost:5279/lbryapi', {
|
|
|
|
method: 'resolve',
|
|
|
|
params: { uri },
|
|
|
|
})
|
|
|
|
.then(({ data }) => {
|
2017-07-19 23:11:47 +02:00
|
|
|
if (data.result[uri].error) { // check for errors
|
2017-06-22 01:36:08 +02:00
|
|
|
reject(data.result[uri].error);
|
2017-07-19 23:11:47 +02:00
|
|
|
} else { // if no errors, resolve
|
2017-07-19 18:11:08 +02:00
|
|
|
resolve(data.result[uri]);
|
2017-06-22 01:36:08 +02:00
|
|
|
}
|
2017-06-17 22:51:30 +02:00
|
|
|
})
|
|
|
|
.catch(error => {
|
2017-08-16 03:24:15 +02:00
|
|
|
console.log('error with resolve', error);
|
2017-06-19 18:37:35 +02:00
|
|
|
reject(error);
|
|
|
|
});
|
|
|
|
});
|
2017-06-17 22:51:30 +02:00
|
|
|
},
|
2017-07-18 18:52:18 +02:00
|
|
|
getDownloadDirectory () {
|
2017-08-03 20:46:56 +02:00
|
|
|
logger.debug('lbryApi >> Retrieving the download directory path from lbry daemon...');
|
2017-08-03 19:42:02 +02:00
|
|
|
return new Promise((resolve, reject) => {
|
2017-07-18 18:52:18 +02:00
|
|
|
axios
|
|
|
|
.post('http://localhost:5279/lbryapi', {
|
|
|
|
method: 'settings_get',
|
|
|
|
})
|
|
|
|
.then(({ data }) => {
|
|
|
|
if (data.result) {
|
|
|
|
resolve(data.result.download_directory);
|
|
|
|
} else {
|
|
|
|
reject(new Error('Successfully connected to lbry daemon, but unable to retrieve the download directory.'));
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
2017-08-03 19:42:02 +02:00
|
|
|
logger.error('Unable to retrieve daemon download directory. Restart spee.ch once the daemon is ready. Using default "/home/lbry/Downloads".', error);
|
|
|
|
resolve('/home/lbry/Downloads/');
|
2017-07-18 18:52:18 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
2017-06-19 18:37:35 +02:00
|
|
|
};
|