added a direct serve route
This commit is contained in:
parent
1b1ebb1b7c
commit
a8cfbd3c9e
5 changed files with 47 additions and 28 deletions
20
server/controllers/assets/serveAsset/index.js
Normal file
20
server/controllers/assets/serveAsset/index.js
Normal file
|
@ -0,0 +1,20 @@
|
|||
const { sendGAServeEvent } = require('../../../utils/googleAnalytics');
|
||||
const getClaimIdAndServeAsset = require('../utils/getClaimIdAndServeAsset.js');
|
||||
const logRequestData = require('../utils/logRequestData.js');
|
||||
|
||||
/*
|
||||
|
||||
route to serve an asset directly
|
||||
|
||||
*/
|
||||
|
||||
const serveAsset = ({ headers, ip, originalUrl, params: { claimName, claimId } }, res) => {
|
||||
// send google analytics
|
||||
sendGAServeEvent(headers, ip, originalUrl);
|
||||
// log the request data for debugging
|
||||
logRequestData(null, claimName, null, claimId);
|
||||
// get the claim Id and then serdve the asset
|
||||
getClaimIdAndServeAsset(null, null, claimName, claimId, originalUrl, ip, res);
|
||||
};
|
||||
|
||||
module.exports = serveAsset;
|
|
@ -3,11 +3,11 @@ const handleShowRender = require('../../../render/build/handleShowRender.js');
|
|||
|
||||
const lbryUri = require('../utils/lbryUri.js');
|
||||
|
||||
const determineResponseType = require('../utils/determineResponseType.js');
|
||||
const determineRequestType = require('../utils/determineRequestType.js');
|
||||
const getClaimIdAndServeAsset = require('../utils/getClaimIdAndServeAsset.js');
|
||||
const logRequestData = require('../utils/logRequestData.js');
|
||||
|
||||
const SERVE = 'SERVE';
|
||||
const { EMBED } = require('../constants/request_types.js');
|
||||
|
||||
/*
|
||||
|
||||
|
@ -15,7 +15,7 @@ const SERVE = 'SERVE';
|
|||
|
||||
*/
|
||||
|
||||
const serverAssetByClaim = (req, res) => {
|
||||
const serveByClaim = (req, res) => {
|
||||
const { headers, ip, originalUrl, params } = req;
|
||||
// decide if this is a show request
|
||||
let hasFileExtension;
|
||||
|
@ -24,13 +24,11 @@ const serverAssetByClaim = (req, res) => {
|
|||
} catch (error) {
|
||||
return res.status(400).json({success: false, message: error.message});
|
||||
}
|
||||
let responseType = determineResponseType(hasFileExtension, headers);
|
||||
if (responseType !== SERVE) {
|
||||
// determine request type
|
||||
let requestType = determineRequestType(hasFileExtension, headers);
|
||||
if (requestType !== EMBED) {
|
||||
return handleShowRender(req, res);
|
||||
}
|
||||
// handle serve request
|
||||
// send google analytics
|
||||
sendGAServeEvent(headers, ip, originalUrl);
|
||||
// parse the claim
|
||||
let claimName;
|
||||
try {
|
||||
|
@ -38,10 +36,12 @@ const serverAssetByClaim = (req, res) => {
|
|||
} catch (error) {
|
||||
return res.status(400).json({success: false, message: error.message});
|
||||
}
|
||||
// send google analytics
|
||||
sendGAServeEvent(headers, ip, originalUrl);
|
||||
// log the request data for debugging
|
||||
logRequestData(responseType, claimName, null, null);
|
||||
logRequestData(requestType, claimName, null, null);
|
||||
// get the claim Id and then serve the asset
|
||||
getClaimIdAndServeAsset(null, null, claimName, null, originalUrl, ip, res);
|
||||
};
|
||||
|
||||
module.exports = serverAssetByClaim;
|
||||
module.exports = serveByClaim;
|
||||
|
|
|
@ -8,7 +8,7 @@ const getClaimIdAndServeAsset = require('../utils/getClaimIdAndServeAsset.js');
|
|||
const flipClaimNameAndId = require('../utils/flipClaimNameAndId.js');
|
||||
const logRequestData = require('../utils/logRequestData.js');
|
||||
|
||||
const { BROWSER, SOCIAL } = require('../constants/request_types.js');
|
||||
const { EMBED } = require('../constants/request_types.js');
|
||||
|
||||
/*
|
||||
|
||||
|
@ -16,25 +16,20 @@ const { BROWSER, SOCIAL } = require('../constants/request_types.js');
|
|||
|
||||
*/
|
||||
|
||||
const serverAssetByIdentifierAndClaim = (req, res) => {
|
||||
const serverByIdentifierAndClaim = (req, res) => {
|
||||
const { headers, ip, originalUrl, params } = req;
|
||||
// decide if this is a show request
|
||||
// parse 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 == BROWSER) {
|
||||
if (requestType !== EMBED) {
|
||||
return handleShowRender(req, res);
|
||||
}
|
||||
if (requestType == SOCIAL) {
|
||||
return handleSocialRequest(req, res);
|
||||
}
|
||||
// handle serve request
|
||||
// send google analytics
|
||||
sendGAServeEvent(headers, ip, originalUrl);
|
||||
// parse the claim
|
||||
let claimName;
|
||||
try {
|
||||
|
@ -53,10 +48,12 @@ const serverAssetByIdentifierAndClaim = (req, res) => {
|
|||
if (!isChannel) {
|
||||
[claimId, claimName] = flipClaimNameAndId(claimId, claimName);
|
||||
}
|
||||
// send google analytics
|
||||
sendGAServeEvent(headers, ip, originalUrl);
|
||||
// log the request data for debugging
|
||||
logRequestData(requestType, claimName, channelName, claimId);
|
||||
// get the claim Id and then serve the asset
|
||||
getClaimIdAndServeAsset(channelName, channelClaimId, claimName, claimId, originalUrl, ip, res);
|
||||
};
|
||||
|
||||
module.exports = serverAssetByIdentifierAndClaim;
|
||||
module.exports = serverByIdentifierAndClaim;
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
const serveAssetByClaim = require('../../controllers/assets/serveByClaim');
|
||||
const serveAssetByIdentifierAndClaim = require('../../controllers/assets/serveByIdentifierAndClaim');
|
||||
const serveByClaim = require('../../controllers/assets/serveByClaim');
|
||||
const serveByIdentifierAndClaim = require('../../controllers/assets/serveByIdentifierAndClaim');
|
||||
const serveAsset = require('../../controllers/assets/serveAsset');
|
||||
|
||||
module.exports = (app, db) => {
|
||||
app.get('/:identifier/:claim', serveAssetByIdentifierAndClaim);
|
||||
app.get('/:claim', serveAssetByClaim);
|
||||
module.exports = (app) => {
|
||||
app.get('/asset/:claimName/:claimId/', serveAsset);
|
||||
app.get('/:identifier/:claim', serveByIdentifierAndClaim);
|
||||
app.get('/:claim', serveByClaim);
|
||||
};
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
const handlePageRequest = require('../../controllers/pages/sendReactApp');
|
||||
const handleEmbedRequest = require('../../controllers/pages/sendEmbedPage');
|
||||
// const handleEmbedRequest = require('../../controllers/pages/sendEmbedPage');
|
||||
const redirect = require('../../controllers/utils/redirect');
|
||||
|
||||
module.exports = (app) => {
|
||||
|
@ -10,5 +10,5 @@ module.exports = (app) => {
|
|||
app.get('/popular', handlePageRequest);
|
||||
app.get('/new', handlePageRequest);
|
||||
app.get('/multisite', handlePageRequest);
|
||||
app.get('/embed/:claimId/:name', handleEmbedRequest); // route to send embedable video player (for twitter)
|
||||
// app.get('/embed/:claimId/:name', handleEmbedRequest); // route to send embedable video player (for twitter)
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue