2019-01-29 07:05:16 +01:00
|
|
|
const {
|
|
|
|
details: { host },
|
|
|
|
assetDefaults: { thumbnail },
|
|
|
|
} = require('@config/siteConfig');
|
2018-12-14 18:42:37 +01:00
|
|
|
const chainquery = require('chainquery').default;
|
2019-01-29 07:05:16 +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.
|
2019-01-29 07:05:16 +01:00
|
|
|
const dataVals = data.dataValues ? data.dataValues : data;
|
|
|
|
const txid = dataVals.transaction_hash_id || dataVals.txid;
|
2019-02-01 08:18:15 +01:00
|
|
|
let nout;
|
|
|
|
|
|
|
|
if (typeof dataVals.vout === 'number') {
|
|
|
|
nout = dataVals.vout;
|
|
|
|
} else {
|
|
|
|
nout = dataVals.nout;
|
|
|
|
}
|
|
|
|
|
2019-01-29 07:05:16 +01:00
|
|
|
const outpoint = `${txid}:${nout}`;
|
|
|
|
const certificateId = dataVals.publisher_id || dataVals.certificateId;
|
|
|
|
const fileExt = data.generated_extension || dataVals.fileExt;
|
|
|
|
|
2018-12-19 08:16:36 +01:00
|
|
|
let channelShortId = chShortId;
|
|
|
|
let channelName = chName;
|
2019-01-29 07:05:16 +01:00
|
|
|
// TODO: Factor blocked out
|
2019-01-07 23:44:34 +01:00
|
|
|
let blocked;
|
2019-01-29 07:05:16 +01:00
|
|
|
|
|
|
|
if (isBlocked(outpoint)) {
|
2019-01-07 23:44:34 +01:00
|
|
|
blocked = true;
|
|
|
|
}
|
2018-10-10 02:11:06 +02:00
|
|
|
|
2018-12-19 08:16:36 +01:00
|
|
|
if (!chName && certificateId && !channelName) {
|
2019-01-29 07:05:16 +01:00
|
|
|
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) {
|
2019-01-29 07:05:16 +01:00
|
|
|
channelShortId = await chainquery.claim.queries
|
|
|
|
.getShortClaimIdFromLongClaimId(certificateId, channelName)
|
|
|
|
.catch(() => null);
|
2018-10-29 15:09:26 +01:00
|
|
|
}
|
|
|
|
|
2019-01-29 07:05:16 +01:00
|
|
|
// Find a solution for the legacy application/octet-stream file extensions
|
2018-12-16 07:12:12 +01:00
|
|
|
|
2019-01-29 07:05:16 +01:00
|
|
|
return {
|
|
|
|
name: dataVals.name,
|
|
|
|
title: dataVals.title,
|
2018-10-10 02:11:06 +02:00
|
|
|
certificateId,
|
|
|
|
channelName,
|
2018-10-29 15:09:26 +01:00
|
|
|
channelShortId,
|
2019-01-29 07:05:16 +01:00
|
|
|
contentType: dataVals.content_type || data.contentType,
|
|
|
|
claimId: dataVals.claim_id || data.claimId,
|
|
|
|
fileExt: fileExt,
|
|
|
|
description: dataVals.description,
|
2019-02-13 01:38:07 +01:00
|
|
|
nsfw: dataVals.is_nsfw,
|
2019-01-29 07:05:16 +01:00
|
|
|
thumbnail: dataVals.thumbnail_url || data.thumbnail || thumbnail,
|
|
|
|
outpoint,
|
2018-10-10 02:11:06 +02:00
|
|
|
host,
|
2019-01-29 07:05:16 +01:00
|
|
|
pending: Boolean(dataVals.height === 0),
|
|
|
|
blocked: blocked,
|
|
|
|
};
|
2018-11-11 01:11:12 +01:00
|
|
|
};
|