2019-03-23 20:29:48 +01:00
|
|
|
const logger = require('winston');
|
|
|
|
|
2018-04-27 18:54:36 +02:00
|
|
|
const { handleErrorResponse } = require('../../../utils/errorHandlers.js');
|
2019-03-23 20:29:48 +01:00
|
|
|
const { getFileListFileByOutpoint } = require('server/lbrynet');
|
|
|
|
|
|
|
|
const chainquery = require('chainquery').default;
|
2018-03-29 02:35:41 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
route to see if asset is available locally
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2018-03-29 20:24:52 +02:00
|
|
|
const fileAvailability = ({ ip, originalUrl, params }, res) => {
|
|
|
|
const name = params.name;
|
|
|
|
const claimId = params.claimId;
|
2019-03-23 20:29:48 +01:00
|
|
|
logger.debug(`fileAvailability params: name:${name} claimId:${claimId}`);
|
|
|
|
// TODO: we probably eventually want to check the publishCache for the claimId too,
|
|
|
|
// and shop the outpoint to file_list.
|
|
|
|
return chainquery.claim.queries
|
|
|
|
.resolveClaim(name, claimId)
|
|
|
|
.then(result => {
|
|
|
|
return `${result.dataValues.transaction_hash_id}:${result.dataValues.vout}`;
|
|
|
|
})
|
|
|
|
.then(outpoint => {
|
|
|
|
logger.debug(`fileAvailability: outpoint: ${outpoint}`);
|
|
|
|
return getFileListFileByOutpoint(outpoint);
|
2018-03-29 20:24:52 +02:00
|
|
|
})
|
|
|
|
.then(result => {
|
2019-03-23 20:29:48 +01:00
|
|
|
if (result && result[0]) {
|
|
|
|
return res.status(200).json({ success: true, data: true });
|
|
|
|
} else {
|
|
|
|
res.status(200).json({ success: true, data: false });
|
2018-03-29 20:24:52 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
handleErrorResponse(originalUrl, ip, error, res);
|
|
|
|
});
|
2018-03-29 02:35:41 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = fileAvailability;
|