diff --git a/web/src/chainquery.js b/web/src/chainquery.js index 5725cdac4..af377a01a 100644 --- a/web/src/chainquery.js +++ b/web/src/chainquery.js @@ -12,6 +12,7 @@ function queryPool(sql, params) { return new Promise(resolve => { pool.query(sql, params, (error, rows) => { if (error) { + console.log('error', error); resolve(); return; } @@ -25,18 +26,22 @@ module.exports.getClaim = async function getClaim(claimName, claimId, channelNam let params = [claimName]; let sql = - 'SELECT channel_claim.name as channel, claim.claim_id, claim.name, claim.description, claim.language, claim.thumbnail_url, claim.title, claim.source_media_type, claim.frame_width, claim.frame_height, claim.fee ' + + 'SELECT channel_claim.name as channel, claim.claim_id, claim.name, claim.description, claim.language, claim.thumbnail_url, claim.title, claim.source_media_type, claim.frame_width, claim.frame_height, claim.fee, ' + + 'repost_channel.name as repost_channel, reposted_claim.claim_id as reposted_claim_id, reposted_claim.name as reposted_name, reposted_claim.description as reposted_description, reposted_claim.language as reposted_language, reposted_claim.thumbnail_url as reposted_thumbnail_url, reposted_claim.title as reposted_title, reposted_claim.source_media_type as reposted_source_media_type, reposted_claim.frame_width as reposted_frame_width, reposted_claim.frame_height as reposted_frame_height, reposted_claim.fee as reposted_fee ' + 'FROM claim ' + 'LEFT JOIN claim channel_claim on claim.publisher_id = channel_claim.claim_id ' + + 'LEFT JOIN claim as reposted_claim on reposted_claim.claim_id = claim.claim_reference ' + + 'AND (reposted_claim.bid_state="controlling" OR reposted_claim.bid_state="active")' + + 'LEFT JOIN claim as repost_channel on repost_channel.claim_id = reposted_claim.publisher_id ' + 'WHERE claim.name = ?'; if (claimId) { sql += ' AND claim.claim_id LIKE ?'; params.push(claimId + '%'); - } else { - sql += ' AND claim.bid_state = "controlling"'; } + sql += ' AND claim.bid_state in ("controlling", "active", "accepted")'; + if (claimName[0] !== '@' && channelName) { sql += ' AND channel_claim.name = ?'; params.push('@' + channelName); @@ -44,7 +49,7 @@ module.exports.getClaim = async function getClaim(claimName, claimId, channelNam sql += ' AND channel_claim.claim_id LIKE ?'; params.push(channelClaimId + '%'); } else { - sql += ' AND channel_claim.bid_state = "controlling"'; + sql += ' AND channel_claim.bid_state in ("controlling", "active", "accepted")'; } } diff --git a/web/src/html.js b/web/src/html.js index 535fca460..7796de7c1 100644 --- a/web/src/html.js +++ b/web/src/html.js @@ -138,7 +138,7 @@ function buildClaimOgMetadata(uri, claim, overrideOptions = {}) { return head; } -async function getClaimFromChainquery(url) { +async function getClaimFromChainqueryOrRedirect(ctx, url) { const { isChannel, streamName, channelName, channelClaimId, streamClaimId } = parseURI(url); const claimName = isChannel ? '@' + channelName : streamName; const claimId = isChannel ? channelClaimId : streamClaimId; @@ -146,6 +146,12 @@ async function getClaimFromChainquery(url) { const rows = await getClaim(claimName, claimId, channelName, channelClaimId); if (rows && rows.length) { const claim = rows[0]; + + if (claim.reposted_name && claim.reposted_claim_id) { + ctx.redirect(`/${claim.reposted_name}:${claim.reposted_claim_id}`); + return; + } + return claim; } @@ -173,7 +179,7 @@ async function getHtml(ctx) { try { parseURI(inviteChannelUrl); - const claim = await getClaimFromChainquery(inviteChannelUrl); + const claim = await getClaimFromChainqueryOrRedirect(ctx, inviteChannelUrl); const invitePageMetadata = buildClaimOgMetadata(inviteChannelUrl, claim, { title: `Join ${claim.name} on LBRY`, description: `Join ${claim.name} on LBRY, a content wonderland owned by everyone (and no one).`, @@ -193,7 +199,7 @@ async function getHtml(ctx) { if (requestPath.includes(embedPath)) { const claimUri = requestPath.replace(embedPath, '').replace(/:/g, '#'); - const claim = await getClaimFromChainquery(claimUri); + const claim = await getClaimFromChainqueryOrRedirect(ctx, claimUri); if (claim) { const ogMetadata = buildClaimOgMetadata(claimUri, claim); @@ -205,7 +211,7 @@ async function getHtml(ctx) { if (!requestPath.includes('$')) { const claimUri = requestPath.slice(1).replace(/:/g, '#'); - const claim = await getClaimFromChainquery(claimUri); + const claim = await getClaimFromChainqueryOrRedirect(ctx, claimUri); if (claim) { const ogMetadata = buildClaimOgMetadata(claimUri, claim);