enables chainquery generated extension

This commit is contained in:
jessop 2019-01-29 01:05:16 -05:00
parent d05dc03261
commit 2f109efeb7
3 changed files with 35 additions and 42 deletions

View file

@ -26,16 +26,6 @@ const getterMethods = {
return 'jpg'; return 'jpg';
} }
}, },
// TODO: Factor this out.
generated_thumbnail() {
return this.thumbnail_url || defaultThumbnail;
},
generated_channel() {
console.log(this);
//
},
}; };
export default (sequelize, { BOOLEAN, DATE, DECIMAL, ENUM, INTEGER, STRING, TEXT }) => export default (sequelize, { BOOLEAN, DATE, DECIMAL, ENUM, INTEGER, STRING, TEXT }) =>

View file

@ -1,15 +1,15 @@
const chainquery = require('chainquery').default; const chainquery = require('chainquery').default;
const db = require('server/models'); const db = require('server/models');
const fetchClaimData = async (params) => { const fetchClaimData = async params => {
let { claimId, claimName: name } = params; let { claimId, claimName: name } = params;
if (claimId === 'none') claimId = null; if (claimId === 'none') claimId = null;
const [cq, local] = await Promise.all([ const [cq, local] = await Promise.all([
chainquery.claim.queries.resolveClaim(name, claimId).then(res => res.dataValues).catch(() => {}), chainquery.claim.queries.resolveClaim(name, claimId).catch(() => {}),
db.Claim.resolveClaim(name, claimId).catch(() => {}), db.Claim.resolveClaim(name, claimId).catch(() => {}),
]); ]);
// Todo: don't use localdb to get post publish content
if (!cq && !local) { if (!cq && !local) {
return null; return null;
} }

View file

@ -1,52 +1,55 @@
const { details: { host } } = require('@config/siteConfig'); const {
details: { host },
assetDefaults: { thumbnail },
} = require('@config/siteConfig');
const chainquery = require('chainquery').default; const chainquery = require('chainquery').default;
const { getClaim } = require('server/lbrynet'); // const { getClaim } = require('server/lbrynet');
const { isBlocked } = require('./blockList'); const { isBlocked } = require('./blockList');
module.exports = async (data, chName = null, chShortId = null) => { 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 dataVals = data.dataValues ? data.dataValues : data;
let lbrynetClaimResult = null; const txid = dataVals.transaction_hash_id || dataVals.txid;
let lbrynetFileExt = null; const nout = dataVals.vout || dataVals.nout;
const outpoint = `${txid}:${nout}`;
const certificateId = dataVals.publisher_id || dataVals.certificateId;
const fileExt = data.generated_extension || dataVals.fileExt;
let channelShortId = chShortId; let channelShortId = chShortId;
let channelName = chName; let channelName = chName;
// TODO: Factor blocked out
let blocked; let blocked;
const outPoint = `${data.transaction_hash_id}:${data.vout}`;
if (isBlocked(outPoint)) { if (isBlocked(outpoint)) {
blocked = true; blocked = true;
} }
if (!chName && certificateId && !channelName) { if (!chName && certificateId && !channelName) {
channelName = await chainquery.claim.queries.getClaimChannelName(certificateId).catch(() => { channelName = await chainquery.claim.queries.getClaimChannelName(certificateId).catch(() => {});
});
} }
if (!chShortId && certificateId && channelName) { if (!chShortId && certificateId && channelName) {
channelShortId = await chainquery.claim.queries.getShortClaimIdFromLongClaimId(certificateId, channelName).catch(() => null); channelShortId = await chainquery.claim.queries
.getShortClaimIdFromLongClaimId(certificateId, channelName)
.catch(() => null);
} }
if (!chName && !chShortId && !data.fileExt) { // Find a solution for the legacy application/octet-stream file extensions
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();
}
return ({ return {
name : data.name, name: dataVals.name,
title : data.title, title: dataVals.title,
certificateId, certificateId,
channelName, channelName,
channelShortId, channelShortId,
contentType: data.content_type || data.contentType, contentType: dataVals.content_type || data.contentType,
claimId : data.claim_id || data.claimId, claimId: dataVals.claim_id || data.claimId,
fileExt : data.generated_extension || data.fileExt || lbrynetFileExt, fileExt: fileExt,
description: data.description, description: dataVals.description,
thumbnail : data.generated_thumbnail || data.thumbnail_url || data.thumbnail, thumbnail: dataVals.thumbnail_url || data.thumbnail || thumbnail,
outpoint : outPoint || data.outpoint, outpoint,
host, host,
pending : Boolean(data.height === 0), pending: Boolean(dataVals.height === 0),
blocked : blocked, blocked: blocked,
}); };
}; };