fix video updates
This commit is contained in:
parent
d35f48a90e
commit
cb28ad5c67
7 changed files with 133 additions and 72 deletions
|
@ -2,11 +2,14 @@ import React from 'react';
|
||||||
import FormFeedbackDisplay from '@components/FormFeedbackDisplay';
|
import FormFeedbackDisplay from '@components/FormFeedbackDisplay';
|
||||||
import Row from '@components/Row';
|
import Row from '@components/Row';
|
||||||
|
|
||||||
const DropzoneInstructionsDisplay = ({fileError}) => {
|
const DropzoneInstructionsDisplay = ({fileError, message}) => {
|
||||||
|
if (!message) {
|
||||||
|
message = 'Drag & drop image or video here to publish';
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<div className={'dropzone-instructions-display'}>
|
<div className={'dropzone-instructions-display'}>
|
||||||
<Row>
|
<Row>
|
||||||
<p className={'text--large'}>Drag & drop image or video here to publish</p>
|
<p className={'text--large'}>{message}</p>
|
||||||
</Row>
|
</Row>
|
||||||
<Row>
|
<Row>
|
||||||
<p className={'text--small'}>OR</p>
|
<p className={'text--small'}>OR</p>
|
||||||
|
|
|
@ -12,6 +12,7 @@ class PublishPreview extends React.Component {
|
||||||
componentDidMount () {
|
componentDidMount () {
|
||||||
const { isUpdate, sourceUrl, file } = this.props;
|
const { isUpdate, sourceUrl, file } = this.props;
|
||||||
if (isUpdate && sourceUrl) {
|
if (isUpdate && sourceUrl) {
|
||||||
|
console.log('setting sourceUrl:', sourceUrl);
|
||||||
this.setState({ imgSource: sourceUrl });
|
this.setState({ imgSource: sourceUrl });
|
||||||
} else {
|
} else {
|
||||||
this.setPreviewImageSource(file);
|
this.setPreviewImageSource(file);
|
||||||
|
|
|
@ -13,7 +13,8 @@ const mapStateToProps = ({ show, publish: { file, thumbnail, fileError, isUpdate
|
||||||
if (isUpdate) {
|
if (isUpdate) {
|
||||||
asset = selectAsset(show);
|
asset = selectAsset(show);
|
||||||
if (asset) {
|
if (asset) {
|
||||||
if (asset.claimData.fileExt === 'mp4') {
|
obj.fileExt = asset.claimData.contentType.split('/')[1];
|
||||||
|
if (obj.fileExt === 'mp4') {
|
||||||
obj.sourceUrl = asset.claimData.thumbnail ? asset.claimData.thumbnail : defaultThumbnail;
|
obj.sourceUrl = asset.claimData.thumbnail ? asset.claimData.thumbnail : defaultThumbnail;
|
||||||
} else {
|
} else {
|
||||||
({claimData: {fileExt, outpoint}} = asset);
|
({claimData: {fileExt, outpoint}} = asset);
|
||||||
|
|
|
@ -82,8 +82,10 @@ class Dropzone extends React.Component {
|
||||||
}
|
}
|
||||||
render () {
|
render () {
|
||||||
const { dragOver, mouseOver, dimPreview } = this.state;
|
const { dragOver, mouseOver, dimPreview } = this.state;
|
||||||
const { file, thumbnail, fileError, isUpdate, sourceUrl } = this.props;
|
const { file, thumbnail, fileError, isUpdate, sourceUrl, fileExt } = this.props;
|
||||||
return (
|
return (
|
||||||
|
<div>
|
||||||
|
{isUpdate && fileExt === 'mp4' && (<p>Video thumbnail:</p>)}
|
||||||
<div className='dropzone-wrapper'>
|
<div className='dropzone-wrapper'>
|
||||||
<form>
|
<form>
|
||||||
<input
|
<input
|
||||||
|
@ -126,6 +128,7 @@ class Dropzone extends React.Component {
|
||||||
{ mouseOver ? (
|
{ mouseOver ? (
|
||||||
<DropzoneInstructionsDisplay
|
<DropzoneInstructionsDisplay
|
||||||
fileError={fileError}
|
fileError={fileError}
|
||||||
|
message={fileExt === 'mp4' ? 'Drag & drop new thumbnail' : null}
|
||||||
/>
|
/>
|
||||||
) : null }
|
) : null }
|
||||||
</div>
|
</div>
|
||||||
|
@ -139,6 +142,7 @@ class Dropzone extends React.Component {
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -5,11 +5,11 @@ const { createFileRecordDataAfterPublish } = require('../../../../models/utils/c
|
||||||
const { createClaimRecordDataAfterPublish } = require('../../../../models/utils/createClaimRecordData.js');
|
const { createClaimRecordDataAfterPublish } = require('../../../../models/utils/createClaimRecordData.js');
|
||||||
const deleteFile = require('./deleteFile.js');
|
const deleteFile = require('./deleteFile.js');
|
||||||
|
|
||||||
const publish = async (publishParams, fileName, fileType, filePath) => {
|
const publish = async (publishParams, fileName, fileType) => {
|
||||||
let publishResults;
|
let publishResults;
|
||||||
let channel;
|
let channel;
|
||||||
let fileRecord;
|
let fileRecord;
|
||||||
let newFile = Boolean(filePath);
|
let newFile = Boolean(publishParams.file_path);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
publishResults = await publishClaim(publishParams);
|
publishResults = await publishClaim(publishParams);
|
||||||
|
@ -33,22 +33,28 @@ const publish = async (publishParams, fileName, fileType, filePath) => {
|
||||||
const {claimId} = claimRecord;
|
const {claimId} = claimRecord;
|
||||||
const upsertCriteria = {name: publishParams.name, claimId};
|
const upsertCriteria = {name: publishParams.name, claimId};
|
||||||
if (newFile) {
|
if (newFile) {
|
||||||
|
// this is the problem
|
||||||
|
//
|
||||||
fileRecord = await createFileRecordDataAfterPublish(fileName, fileType, publishParams, publishResults);
|
fileRecord = await createFileRecordDataAfterPublish(fileName, fileType, publishParams, publishResults);
|
||||||
} else {
|
} else {
|
||||||
fileRecord = await db.File.findOne({where: {claimId}});
|
fileRecord = await db.File.findOne({where: {claimId}}).then(result => result.dataValues);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.info('fileRecord:', fileRecord);
|
||||||
|
logger.info('claimRecord:', claimRecord);
|
||||||
|
logger.info('upsertCriteria:', upsertCriteria);
|
||||||
|
|
||||||
const [file, claim] = await Promise.all([
|
const [file, claim] = await Promise.all([
|
||||||
db.upsert(db.File, fileRecord, upsertCriteria, 'File'),
|
db.upsert(db.File, fileRecord, upsertCriteria, 'File'),
|
||||||
db.upsert(db.Claim, claimRecord, upsertCriteria, 'Claim'),
|
db.upsert(db.Claim, claimRecord, upsertCriteria, 'Claim'),
|
||||||
]);
|
]);
|
||||||
logger.info('File and Claim records successfully created');
|
logger.info(`File and Claim records successfully created (${publishParams.name})`);
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
file.setClaim(claim),
|
file.setClaim(claim),
|
||||||
claim.setFile(file),
|
claim.setFile(file),
|
||||||
]);
|
]);
|
||||||
logger.info('File and Claim records successfully associated');
|
logger.info(`File and Claim records successfully associated (${publishParams.name})`);
|
||||||
|
|
||||||
return Object.assign({}, claimRecord, {outpoint});
|
return Object.assign({}, claimRecord, {outpoint});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -56,8 +62,8 @@ const publish = async (publishParams, fileName, fileType, filePath) => {
|
||||||
// this needs work
|
// this needs work
|
||||||
logger.info('publish/publish err:', err);
|
logger.info('publish/publish err:', err);
|
||||||
const error = typeof err === 'string' ? JSON.parse(err) : err;
|
const error = typeof err === 'string' ? JSON.parse(err) : err;
|
||||||
if (filePath) {
|
if (publishParams.file_path) {
|
||||||
await deleteFile(filePath);
|
await deleteFile(publishParams.file_path);
|
||||||
}
|
}
|
||||||
const message = error.error && error.error.message ? error.error.message : 'Unknown publish error';
|
const message = error.error && error.error.message ? error.error.message : 'Unknown publish error';
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -25,6 +25,13 @@ const updateMetadata = ({nsfw, license, title, description}) => {
|
||||||
return update;
|
return update;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const rando = () => {
|
||||||
|
let text = '';
|
||||||
|
const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||||
|
for (let i = 0; i < 6; i += 1) text += possible.charAt(Math.floor(Math.random() * 62));
|
||||||
|
return text;
|
||||||
|
};
|
||||||
|
|
||||||
const claimUpdate = ({ body, files, headers, ip, originalUrl, user, tor }, res) => {
|
const claimUpdate = ({ body, files, headers, ip, originalUrl, user, tor }, res) => {
|
||||||
// logging
|
// logging
|
||||||
logger.info('Claim update request:', {
|
logger.info('Claim update request:', {
|
||||||
|
@ -44,7 +51,27 @@ const claimUpdate = ({ body, files, headers, ip, originalUrl, user, tor }, res)
|
||||||
}
|
}
|
||||||
|
|
||||||
// define variables
|
// define variables
|
||||||
let channelName, channelId, channelPassword, description, fileName, filePath, fileType, gaStartTime, thumbnail, fileExtension, license, name, nsfw, thumbnailFileName, thumbnailFilePath, thumbnailFileType, title, claimRecord, metadata, publishResult;
|
let channelName,
|
||||||
|
channelId,
|
||||||
|
channelPassword,
|
||||||
|
description,
|
||||||
|
fileName,
|
||||||
|
filePath,
|
||||||
|
fileType,
|
||||||
|
gaStartTime,
|
||||||
|
thumbnail,
|
||||||
|
fileExtension,
|
||||||
|
license,
|
||||||
|
name,
|
||||||
|
nsfw,
|
||||||
|
thumbnailFileName,
|
||||||
|
thumbnailFilePath,
|
||||||
|
thumbnailFileType,
|
||||||
|
title,
|
||||||
|
claimRecord,
|
||||||
|
metadata,
|
||||||
|
publishResult,
|
||||||
|
thumbnailUpdate = false;
|
||||||
// record the start time of the request
|
// record the start time of the request
|
||||||
gaStartTime = Date.now();
|
gaStartTime = Date.now();
|
||||||
|
|
||||||
|
@ -59,12 +86,19 @@ const claimUpdate = ({ body, files, headers, ip, originalUrl, user, tor }, res)
|
||||||
// check channel authorization
|
// check channel authorization
|
||||||
authenticateUser(channelName, channelId, channelPassword, user)
|
authenticateUser(channelName, channelId, channelPassword, user)
|
||||||
.then(({ channelName, channelClaimId }) => {
|
.then(({ channelName, channelClaimId }) => {
|
||||||
|
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 => {
|
.then(claim => {
|
||||||
claimRecord = claim;
|
claimRecord = claim;
|
||||||
|
if (claimRecord.content_type === 'video/mp4' && files.file) {
|
||||||
|
thumbnailUpdate = true;
|
||||||
|
}
|
||||||
|
logger.info('claimRecord:', claimRecord);
|
||||||
|
|
||||||
if (!files.file) {
|
if (!files.file || thumbnailUpdate) {
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
db.File.findOne({ where: { name, claimId: claim.claim_id } }),
|
db.File.findOne({ where: { name, claimId: claim.claim_id } }),
|
||||||
resolveUri(`${claim.name}#${claim.claim_id}`),
|
resolveUri(`${claim.name}#${claim.claim_id}`),
|
||||||
|
@ -91,18 +125,26 @@ const claimUpdate = ({ body, files, headers, ip, originalUrl, user, tor }, res)
|
||||||
channel_id : channelId,
|
channel_id : channelId,
|
||||||
metadata,
|
metadata,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (files.file) {
|
if (files.file) {
|
||||||
|
if (thumbnailUpdate) {
|
||||||
|
// publish new thumbnail
|
||||||
|
const newThumbnailName = `${name}-${rando()}`;
|
||||||
|
const newThumbnailParams = createThumbnailPublishParams(filePath, newThumbnailName, license, nsfw);
|
||||||
|
newThumbnailParams['file_path'] = filePath;
|
||||||
|
logger.info('newThumbnailParams:', newThumbnailParams);
|
||||||
|
publish(newThumbnailParams, fileName, fileType);
|
||||||
|
|
||||||
|
publishParams['sources'] = resolution.claim.value.stream.source;
|
||||||
|
publishParams['thumbnail'] = `${details.host}/${newThumbnailParams.channel_name}:${newThumbnailParams.channel_id}/${newThumbnailName}-thumb.jpg`;
|
||||||
|
} 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['sources'] = resolution.claim.value.stream.source;
|
||||||
}
|
publishParams['thumbnail'] = claimRecord.thumbnail_url;
|
||||||
// publish the thumbnail, if one exists
|
|
||||||
if (thumbnailFileName) {
|
|
||||||
const thumbnailPublishParams = createThumbnailPublishParams(thumbnailFilePath, name, license, nsfw);
|
|
||||||
publish(thumbnailPublishParams, thumbnailFileName, thumbnailFileType);
|
|
||||||
publishParams['thumbnail'] = `${details.host}/${channelName}:${channelId}/${name}-thumb.jpg`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const fp = files && files.file && files.file.path ? files.file.path : undefined;
|
const fp = files && files.file && files.file.path ? files.file.path : undefined;
|
||||||
|
|
|
@ -47,7 +47,7 @@ async function createFileRecordDataAfterPublish (fileName, fileType, publishPara
|
||||||
width: fileWidth,
|
width: fileWidth,
|
||||||
} = await getMediaDimensions(fileType, filePath);
|
} = await getMediaDimensions(fileType, filePath);
|
||||||
|
|
||||||
return {
|
const obj = {
|
||||||
name,
|
name,
|
||||||
claimId,
|
claimId,
|
||||||
outpoint: `${txid}:${nout}`,
|
outpoint: `${txid}:${nout}`,
|
||||||
|
@ -57,6 +57,10 @@ async function createFileRecordDataAfterPublish (fileName, fileType, publishPara
|
||||||
filePath,
|
filePath,
|
||||||
fileType,
|
fileType,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
console.log('createFileRecordDataAfterPublish return:', obj);
|
||||||
|
|
||||||
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
Loading…
Reference in a new issue