updated google analytics
This commit is contained in:
parent
a7f8154082
commit
a6cbb79921
6 changed files with 17 additions and 24 deletions
|
@ -94,7 +94,7 @@ module.exports = {
|
||||||
getAssetByShortUrl: function (shortUrl, name) {
|
getAssetByShortUrl: function (shortUrl, name) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// get the full claimId
|
// get the full claimId
|
||||||
serveHelpers.getClaimIdByShortUrl(shortUrl, name)
|
serveHelpers.getClaimIdFromShortUrl(shortUrl, name)
|
||||||
// get the asset by the claimId
|
// get the asset by the claimId
|
||||||
.then(claimId => {
|
.then(claimId => {
|
||||||
resolve(getAssetByClaimId(claimId, name));
|
resolve(getAssetByClaimId(claimId, name));
|
||||||
|
|
|
@ -42,7 +42,7 @@ module.exports = {
|
||||||
const visitor = ua(googleApiKey, visitorId, { strictCidFormat: false, https: true });
|
const visitor = ua(googleApiKey, visitorId, { strictCidFormat: false, https: true });
|
||||||
let params;
|
let params;
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case 'serve':
|
case 'SERVE':
|
||||||
params = {
|
params = {
|
||||||
ec : 'serve',
|
ec : 'serve',
|
||||||
ea : originalUrl,
|
ea : originalUrl,
|
||||||
|
@ -51,7 +51,7 @@ module.exports = {
|
||||||
ul : headers['accept-language'],
|
ul : headers['accept-language'],
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
case 'publish':
|
case 'PUBLISH':
|
||||||
params = {
|
params = {
|
||||||
ec : 'publish',
|
ec : 'publish',
|
||||||
ea : originalUrl,
|
ea : originalUrl,
|
||||||
|
|
|
@ -92,7 +92,7 @@ module.exports = {
|
||||||
logger.debug('showing file lite');
|
logger.debug('showing file lite');
|
||||||
res.status(200).render('showLite', { layout: 'show', fileInfo });
|
res.status(200).render('showLite', { layout: 'show', fileInfo });
|
||||||
},
|
},
|
||||||
getClaimIdByShortUrl (shortUrl, name) {
|
getClaimIdFromShortUrl (shortUrl, name) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
logger.debug('getting claims list from lbrynet');
|
logger.debug('getting claims list from lbrynet');
|
||||||
// use the daemon to check for claims list
|
// use the daemon to check for claims list
|
||||||
|
|
|
@ -11,7 +11,7 @@ module.exports = (app, hostedContentPath) => {
|
||||||
// route to run a claim_list request on the daemon
|
// route to run a claim_list request on the daemon
|
||||||
app.get('/api/claim_list/:name', ({ headers, ip, originalUrl, params }, res) => {
|
app.get('/api/claim_list/:name', ({ headers, ip, originalUrl, params }, res) => {
|
||||||
// google analytics
|
// google analytics
|
||||||
sendGoogleAnalytics('serve', headers, ip, originalUrl);
|
sendGoogleAnalytics('SERVE', headers, ip, originalUrl);
|
||||||
// serve the content
|
// serve the content
|
||||||
lbryApi
|
lbryApi
|
||||||
.getClaimsList(params.name)
|
.getClaimsList(params.name)
|
||||||
|
@ -43,7 +43,7 @@ module.exports = (app, hostedContentPath) => {
|
||||||
// route to run a resolve request on the daemon
|
// route to run a resolve request on the daemon
|
||||||
app.get('/api/resolve/:uri', ({ headers, ip, originalUrl, params }, res) => {
|
app.get('/api/resolve/:uri', ({ headers, ip, originalUrl, params }, res) => {
|
||||||
// google analytics
|
// google analytics
|
||||||
sendGoogleAnalytics('serve', headers, ip, originalUrl);
|
sendGoogleAnalytics('SERVE', headers, ip, originalUrl);
|
||||||
// serve content
|
// serve content
|
||||||
lbryApi
|
lbryApi
|
||||||
.resolveUri(params.uri)
|
.resolveUri(params.uri)
|
||||||
|
@ -59,7 +59,7 @@ module.exports = (app, hostedContentPath) => {
|
||||||
// route to run a publish request on the daemon
|
// route to run a publish request on the daemon
|
||||||
app.post('/api/publish', multipartMiddleware, ({ body, files, headers, ip, originalUrl }, res) => {
|
app.post('/api/publish', multipartMiddleware, ({ body, files, headers, ip, originalUrl }, res) => {
|
||||||
// google analytics
|
// google analytics
|
||||||
sendGoogleAnalytics('publish', headers, ip, originalUrl);
|
sendGoogleAnalytics('PUBLISH', headers, ip, originalUrl);
|
||||||
// validate that a file was provided
|
// validate that a file was provided
|
||||||
const file = files.speech || files.null;
|
const file = files.speech || files.null;
|
||||||
const name = body.name || file.name.substring(0, file.name.indexOf('.'));
|
const name = body.name || file.name.substring(0, file.name.indexOf('.'));
|
||||||
|
|
|
@ -17,7 +17,7 @@ module.exports = app => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
// a catch-all route if someone visits a page that does not exist
|
// a catch-all route if someone visits a page that does not exist
|
||||||
app.use('*', ({ originalUrl, ip }, res) => {
|
app.use('*', ({ headers, originalUrl, ip }, res) => {
|
||||||
// post to stats
|
// post to stats
|
||||||
postToStats('show', originalUrl, ip, null, null, 'Error: 404');
|
postToStats('show', originalUrl, ip, null, null, 'Error: 404');
|
||||||
// send response
|
// send response
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
const logger = require('winston');
|
const logger = require('winston');
|
||||||
const { serveFile, showFile, showFileLite, getShortUrlFromClaimId } = require('../helpers/serveHelpers.js');
|
const { serveFile, showFile, showFileLite, getShortUrlFromClaimId } = require('../helpers/serveHelpers.js');
|
||||||
const { getAssetByChannel, getAssetByShortUrl, getAssetByClaimId, getAssetByName } = require('../controllers/serveController.js');
|
const { getAssetByChannel, getAssetByShortUrl, getAssetByClaimId, getAssetByName } = require('../controllers/serveController.js');
|
||||||
const { postToStats } = require('../controllers/statsController.js');
|
|
||||||
const { handleRequestError } = require('../helpers/errorHandlers.js');
|
const { handleRequestError } = require('../helpers/errorHandlers.js');
|
||||||
|
const { postToStats, sendGoogleAnalytics } = require('../controllers/statsController.js');
|
||||||
// const db = require('../models');
|
// const db = require('../models');
|
||||||
const SERVE = 'SERVE';
|
const SERVE = 'SERVE';
|
||||||
const SHOW = 'SHOW';
|
const SHOW = 'SHOW';
|
||||||
|
@ -33,7 +33,7 @@ function updateFileDb (fileInfo) {
|
||||||
// 2. upsert the file info into the file db
|
// 2. upsert the file info into the file db
|
||||||
}
|
}
|
||||||
|
|
||||||
function serveOrShowAsset (fileInfo, method, originalUrl, ip, res) {
|
function serveOrShowAsset (fileInfo, method, headers, originalUrl, ip, res) {
|
||||||
// add file extension to the file info
|
// add file extension to the file info
|
||||||
fileInfo['fileExt'] = fileInfo.fileName.substring(fileInfo.fileName.lastIndexOf('.'));
|
fileInfo['fileExt'] = fileInfo.fileName.substring(fileInfo.fileName.lastIndexOf('.'));
|
||||||
// test logging
|
// test logging
|
||||||
|
@ -42,6 +42,7 @@ function serveOrShowAsset (fileInfo, method, originalUrl, ip, res) {
|
||||||
switch (method) {
|
switch (method) {
|
||||||
case SERVE:
|
case SERVE:
|
||||||
serveFile(fileInfo, res);
|
serveFile(fileInfo, res);
|
||||||
|
sendGoogleAnalytics(method, headers, ip, originalUrl);
|
||||||
postToStats('serve', originalUrl, ip, fileInfo.name, fileInfo.claimId, 'success');
|
postToStats('serve', originalUrl, ip, fileInfo.name, fileInfo.claimId, 'success');
|
||||||
return fileInfo;
|
return fileInfo;
|
||||||
case SHOWLITE:
|
case SHOWLITE:
|
||||||
|
@ -67,7 +68,7 @@ function serveOrShowAsset (fileInfo, method, originalUrl, ip, res) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function isValidClaimId (claimId) {
|
function isValidClaimId (claimId) {
|
||||||
return ((claimId.length === 40) && !/[^A-Za-z0-9,-]/g.test(claimId));
|
return ((claimId.length === 40) && !/[^A-Za-z0-9]/g.test(claimId));
|
||||||
}
|
}
|
||||||
|
|
||||||
function isValidShortUrl (claimId) {
|
function isValidShortUrl (claimId) {
|
||||||
|
@ -107,21 +108,13 @@ module.exports = (app) => {
|
||||||
method = SHOW;
|
method = SHOW;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
/* start: temporary patch for backwards compatability spee.ch/name/claim_id */
|
||||||
temporary patch for backwards compatability spee.ch/name/claim_id...
|
|
||||||
/doitlive/d
|
|
||||||
/doitlive/d.jpg
|
|
||||||
/doitlive/asldfj...sdjf
|
|
||||||
/doitlive/asldfj...sdjf.jpg
|
|
||||||
/not a valid short url or claim/is a valid short url or claim
|
|
||||||
*/
|
|
||||||
if (isValidShortUrlOrClaimId(name) && !isValidShortUrlOrClaimId(identifier)) {
|
if (isValidShortUrlOrClaimId(name) && !isValidShortUrlOrClaimId(identifier)) {
|
||||||
let tempName = name;
|
let tempName = name;
|
||||||
name = identifier;
|
name = identifier;
|
||||||
identifier = tempName;
|
identifier = tempName;
|
||||||
}
|
}
|
||||||
/*
|
/* end */
|
||||||
*/
|
|
||||||
logger.debug('claim name =', name);
|
logger.debug('claim name =', name);
|
||||||
logger.debug('identifiery =', identifier);
|
logger.debug('identifiery =', identifier);
|
||||||
logger.debug('method =', method);
|
logger.debug('method =', method);
|
||||||
|
@ -139,7 +132,7 @@ module.exports = (app) => {
|
||||||
logger.debug('short url =', shortUrl);
|
logger.debug('short url =', shortUrl);
|
||||||
claimType = SHORTURL;
|
claimType = SHORTURL;
|
||||||
} else {
|
} else {
|
||||||
logger.error('that url does not compute');
|
logger.error('The URL provided could not be parsed');
|
||||||
res.send('that url is invalid');
|
res.send('that url is invalid');
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
@ -150,7 +143,7 @@ module.exports = (app) => {
|
||||||
if (!fileInfo) {
|
if (!fileInfo) {
|
||||||
res.status(200).render('noClaims');
|
res.status(200).render('noClaims');
|
||||||
} else {
|
} else {
|
||||||
return serveOrShowAsset(fileInfo, method, originalUrl, ip, res);
|
return serveOrShowAsset(fileInfo, method, headers, originalUrl, ip, res);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
// 3. update the database
|
// 3. update the database
|
||||||
|
@ -190,7 +183,7 @@ module.exports = (app) => {
|
||||||
if (!fileInfo) {
|
if (!fileInfo) {
|
||||||
res.status(200).render('noClaims');
|
res.status(200).render('noClaims');
|
||||||
} else {
|
} else {
|
||||||
return serveOrShowAsset(fileInfo, method, originalUrl, ip, res);
|
return serveOrShowAsset(fileInfo, method, headers, originalUrl, ip, res);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
// 3. update the database
|
// 3. update the database
|
||||||
|
|
Loading…
Reference in a new issue