enables chainquery generated extension
This commit is contained in:
parent
d05dc03261
commit
2f109efeb7
3 changed files with 35 additions and 42 deletions
|
@ -26,16 +26,6 @@ const getterMethods = {
|
|||
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 }) =>
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
const chainquery = require('chainquery').default;
|
||||
const db = require('server/models');
|
||||
|
||||
const fetchClaimData = async (params) => {
|
||||
const fetchClaimData = async params => {
|
||||
let { claimId, claimName: name } = params;
|
||||
if (claimId === 'none') claimId = null;
|
||||
|
||||
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(() => {}),
|
||||
]);
|
||||
|
||||
// Todo: don't use localdb to get post publish content
|
||||
if (!cq && !local) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -1,52 +1,55 @@
|
|||
const { details: { host } } = require('@config/siteConfig');
|
||||
const {
|
||||
details: { host },
|
||||
assetDefaults: { thumbnail },
|
||||
} = require('@config/siteConfig');
|
||||
const chainquery = require('chainquery').default;
|
||||
const { getClaim } = require('server/lbrynet');
|
||||
// const { getClaim } = require('server/lbrynet');
|
||||
const { isBlocked } = require('./blockList');
|
||||
|
||||
module.exports = async (data, chName = null, chShortId = null) => {
|
||||
// TODO: Refactor getching the channel name out; requires invasive changes.
|
||||
const certificateId = data.publisher_id || data.certificateId;
|
||||
let lbrynetClaimResult = null;
|
||||
let lbrynetFileExt = null;
|
||||
const dataVals = data.dataValues ? data.dataValues : data;
|
||||
const txid = dataVals.transaction_hash_id || dataVals.txid;
|
||||
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 channelName = chName;
|
||||
// TODO: Factor blocked out
|
||||
let blocked;
|
||||
const outPoint = `${data.transaction_hash_id}:${data.vout}`;
|
||||
if (isBlocked(outPoint)) {
|
||||
|
||||
if (isBlocked(outpoint)) {
|
||||
blocked = true;
|
||||
}
|
||||
|
||||
if (!chName && certificateId && !channelName) {
|
||||
channelName = await chainquery.claim.queries.getClaimChannelName(certificateId).catch(() => {
|
||||
});
|
||||
channelName = await chainquery.claim.queries.getClaimChannelName(certificateId).catch(() => {});
|
||||
}
|
||||
|
||||
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) {
|
||||
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();
|
||||
}
|
||||
// Find a solution for the legacy application/octet-stream file extensions
|
||||
|
||||
return ({
|
||||
name : data.name,
|
||||
title : data.title,
|
||||
return {
|
||||
name: dataVals.name,
|
||||
title: dataVals.title,
|
||||
certificateId,
|
||||
channelName,
|
||||
channelShortId,
|
||||
contentType: data.content_type || data.contentType,
|
||||
claimId : data.claim_id || data.claimId,
|
||||
fileExt : data.generated_extension || data.fileExt || lbrynetFileExt,
|
||||
description: data.description,
|
||||
thumbnail : data.generated_thumbnail || data.thumbnail_url || data.thumbnail,
|
||||
outpoint : outPoint || data.outpoint,
|
||||
contentType: dataVals.content_type || data.contentType,
|
||||
claimId: dataVals.claim_id || data.claimId,
|
||||
fileExt: fileExt,
|
||||
description: dataVals.description,
|
||||
thumbnail: dataVals.thumbnail_url || data.thumbnail || thumbnail,
|
||||
outpoint,
|
||||
host,
|
||||
pending : Boolean(data.height === 0),
|
||||
pending: Boolean(dataVals.height === 0),
|
||||
blocked: blocked,
|
||||
});
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue