updated short url route
This commit is contained in:
parent
651f90cad9
commit
7dea5d5cd4
3 changed files with 29 additions and 47 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
const logger = require('winston');
|
||||||
|
|
||||||
const { sendGAServeEvent } = require('../../../utils/googleAnalytics');
|
const { sendGAServeEvent } = require('../../../utils/googleAnalytics');
|
||||||
const handleShowRender = require('../../../render/build/handleShowRender.js');
|
const handleShowRender = require('../../../render/build/handleShowRender.js');
|
||||||
|
|
||||||
|
@ -16,39 +18,36 @@ const { SHOW } = require('../constants/request_types.js');
|
||||||
|
|
||||||
const serveByClaim = (req, res) => {
|
const serveByClaim = (req, res) => {
|
||||||
const { headers, ip, originalUrl, params } = req;
|
const { headers, ip, originalUrl, params } = req;
|
||||||
|
|
||||||
|
try {
|
||||||
// return early if channel request
|
// return early if channel request
|
||||||
let isChannel = false;
|
const { isChannel } = lbryUri.parseIdentifier(params.claim);
|
||||||
try {
|
|
||||||
({ isChannel } = lbryUri.parseIdentifier(params.claim));
|
|
||||||
} catch (error) {
|
|
||||||
return res.status(400).json({success: false, message: error.message});
|
|
||||||
}
|
|
||||||
if (isChannel) {
|
if (isChannel) {
|
||||||
|
logger.info('channel request:', { headers, ip, originalUrl, params });
|
||||||
return handleShowRender(req, res);
|
return handleShowRender(req, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
// decide if this is a show request
|
// decide if this is a show request
|
||||||
let hasFileExtension;
|
const { hasFileExtension } = lbryUri.parseModifier(params.claim);
|
||||||
try {
|
if (determineRequestType(hasFileExtension, headers) === SHOW) {
|
||||||
({ hasFileExtension } = lbryUri.parseModifier(params.claim));
|
logger.info('show request:', { headers, ip, originalUrl, params });
|
||||||
} 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);
|
return handleShowRender(req, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse the claim
|
// parse the claim
|
||||||
let claimName;
|
const { claimName } = lbryUri.parseClaim(params.claim);
|
||||||
try {
|
|
||||||
({claimName} = lbryUri.parseClaim(params.claim));
|
|
||||||
} catch (error) {
|
|
||||||
return res.status(400).json({success: false, message: error.message});
|
|
||||||
}
|
|
||||||
// send google analytics
|
// send google analytics
|
||||||
sendGAServeEvent(headers, ip, originalUrl);
|
sendGAServeEvent(headers, ip, originalUrl);
|
||||||
|
|
||||||
// get the claim Id and then serve the asset
|
// 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);
|
getClaimIdAndServeAsset(null, null, claimName, null, originalUrl, ip, res);
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
return res.status(400).json({success: false, message: error.message});
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = serveByClaim;
|
module.exports = serveByClaim;
|
||||||
|
|
|
@ -27,19 +27,7 @@ const serverByIdentifierAndClaim = (req, res) => {
|
||||||
return res.status(400).json({success: false, message: error.message});
|
return res.status(400).json({success: false, message: error.message});
|
||||||
}
|
}
|
||||||
// determine request type
|
// determine request type
|
||||||
let requestType = determineRequestType(hasFileExtension, headers);
|
if (determineRequestType(hasFileExtension, headers) === SHOW) {
|
||||||
|
|
||||||
/* test logging */
|
|
||||||
logger.info('serveByIdentifierAndClaim', {
|
|
||||||
headers,
|
|
||||||
ip,
|
|
||||||
originalUrl,
|
|
||||||
params,
|
|
||||||
response: requestType,
|
|
||||||
});
|
|
||||||
/* end test logging */
|
|
||||||
|
|
||||||
if (requestType === SHOW) {
|
|
||||||
return handleShowRender(req, res);
|
return handleShowRender(req, res);
|
||||||
}
|
}
|
||||||
// parse the claim
|
// parse the claim
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
const logger = require('winston');
|
|
||||||
const { EMBED, SHOW } = require('../constants/request_types.js');
|
const { EMBED, SHOW } = require('../constants/request_types.js');
|
||||||
|
|
||||||
function clientWantsAsset ({accept, range}) {
|
function clientWantsAsset ({accept, range}) {
|
||||||
|
@ -8,10 +7,6 @@ function clientWantsAsset ({accept, range}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const determineRequestType = (hasFileExtension, headers) => {
|
const determineRequestType = (hasFileExtension, headers) => {
|
||||||
logger.info('determineRequestType', {
|
|
||||||
hasFileExtension,
|
|
||||||
headers,
|
|
||||||
});
|
|
||||||
if (hasFileExtension || clientWantsAsset(headers)) {
|
if (hasFileExtension || clientWantsAsset(headers)) {
|
||||||
return EMBED;
|
return EMBED;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue