redirect to reposted claims serverside
This commit is contained in:
parent
ca38d2cbdc
commit
c9c98501af
2 changed files with 17 additions and 6 deletions
|
@ -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,9 +26,13 @@ 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) {
|
||||
|
|
|
@ -138,7 +138,7 @@ function buildClaimOgMetadata(uri, claim, overrideOptions = {}) {
|
|||
return head;
|
||||
}
|
||||
|
||||
async function getClaimFromChainquery(url) {
|
||||
async function getClaimFromChainqueryOrRedirect(url, ctx) {
|
||||
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(inviteChannelUrl, ctx);
|
||||
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(claimUri, ctx);
|
||||
|
||||
if (claim) {
|
||||
const ogMetadata = buildClaimOgMetadata(claimUri, claim);
|
||||
|
@ -205,8 +211,8 @@ async function getHtml(ctx) {
|
|||
|
||||
if (!requestPath.includes('$')) {
|
||||
const claimUri = requestPath.slice(1).replace(/:/g, '#');
|
||||
const claim = await getClaimFromChainquery(claimUri);
|
||||
|
||||
const claim = await getClaimFromChainqueryOrRedirect(claimUri, ctx);
|
||||
console.log('claim', claim);
|
||||
if (claim) {
|
||||
const ogMetadata = buildClaimOgMetadata(claimUri, claim);
|
||||
return insertToHead(html, ogMetadata);
|
||||
|
|
Loading…
Reference in a new issue