serve static assets on urls with file extension #538

Merged
bones7242 merged 19 commits from 515-showlite-serves-asset into master 2018-07-20 18:57:12 +02:00
3 changed files with 29 additions and 47 deletions
Showing only changes of commit 7dea5d5cd4 - Show all commits

View file

@ -1,3 +1,5 @@
const logger = require('winston');
const { sendGAServeEvent } = require('../../../utils/googleAnalytics');
const handleShowRender = require('../../../render/build/handleShowRender.js');
@ -16,39 +18,36 @@ const { SHOW } = require('../constants/request_types.js');
const serveByClaim = (req, res) => {
const { headers, ip, originalUrl, params } = req;
// return early if channel request
let isChannel = false;
try {
({ isChannel } = lbryUri.parseIdentifier(params.claim));
// return early if channel request
const { isChannel } = lbryUri.parseIdentifier(params.claim);
if (isChannel) {
logger.info('channel request:', { headers, ip, originalUrl, params });
return handleShowRender(req, res);
}
// decide if this is a show request
const { hasFileExtension } = lbryUri.parseModifier(params.claim);
if (determineRequestType(hasFileExtension, headers) === SHOW) {
logger.info('show request:', { headers, ip, originalUrl, params });
return handleShowRender(req, res);
}
// parse the claim
const { claimName } = lbryUri.parseClaim(params.claim);
// send google analytics
sendGAServeEvent(headers, ip, originalUrl);
// get the claim Id and then serve the asset
logger.info('embed request:', { headers, ip, originalUrl, params });
getClaimIdAndServeAsset(null, null, claimName, null, originalUrl, ip, res);
} catch (error) {
return res.status(400).json({success: false, message: error.message});
}
if (isChannel) {
return handleShowRender(req, res);
}
// decide if this is a show request
let hasFileExtension;
try {
({ hasFileExtension } = lbryUri.parseModifier(params.claim));
} catch (error) {
return res.status(400).json({success: false, message: error.message});
}
// determine request type
let requestType = determineRequestType(hasFileExtension, headers);
if (requestType === SHOW) {
return handleShowRender(req, res);
}
// parse the claim
let claimName;
try {
({claimName} = lbryUri.parseClaim(params.claim));
} catch (error) {
return res.status(400).json({success: false, message: error.message});
}
// send google analytics
sendGAServeEvent(headers, ip, originalUrl);
// get the claim Id and then serve the asset
getClaimIdAndServeAsset(null, null, claimName, null, originalUrl, ip, res);
};
module.exports = serveByClaim;

View file

@ -27,19 +27,7 @@ const serverByIdentifierAndClaim = (req, res) => {
return res.status(400).json({success: false, message: error.message});
}
// determine request type
let requestType = determineRequestType(hasFileExtension, headers);
/* test logging */
logger.info('serveByIdentifierAndClaim', {
headers,
ip,
originalUrl,
params,
response: requestType,
});
/* end test logging */
if (requestType === SHOW) {
if (determineRequestType(hasFileExtension, headers) === SHOW) {
return handleShowRender(req, res);
}
// parse the claim

View file

@ -1,4 +1,3 @@
const logger = require('winston');
const { EMBED, SHOW } = require('../constants/request_types.js');
function clientWantsAsset ({accept, range}) {
@ -8,10 +7,6 @@ function clientWantsAsset ({accept, range}) {
}
const determineRequestType = (hasFileExtension, headers) => {
logger.info('determineRequestType', {
hasFileExtension,
headers,
});
if (hasFileExtension || clientWantsAsset(headers)) {
return EMBED;
}