Merge pull request #847 from jessopb/getClaimPreviewData

reduces channel loadtimes, fixes fallback fileExt
This commit is contained in:
Shawn K 2018-12-19 16:19:13 -06:00 committed by GitHub
commit 1d00891c64
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 17 deletions

View file

@ -23,7 +23,7 @@ const getChannelClaims = async (channelName, channelShortId, page) => {
); );
channelClaims = split.zero.concat(split.nonzero); channelClaims = split.zero.concat(split.nonzero);
const processingChannelClaims = channelClaims ? channelClaims.map((claim) => getClaimData(claim)) : []; const processingChannelClaims = channelClaims ? channelClaims.map((claim) => getClaimData(claim, channelName, channelShortId)) : [];
const processedChannelClaims = await Promise.all(processingChannelClaims); const processedChannelClaims = await Promise.all(processingChannelClaims);
return returnPaginatedChannelClaims(channelName, channelId, processedChannelClaims, page); return returnPaginatedChannelClaims(channelName, channelId, processedChannelClaims, page);

View file

@ -2,30 +2,31 @@ const { details: { host } } = require('@config/siteConfig');
const chainquery = require('chainquery').default; const chainquery = require('chainquery').default;
const { getClaim } = require('server/lbrynet'); const { getClaim } = require('server/lbrynet');
module.exports = async (data) => { module.exports = async (data, chName = null, chShortId = null) => {
// TODO: Refactor getching the channel name out; requires invasive changes. // TODO: Refactor getching the channel name out; requires invasive changes.
const certificateId = data.publisher_id || data.certificateId; const certificateId = data.publisher_id || data.certificateId;
const lbrynetUri = `${data.name}#${data.claim_id}`; let lbrynetClaimResult = null;
let channelName = data.channelName; let lbrynetFileExt = null;
let channelShortId = chShortId;
let channelName = chName;
if (certificateId && !channelName) { if (!chName && certificateId && !channelName) {
channelName = await chainquery.claim.queries.getClaimChannelName(certificateId).catch(() => {}); channelName = await chainquery.claim.queries.getClaimChannelName(certificateId).catch(() => {
});
} }
let channelShortId = null; if (!chShortId && certificateId && channelName) {
if (certificateId && channelName) {
channelShortId = await chainquery.claim.queries.getShortClaimIdFromLongClaimId(certificateId, channelName).catch(() => null); channelShortId = await chainquery.claim.queries.getShortClaimIdFromLongClaimId(certificateId, channelName).catch(() => null);
} }
let lbrynetClaimResult = null; if (!chName && !chShortId && !data.fileExt) {
let lbrynetFileExt = null; 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();
}
// if (!data.fileExt) {
// lbrynetClaimResult = await getClaim(lbrynetUri).catch(() => { return 'invalid URI' });
// lbrynetFileExt = lbrynetClaimResult && lbrynetClaimResult.file_name && lbrynetClaimResult.file_name.split('.').slice(-1).pop();
// }
// TODO verify that "generated_x" does anything at all
return ({ return ({
name : data.name, name : data.name,
title : data.title, title : data.title,
@ -37,7 +38,7 @@ module.exports = async (data) => {
fileExt : data.generated_extension || data.fileExt || lbrynetFileExt, fileExt : data.generated_extension || data.fileExt || lbrynetFileExt,
description: data.description, description: data.description,
thumbnail : data.generated_thumbnail || data.thumbnail_url || data.thumbnail, thumbnail : data.generated_thumbnail || data.thumbnail_url || data.thumbnail,
outpoint : data.transaction_hash_id || data.outpoint, outpoint : `${data.transaction_hash_id}:${data.vout}` || data.outpoint,
host, host,
pending : Boolean(data.height === 0), pending : Boolean(data.height === 0),
}); });