updates for sdk .32 #924

Merged
jessopb merged 1 commit from sdkUpdates into master 2019-02-19 07:08:33 +01:00
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');
@ -77,7 +80,15 @@ const claimUpdate = ({ body, files, headers, ip, originalUrl, user, tor }, res)
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)); ({
fileName,
filePath,
fileExtension,
fileType,
thumbnailFileName,
thumbnailFilePath,
thumbnailFileType,
} = parsePublishApiRequestFiles(files, true));
({ channelName, channelId, channelPassword } = body); ({ 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 });
@ -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,14 +120,18 @@ 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, title: claimRecord.title,
description: claimRecord.description, description: claimRecord.description,
nsfw: claimRecord.nsfw, nsfw: claimRecord.nsfw,
license: claimRecord.license, license: claimRecord.license,
language: 'en', language: 'en',
author: details.title, author: details.title,
}, updateMetadata({title, description, nsfw, license})); },
updateMetadata({ title, description, nsfw, license })
);
const publishParams = { const publishParams = {
name, name,
bid: '0.01', bid: '0.01',
@ -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,9 +173,14 @@ 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
.getShortClaimIdFromLongClaimId(result.claimId, name, result)
.catch(() => {
return result.claimId.slice(0, 1); return result.claimId.slice(0, 1);
}); });
} }
@ -161,7 +188,9 @@ const claimUpdate = ({ body, files, headers, ip, originalUrl, user, tor }, res)
.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 } });
} }

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());