updated long url routes

This commit is contained in:
bill bittner 2018-07-18 16:17:20 -07:00
parent 7dea5d5cd4
commit 792fd0ab06
2 changed files with 26 additions and 30 deletions

View file

@ -41,7 +41,7 @@ const serveByClaim = (req, res) => {
sendGAServeEvent(headers, ip, originalUrl);
// get the claim Id and then serve the asset
logger.info('embed request:', { headers, ip, originalUrl, params });
logger.info('serve request:', { headers, ip, originalUrl, params });
getClaimIdAndServeAsset(null, null, claimName, null, originalUrl, ip, res);
} catch (error) {

View file

@ -19,39 +19,35 @@ const { SHOW } = require('../constants/request_types.js');
const serverByIdentifierAndClaim = (req, res) => {
const { headers, ip, originalUrl, params } = req;
// parse request
let hasFileExtension;
try {
({ hasFileExtension } = lbryUri.parseModifier(params.claim));
// 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 indentifier and claim
let { claimName } = lbryUri.parseClaim(params.claim);
let { isChannel, channelName, channelClaimId, claimId } = lbryUri.parseIdentifier(params.identifier);
// for backwards compatability, flip claim name and claim id if necessary
if (!isChannel) {
[claimId, claimName] = flipClaimNameAndId(claimId, claimName);
}
// send google analytics
sendGAServeEvent(headers, ip, originalUrl);
// get the claim Id and then serve the asset
logger.info('serve request:', { headers, ip, originalUrl, params });
getClaimIdAndServeAsset(channelName, channelClaimId, claimName, claimId, originalUrl, ip, res);
} catch (error) {
return res.status(400).json({success: false, message: error.message});
}
// determine request type
if (determineRequestType(hasFileExtension, headers) === 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});
}
// parse the identifier
let isChannel, channelName, channelClaimId, claimId;
try {
({ isChannel, channelName, channelClaimId, claimId } = lbryUri.parseIdentifier(params.identifier));
} catch (error) {
return res.status(400).json({success: false, message: error.message});
}
// for backwards compatability, flip claim name and claim id if necessary
if (!isChannel) {
[claimId, claimName] = flipClaimNameAndId(claimId, claimName);
}
// send google analytics
sendGAServeEvent(headers, ip, originalUrl);
// get the claim Id and then serve the asset
getClaimIdAndServeAsset(channelName, channelClaimId, claimName, claimId, originalUrl, ip, res);
};
module.exports = serverByIdentifierAndClaim;