Merge pull request #513 from lbryio/507-app-thumbnails

fix app thumbnail viewing on spee.ch
This commit is contained in:
Bill Bittner 2018-07-11 10:56:39 -07:00 committed by GitHub
commit 9427776c59
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 25 additions and 11 deletions

View file

@ -19,7 +19,7 @@ var AssetPreview = function AssetPreview(_ref) {
fileExt = _ref$claimData.fileExt, fileExt = _ref$claimData.fileExt,
contentType = _ref$claimData.contentType, contentType = _ref$claimData.contentType,
thumbnail = _ref$claimData.thumbnail; thumbnail = _ref$claimData.thumbnail;
var directSourceLink = "".concat(claimId, "/").concat(name, ".").concat(fileExt); var directSourceLink = "asset/".concat(name, "/").concat(claimId);
var showUrlLink = "/".concat(claimId, "/").concat(name); var showUrlLink = "/".concat(claimId, "/").concat(name);
return _react.default.createElement(_reactRouterDom.Link, { return _react.default.createElement(_reactRouterDom.Link, {
to: showUrlLink to: showUrlLink

View file

@ -82,7 +82,7 @@ function (_React$Component) {
case 'image/gif': case 'image/gif':
return _react.default.createElement("img", { return _react.default.createElement("img", {
className: "asset-image", className: "asset-image",
src: "/".concat(claimId, "/").concat(name, ".").concat(fileExt), src: "/asset/".concat(name, "/").concat(claimId),
alt: name alt: name
}); });
@ -92,7 +92,7 @@ function (_React$Component) {
controls: true, controls: true,
poster: thumbnail poster: thumbnail
}, _react.default.createElement("source", { }, _react.default.createElement("source", {
src: "/".concat(claimId, "/").concat(name, ".").concat(fileExt) src: "/asset/".concat(name, "/").concat(claimId)
}), _react.default.createElement("p", null, "Your browser does not support the ", _react.default.createElement("code", null, "video"), " element.")); }), _react.default.createElement("p", null, "Your browser does not support the ", _react.default.createElement("code", null, "video"), " element."));
default: default:

View file

@ -2,7 +2,7 @@ import React from 'react';
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
const AssetPreview = ({ defaultThumbnail, claimData: { name, claimId, fileExt, contentType, thumbnail } }) => { const AssetPreview = ({ defaultThumbnail, claimData: { name, claimId, fileExt, contentType, thumbnail } }) => {
const directSourceLink = `${claimId}/${name}.${fileExt}`; const directSourceLink = `asset/${name}/${claimId}`;
const showUrlLink = `/${claimId}/${name}`; const showUrlLink = `/${claimId}/${name}`;
return ( return (
<Link to={showUrlLink} > <Link to={showUrlLink} >

View file

@ -39,7 +39,7 @@ class AssetDisplay extends React.Component {
return ( return (
<img <img
className='asset-image' className='asset-image'
src={`/${claimId}/${name}.${fileExt}`} src={`/asset/${name}/${claimId}`}
alt={name} alt={name}
/> />
); );
@ -49,7 +49,9 @@ class AssetDisplay extends React.Component {
className='asset-video' className='asset-video'
controls poster={thumbnail} controls poster={thumbnail}
> >
<source src={`/${claimId}/${name}.${fileExt}`} /> <source
src={`/asset/${name}/${claimId}`}
/>
<p>Your browser does not support the <code>video</code> element.</p> <p>Your browser does not support the <code>video</code> element.</p>
</video> </video>
); );

View file

@ -12,9 +12,18 @@ const parsePublishApiRequestFiles = ({file, thumbnail}) => {
throw new Error('no file type found'); throw new Error('no file type found');
} }
if (!file.size) { if (!file.size) {
throw new Error('no file type found'); throw new Error('no file size found');
} }
// validate the file name // validate the file name
if (!file.name) {
throw new Error('no file name found');
}
if (file.name.indexOf('.') < 0) {
throw new Error('no file extension found in file name');
}
if (file.name.indexOf('.') === 0) {
throw new Error('file name cannot start with "."');
}
if (/'/.test(file.name)) { if (/'/.test(file.name)) {
throw new Error('apostrophes are not allowed in the file name'); throw new Error('apostrophes are not allowed in the file name');
} }

View file

@ -25,7 +25,7 @@ const validateFileTypeAndSize = (file) => {
break; break;
default: default:
logger.debug('publish > file validation > unrecognized file type'); logger.debug('publish > file validation > unrecognized file type');
throw new Error('The ' + file.type + ' content type is not supported. Only, .jpeg, .png, .gif, and .mp4 files are currently supported.'); throw new Error('The ' + file.type + ' content type is not supported. Only, image/jpg, image/png, image/gif, and video/mp4 content types are currently supported.');
} }
return file; return file;
}; };

View file

@ -1,13 +1,16 @@
const logger = require('winston'); const logger = require('winston');
const serveFile = ({ filePath, fileType }, res) => { const serveFile = ({ filePath, fileType }, res) => {
logger.verbose(`serving file: ${filePath}`); if (!fileType) {
logger.error(`no fileType provided for ${filePath}`);
}
const sendFileOptions = { const sendFileOptions = {
headers: { headers: {
'X-Content-Type-Options': 'nosniff', 'X-Content-Type-Options': 'nosniff',
'Content-Type' : fileType || 'image/jpeg', 'Content-Type' : fileType,
}, },
}; };
logger.debug(`fileOptions for ${filePath}:`, sendFileOptions);
res.status(200).sendFile(filePath, sendFileOptions); res.status(200).sendFile(filePath, sendFileOptions);
}; };

View file

@ -1 +1 @@
<video width="100%" controls src="{{host}}/{{claimId}}/{{name}}.mp4" type="video/mp4"></video> <video width="100%" controls src="{{host}}/asset/{{name}}/{{claimId}}" type="video/mp4"></video>