Merge pull request #924 from jessopb/sdkUpdates

updates for sdk .32
This commit is contained in:
jessopb 2019-02-19 01:08:32 -05:00 committed by GitHub
commit cf97b0d3df
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 63 additions and 34 deletions

View file

@ -1,6 +1,9 @@
const logger = require('winston'); const logger = require('winston');
const db = require('server/models'); const db = require('server/models');
const { details, publishing: { disabled, disabledMessage, primaryClaimAddress } } = require('@config/siteConfig'); const {
details,
publishing: { disabled, disabledMessage, primaryClaimAddress },
} = require('@config/siteConfig');
const { resolveUri } = require('server/lbrynet'); const { resolveUri } = require('server/lbrynet');
const { sendGATimingEvent } = require('../../../../utils/googleAnalytics.js'); const { sendGATimingEvent } = require('../../../../utils/googleAnalytics.js');
const { handleErrorResponse } = require('../../../utils/errorHandlers.js'); const { handleErrorResponse } = require('../../../utils/errorHandlers.js');
@ -16,7 +19,7 @@ const createCanonicalLink = require('@globalutils/createCanonicalLink');
route to update a claim through the daemon route to update a claim through the daemon
*/ */
const updateMetadata = ({nsfw, license, title, description}) => { const updateMetadata = ({ nsfw, license, title, description }) => {
const update = {}; const update = {};
if (nsfw) update['nsfw'] = nsfw; if (nsfw) update['nsfw'] = nsfw;
if (license) update['license'] = license; if (license) update['license'] = license;
@ -76,11 +79,19 @@ const claimUpdate = ({ body, files, headers, ip, originalUrl, user, tor }, res)
gaStartTime = Date.now(); gaStartTime = Date.now();
try { try {
({name, nsfw, license, title, description, thumbnail} = parsePublishApiRequestBody(body)); ({ name, nsfw, license, title, description, thumbnail } = parsePublishApiRequestBody(body));
({fileName, filePath, fileExtension, fileType, thumbnailFileName, thumbnailFilePath, thumbnailFileType} = parsePublishApiRequestFiles(files, true)); ({
({channelName, channelId, channelPassword} = body); fileName,
filePath,
fileExtension,
fileType,
thumbnailFileName,
thumbnailFilePath,
thumbnailFileType,
} = parsePublishApiRequestFiles(files, true));
({ channelName, channelId, channelPassword } = body);
} catch (error) { } catch (error) {
return res.status(400).json({success: false, message: error.message}); return res.status(400).json({ success: false, message: error.message });
} }
// check channel authorization // check channel authorization
@ -89,7 +100,9 @@ const claimUpdate = ({ body, files, headers, ip, originalUrl, user, tor }, res)
if (!channelId) { if (!channelId) {
channelId = channelClaimId; channelId = channelClaimId;
} }
return chainquery.claim.queries.resolveClaimInChannel(name, channelClaimId).then(claim => claim.dataValues); return chainquery.claim.queries
.resolveClaimInChannel(name, channelClaimId)
.then(claim => claim.dataValues);
}) })
.then(claim => { .then(claim => {
claimRecord = claim; claimRecord = claim;
@ -107,20 +120,24 @@ const claimUpdate = ({ body, files, headers, ip, originalUrl, user, tor }, res)
return [null, null]; return [null, null];
}) })
.then(([fileResult, resolution]) => { .then(([fileResult, resolution]) => {
metadata = Object.assign({}, { metadata = Object.assign(
title : claimRecord.title, {},
description: claimRecord.description, {
nsfw : claimRecord.nsfw, title: claimRecord.title,
license : claimRecord.license, description: claimRecord.description,
language : 'en', nsfw: claimRecord.nsfw,
author : details.title, license: claimRecord.license,
}, updateMetadata({title, description, nsfw, license})); language: 'en',
author: details.title,
},
updateMetadata({ title, description, nsfw, license })
);
const publishParams = { const publishParams = {
name, name,
bid : '0.01', bid: '0.01',
claim_address: primaryClaimAddress, claim_address: primaryClaimAddress,
channel_name : channelName, channel_name: channelName,
channel_id : channelId, channel_id: channelId,
metadata, metadata,
}; };
@ -128,19 +145,24 @@ const claimUpdate = ({ body, files, headers, ip, originalUrl, user, tor }, res)
if (thumbnailUpdate) { if (thumbnailUpdate) {
// publish new thumbnail // publish new thumbnail
const newThumbnailName = `${name}-${rando()}`; const newThumbnailName = `${name}-${rando()}`;
const newThumbnailParams = createThumbnailPublishParams(filePath, newThumbnailName, license, nsfw); const newThumbnailParams = createThumbnailPublishParams(
filePath,
newThumbnailName,
license,
nsfw
);
newThumbnailParams['file_path'] = filePath; newThumbnailParams['file_path'] = filePath;
publish(newThumbnailParams, fileName, fileType); publish(newThumbnailParams, fileName, fileType);
publishParams['sources'] = resolution.claim.value.stream.source; publishParams['thumbnail'] = `${details.host}/${newThumbnailParams.channel_name}:${
publishParams['thumbnail'] = `${details.host}/${newThumbnailParams.channel_name}:${newThumbnailParams.channel_id}/${newThumbnailName}-thumb.jpg`; newThumbnailParams.channel_id
}/${newThumbnailName}-thumb.jpg`;
} else { } else {
publishParams['file_path'] = filePath; publishParams['file_path'] = filePath;
} }
} else { } else {
fileName = fileResult.fileName; fileName = fileResult.fileName;
fileType = fileResult.fileType; fileType = fileResult.fileType;
publishParams['sources'] = resolution.claim.value.stream.source;
publishParams['thumbnail'] = claimRecord.thumbnail_url; publishParams['thumbnail'] = claimRecord.thumbnail_url;
} }
@ -151,17 +173,24 @@ const claimUpdate = ({ body, files, headers, ip, originalUrl, user, tor }, res)
publishResult = result; publishResult = result;
if (channelName) { if (channelName) {
return chainquery.claim.queries.getShortClaimIdFromLongClaimId(result.certificateId, channelName); return chainquery.claim.queries.getShortClaimIdFromLongClaimId(
result.certificateId,
channelName
);
} else { } else {
return chainquery.claim.queries.getShortClaimIdFromLongClaimId(result.claimId, name, result).catch(() => { return chainquery.claim.queries
return result.claimId.slice(0, 1); .getShortClaimIdFromLongClaimId(result.claimId, name, result)
}); .catch(() => {
return result.claimId.slice(0, 1);
});
} }
}) })
.then(shortId => { .then(shortId => {
let canonicalUrl; let canonicalUrl;
if (channelName) { if (channelName) {
canonicalUrl = createCanonicalLink({ asset: { ...publishResult, channelShortId: shortId } }); canonicalUrl = createCanonicalLink({
asset: { ...publishResult, channelShortId: shortId },
});
} else { } else {
canonicalUrl = createCanonicalLink({ asset: { ...publishResult, shortId } }); canonicalUrl = createCanonicalLink({ asset: { ...publishResult, shortId } });
} }
@ -173,17 +202,17 @@ const claimUpdate = ({ body, files, headers, ip, originalUrl, user, tor }, res)
}); });
} }
const {claimId} = publishResult; const { claimId } = publishResult;
res.status(200).json({ res.status(200).json({
success: true, success: true,
message: 'update successful', message: 'update successful',
data : { data: {
name, name,
claimId, claimId,
url : `${details.host}${canonicalUrl}`, // for backwards compatability with app url: `${details.host}${canonicalUrl}`, // for backwards compatability with app
showUrl : `${details.host}${canonicalUrl}`, showUrl: `${details.host}${canonicalUrl}`,
serveUrl : `${details.host}${canonicalUrl}${fileExtension}`, serveUrl: `${details.host}${canonicalUrl}${fileExtension}`,
pushTo : canonicalUrl, pushTo: canonicalUrl,
claimData: publishResult, claimData: publishResult,
}, },
}); });

View file

@ -93,7 +93,7 @@ module.exports = {
axios axios
.post(lbrynetUri, { .post(lbrynetUri, {
method: 'resolve', method: 'resolve',
params: { uri }, params: { urls: uri },
}) })
.then(({ data }) => { .then(({ data }) => {
sendGATimingEvent('lbrynet', 'resolveUri', 'RESOLVE', gaStartTime, Date.now()); sendGATimingEvent('lbrynet', 'resolveUri', 'RESOLVE', gaStartTime, Date.now());