basic show and serve are functioning
This commit is contained in:
parent
bec1dd3f02
commit
b0f43189a3
1 changed files with 16 additions and 10 deletions
|
@ -38,17 +38,19 @@ function retrieveAssetShowInfo (name, claimId) {
|
||||||
module.exports = (app) => {
|
module.exports = (app) => {
|
||||||
// route to serve a specific asset
|
// route to serve a specific asset
|
||||||
app.get('/:name/:claim_id', ({ headers, ip, originalUrl, params }, res) => {
|
app.get('/:name/:claim_id', ({ headers, ip, originalUrl, params }, res) => {
|
||||||
// google analytics
|
|
||||||
sendGoogleAnalytics('serve', headers, ip, originalUrl);
|
|
||||||
// decide to serve or show
|
// decide to serve or show
|
||||||
const dotIndex = params.claim_id.lastIndexOf('.');
|
const dotIndex = params.claim_id.lastIndexOf('.');
|
||||||
if (dotIndex === 0) {
|
if (dotIndex === 0) {
|
||||||
logger.error('only an extension was submitted');
|
logger.error('a file extension with no name was submitted');
|
||||||
|
errorHandlers.handleRequestError('serve', originalUrl, ip, new Error('no claim id provided'), res);
|
||||||
// if an image extension was given, serve the image directly
|
// if an image extension was given, serve the image directly
|
||||||
} else if (dotIndex > 0) {
|
} else if (dotIndex > 0) {
|
||||||
|
// google analytics
|
||||||
|
sendGoogleAnalytics('serve', headers, ip, originalUrl);
|
||||||
const fileExtension = params.claim_id.substring(dotIndex);
|
const fileExtension = params.claim_id.substring(dotIndex);
|
||||||
const claimId = params.claim_id.substring(0, dotIndex - 1);
|
const claimId = params.claim_id.substring(0, dotIndex);
|
||||||
logger.debug('file extension is:', fileExtension);
|
logger.debug('file extension is:', fileExtension);
|
||||||
|
// begin image-serve processes
|
||||||
retrieveAssetServeInfo(params.name, claimId)
|
retrieveAssetServeInfo(params.name, claimId)
|
||||||
.then((fileInfo) => {
|
.then((fileInfo) => {
|
||||||
// check to make sure a file was found
|
// check to make sure a file was found
|
||||||
|
@ -76,10 +78,11 @@ module.exports = (app) => {
|
||||||
});
|
});
|
||||||
// if no image extension was given, show the asset with details
|
// if no image extension was given, show the asset with details
|
||||||
} else if (dotIndex === -1) {
|
} else if (dotIndex === -1) {
|
||||||
// begin image-serve processes
|
// google analytics
|
||||||
|
sendGoogleAnalytics('show', headers, ip, originalUrl);
|
||||||
|
// begin image-show processes
|
||||||
retrieveAssetShowInfo(params.name, params.claim_id)
|
retrieveAssetShowInfo(params.name, params.claim_id)
|
||||||
.then((fileInfo) => {
|
.then((fileInfo) => {
|
||||||
console.log('SHORT URL:', fileInfo.shortUrl);
|
|
||||||
// check to make sure a file was found
|
// check to make sure a file was found
|
||||||
if (!fileInfo) {
|
if (!fileInfo) {
|
||||||
res.status(307).render('noClaims');
|
res.status(307).render('noClaims');
|
||||||
|
@ -96,16 +99,17 @@ module.exports = (app) => {
|
||||||
});
|
});
|
||||||
// route to serve the winning asset at a claim
|
// route to serve the winning asset at a claim
|
||||||
app.get('/:name', ({ headers, ip, originalUrl, params }, res) => {
|
app.get('/:name', ({ headers, ip, originalUrl, params }, res) => {
|
||||||
// google analytics
|
|
||||||
sendGoogleAnalytics('serve', headers, ip, originalUrl);
|
|
||||||
// decide to serve or show
|
// decide to serve or show
|
||||||
const dotIndex = params.name.lastIndexOf('.');
|
const dotIndex = params.name.lastIndexOf('.');
|
||||||
if (dotIndex === 0) {
|
if (dotIndex === 0) {
|
||||||
logger.error('only an extension was submitted');
|
logger.error('a file extension with no name was submitted');
|
||||||
|
errorHandlers.handleRequestError('serve', originalUrl, ip, new Error('no name provided'), res);
|
||||||
// if an image extension was given, serve the image directly
|
// if an image extension was given, serve the image directly
|
||||||
} else if (dotIndex > 0) {
|
} else if (dotIndex > 0) {
|
||||||
|
// google analytics
|
||||||
|
sendGoogleAnalytics('serve', headers, ip, originalUrl);
|
||||||
const fileExtension = params.name.substring(dotIndex);
|
const fileExtension = params.name.substring(dotIndex);
|
||||||
const claimName = params.name.substring(0, dotIndex - 1);
|
const claimName = params.name.substring(0, dotIndex);
|
||||||
logger.debug('file extension is:', fileExtension);
|
logger.debug('file extension is:', fileExtension);
|
||||||
// begin image-serve processes
|
// begin image-serve processes
|
||||||
serveClaimByName(claimName)
|
serveClaimByName(claimName)
|
||||||
|
@ -135,6 +139,8 @@ module.exports = (app) => {
|
||||||
});
|
});
|
||||||
// if no image extension was given, show the asset with details
|
// if no image extension was given, show the asset with details
|
||||||
} else if (dotIndex === -1) {
|
} else if (dotIndex === -1) {
|
||||||
|
// google analytics
|
||||||
|
sendGoogleAnalytics('show', headers, ip, originalUrl);
|
||||||
// get and render the content
|
// get and render the content
|
||||||
showClaimByName(params.name)
|
showClaimByName(params.name)
|
||||||
.then(fileInfo => {
|
.then(fileInfo => {
|
||||||
|
|
Loading…
Add table
Reference in a new issue