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