2018-09-26 03:20:59 +02:00
|
|
|
const { details: { host } } = require('@config/siteConfig');
|
2018-12-14 18:42:37 +01:00
|
|
|
const chainquery = require('chainquery').default;
|
2018-12-16 07:12:12 +01:00
|
|
|
const { getClaim } = require('server/lbrynet');
|
2019-01-07 23:44:34 +01:00
|
|
|
const { isBlocked } = require('./blockList');
|
2018-09-26 03:20:59 +02:00
|
|
|
|
2018-12-19 08:16:36 +01:00
|
|
|
module.exports = async (data, chName = null, chShortId = null) => {
|
2018-10-10 02:11:06 +02:00
|
|
|
// TODO: Refactor getching the channel name out; requires invasive changes.
|
|
|
|
const certificateId = data.publisher_id || data.certificateId;
|
2018-12-19 08:16:36 +01:00
|
|
|
let lbrynetClaimResult = null;
|
|
|
|
let lbrynetFileExt = null;
|
|
|
|
let channelShortId = chShortId;
|
|
|
|
let channelName = chName;
|
2019-01-07 23:44:34 +01:00
|
|
|
let blocked;
|
|
|
|
const outPoint = `${data.transaction_hash_id}:${data.vout}`;
|
|
|
|
if (isBlocked(outPoint)) {
|
|
|
|
blocked = true;
|
|
|
|
}
|
2018-10-10 02:11:06 +02:00
|
|
|
|
2018-12-19 08:16:36 +01:00
|
|
|
if (!chName && certificateId && !channelName) {
|
|
|
|
channelName = await chainquery.claim.queries.getClaimChannelName(certificateId).catch(() => {
|
|
|
|
});
|
2018-10-10 02:11:06 +02:00
|
|
|
}
|
|
|
|
|
2018-12-19 08:16:36 +01:00
|
|
|
if (!chShortId && certificateId && channelName) {
|
2018-10-29 15:09:26 +01:00
|
|
|
channelShortId = await chainquery.claim.queries.getShortClaimIdFromLongClaimId(certificateId, channelName).catch(() => null);
|
|
|
|
}
|
|
|
|
|
2018-12-19 08:16:36 +01:00
|
|
|
if (!chName && !chShortId && !data.fileExt) {
|
|
|
|
const lbrynetUri = `${data.name}#${data.claim_id}`;
|
|
|
|
lbrynetClaimResult = await getClaim(lbrynetUri).catch(() => {
|
|
|
|
return 'invalid URI';
|
|
|
|
});
|
|
|
|
lbrynetFileExt = lbrynetClaimResult && lbrynetClaimResult.file_name && lbrynetClaimResult.file_name.includes('.') && lbrynetClaimResult.file_name.split('.').slice(-1).pop();
|
|
|
|
}
|
2018-12-16 07:12:12 +01:00
|
|
|
|
2018-10-10 02:11:06 +02:00
|
|
|
return ({
|
2018-11-11 01:11:12 +01:00
|
|
|
name : data.name,
|
|
|
|
title : data.title,
|
2018-10-10 02:11:06 +02:00
|
|
|
certificateId,
|
|
|
|
channelName,
|
2018-10-29 15:09:26 +01:00
|
|
|
channelShortId,
|
2018-10-10 02:11:06 +02:00
|
|
|
contentType: data.content_type || data.contentType,
|
2018-11-11 01:11:12 +01:00
|
|
|
claimId : data.claim_id || data.claimId,
|
2018-12-16 07:12:12 +01:00
|
|
|
fileExt : data.generated_extension || data.fileExt || lbrynetFileExt,
|
2018-10-10 02:11:06 +02:00
|
|
|
description: data.description,
|
2018-11-11 01:11:12 +01:00
|
|
|
thumbnail : data.generated_thumbnail || data.thumbnail_url || data.thumbnail,
|
2019-01-07 23:44:34 +01:00
|
|
|
outpoint : outPoint || data.outpoint,
|
2018-10-10 02:11:06 +02:00
|
|
|
host,
|
2018-12-16 07:12:12 +01:00
|
|
|
pending : Boolean(data.height === 0),
|
2019-01-07 23:44:34 +01:00
|
|
|
blocked : blocked,
|
2018-11-11 01:11:12 +01:00
|
|
|
});
|
|
|
|
};
|