spee.ch/server/utils/getClaimData.js

64 lines
1.9 KiB
JavaScript
Raw Normal View History

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
module.exports = async (data, chName = null, chShortId = null) => {
// 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;
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;
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;
}
if (!chName && certificateId && !channelName) {
2019-01-29 07:05:16 +01:00
channelName = await chainquery.claim.queries.getClaimChannelName(certificateId).catch(() => {});
}
if (!chShortId && certificateId && channelName) {
2019-01-29 07:05:16 +01:00
channelShortId = await chainquery.claim.queries
.getShortClaimIdFromLongClaimId(certificateId, channelName)
.catch(() => null);
}
2019-01-29 07:05:16 +01:00
// Find a solution for the legacy application/octet-stream file extensions
2019-01-29 07:05:16 +01:00
return {
name: dataVals.name,
title: dataVals.title,
certificateId,
channelName,
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,
host,
2019-01-29 07:05:16 +01:00
pending: Boolean(dataVals.height === 0),
blocked: blocked,
};
2018-11-11 01:11:12 +01:00
};