Merge pull request #827 from jessopb/fileExt

uses lbrynet as fallback to get file extension
This commit is contained in:
Shawn K 2018-12-16 01:41:14 -06:00 committed by GitHub
commit 8f9d80acbe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,9 +1,12 @@
const { details: { host } } = require('@config/siteConfig'); const { details: { host } } = require('@config/siteConfig');
const chainquery = require('chainquery').default; const chainquery = require('chainquery').default;
const { getClaim } = require('server/lbrynet');
module.exports = async (data) => { module.exports = async (data) => {
// 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 channelName = data.channelName; let channelName = data.channelName;
if (certificateId && !channelName) { if (certificateId && !channelName) {
@ -15,6 +18,14 @@ module.exports = async (data) => {
channelShortId = await chainquery.claim.queries.getShortClaimIdFromLongClaimId(certificateId, channelName).catch(() => null); channelShortId = await chainquery.claim.queries.getShortClaimIdFromLongClaimId(certificateId, channelName).catch(() => null);
} }
let lbrynetClaimResult = null;
let lbrynetFileExt = null;
if (!data.fileExt) {
lbrynetClaimResult = await getClaim(lbrynetUri).catch(() => { return 'invalid URI' });
lbrynetFileExt = lbrynetClaimResult && 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,
@ -23,7 +34,7 @@ module.exports = async (data) => {
channelShortId, channelShortId,
contentType: data.content_type || data.contentType, contentType: data.content_type || data.contentType,
claimId : data.claim_id || data.claimId, claimId : data.claim_id || data.claimId,
fileExt : data.generated_extension || data.fileExt, 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.outpoint,