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 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 { sendGATimingEvent } = require('../../../../utils/googleAnalytics.js');
const { handleErrorResponse } = require('../../../utils/errorHandlers.js');
@ -77,7 +80,15 @@ const claimUpdate = ({ body, files, headers, ip, originalUrl, user, tor }, res)
try {
({ 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);
} catch (error) {
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) {
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 => {
claimRecord = claim;
@ -107,14 +120,18 @@ const claimUpdate = ({ body, files, headers, ip, originalUrl, user, tor }, res)
return [null, null];
})
.then(([fileResult, resolution]) => {
metadata = Object.assign({}, {
metadata = Object.assign(
{},
{
title: claimRecord.title,
description: claimRecord.description,
nsfw: claimRecord.nsfw,
license: claimRecord.license,
language: 'en',
author: details.title,
}, updateMetadata({title, description, nsfw, license}));
},
updateMetadata({ title, description, nsfw, license })
);
const publishParams = {
name,
bid: '0.01',
@ -128,19 +145,24 @@ const claimUpdate = ({ body, files, headers, ip, originalUrl, user, tor }, res)
if (thumbnailUpdate) {
// publish new thumbnail
const newThumbnailName = `${name}-${rando()}`;
const newThumbnailParams = createThumbnailPublishParams(filePath, newThumbnailName, license, nsfw);
const newThumbnailParams = createThumbnailPublishParams(
filePath,
newThumbnailName,
license,
nsfw
);
newThumbnailParams['file_path'] = filePath;
publish(newThumbnailParams, fileName, fileType);
publishParams['sources'] = resolution.claim.value.stream.source;
publishParams['thumbnail'] = `${details.host}/${newThumbnailParams.channel_name}:${newThumbnailParams.channel_id}/${newThumbnailName}-thumb.jpg`;
publishParams['thumbnail'] = `${details.host}/${newThumbnailParams.channel_name}:${
newThumbnailParams.channel_id
}/${newThumbnailName}-thumb.jpg`;
} else {
publishParams['file_path'] = filePath;
}
} else {
fileName = fileResult.fileName;
fileType = fileResult.fileType;
publishParams['sources'] = resolution.claim.value.stream.source;
publishParams['thumbnail'] = claimRecord.thumbnail_url;
}
@ -151,9 +173,14 @@ const claimUpdate = ({ body, files, headers, ip, originalUrl, user, tor }, res)
publishResult = result;
if (channelName) {
return chainquery.claim.queries.getShortClaimIdFromLongClaimId(result.certificateId, channelName);
return chainquery.claim.queries.getShortClaimIdFromLongClaimId(
result.certificateId,
channelName
);
} 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);
});
}
@ -161,7 +188,9 @@ const claimUpdate = ({ body, files, headers, ip, originalUrl, user, tor }, res)
.then(shortId => {
let canonicalUrl;
if (channelName) {
canonicalUrl = createCanonicalLink({ asset: { ...publishResult, channelShortId: shortId } });
canonicalUrl = createCanonicalLink({
asset: { ...publishResult, channelShortId: shortId },
});
} else {
canonicalUrl = createCanonicalLink({ asset: { ...publishResult, shortId } });
}

View file

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