Track publish time #329
4 changed files with 35 additions and 48 deletions
|
@ -38,7 +38,7 @@ module.exports = {
|
|||
logger.error('Sequelize error >>', error);
|
||||
});
|
||||
},
|
||||
sendGoogleAnalytics (action, headers, ip, originalUrl) {
|
||||
sendGoogleAnalyticsEvent (action, headers, ip, originalUrl) {
|
||||
const visitorId = ip.replace(/\./g, '-');
|
||||
const visitor = ua(googleApiKey, visitorId, { strictCidFormat: false, https: true });
|
||||
let params;
|
||||
|
@ -52,15 +52,6 @@ module.exports = {
|
|||
ul : headers['accept-language'],
|
||||
};
|
||||
break;
|
||||
case 'PUBLISH':
|
||||
params = {
|
||||
ec : 'publish',
|
||||
ea : originalUrl,
|
||||
uip: ip,
|
||||
ua : headers['user-agent'],
|
||||
ul : headers['accept-language'],
|
||||
};
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
visitor.event(params, (err) => {
|
||||
|
@ -69,40 +60,29 @@ module.exports = {
|
|||
}
|
||||
});
|
||||
},
|
||||
getTrendingClaims (startDate) {
|
||||
logger.debug('retrieving trending');
|
||||
return new Promise((resolve, reject) => {
|
||||
// get the raw requests data
|
||||
db.getTrendingFiles(startDate)
|
||||
.then(fileArray => {
|
||||
let claimsPromiseArray = [];
|
||||
if (fileArray) {
|
||||
fileArray.forEach(file => {
|
||||
claimsPromiseArray.push(db.Claim.resolveClaim(file.name, file.claimId));
|
||||
});
|
||||
return Promise.all(claimsPromiseArray);
|
||||
}
|
||||
})
|
||||
.then(claimsArray => {
|
||||
resolve(claimsArray);
|
||||
})
|
||||
.catch(error => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
},
|
||||
getRecentClaims () {
|
||||
logger.debug('retrieving most recent claims');
|
||||
return new Promise((resolve, reject) => {
|
||||
// get the raw requests data
|
||||
db.File.getRecentClaims()
|
||||
.then(results => {
|
||||
resolve(results);
|
||||
})
|
||||
.catch(error => {
|
||||
logger.error('sequelize error', error);
|
||||
reject(error);
|
||||
});
|
||||
sendGoogleAnalyticsTiming (action, headers, ip, originalUrl, startTime, endTime) {
|
||||
const visitorId = ip.replace(/\./g, '-');
|
||||
const visitor = ua(googleApiKey, visitorId, { strictCidFormat: false, https: true });
|
||||
const publishDurration = endTime - startTime;
|
||||
let params;
|
||||
switch (action) {
|
||||
case 'PUBLISH':
|
||||
params = {
|
||||
userTimingCategory : 'lbrynet',
|
||||
userTimingVariableName: 'publish',
|
||||
userTimingTime : publishDurration,
|
||||
uip : ip,
|
||||
ua : headers['user-agent'],
|
||||
ul : headers['accept-language'],
|
||||
};
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
visitor.timing(params, (err) => {
|
||||
if (err) {
|
||||
logger.error('Google Analytics Event Error >>', err);
|
||||
}
|
||||
logger.info(`publish completed successfully in ${publishDurration}ms`);
|
||||
});
|
||||
},
|
||||
};
|
|
@ -7,6 +7,7 @@ const { checkClaimNameAvailability, checkChannelAvailability, publish } = requir
|
|||
const { getClaimList, resolveUri, getClaim } = require('../helpers/lbryApi.js');
|
||||
const { createPublishParams, parsePublishApiRequestBody, parsePublishApiRequestFiles, parsePublishApiChannel } = require('../helpers/publishHelpers.js');
|
||||
const errorHandlers = require('../helpers/errorHandlers.js');
|
||||
const { sendGoogleAnalyticsTiming } = require('../helpers/statsHelpers.js');
|
||||
const { authenticateIfNoUserToken } = require('../auth/authentication.js');
|
||||
|
||||
function addGetResultsToFileData (fileInfo, getResult) {
|
||||
|
@ -124,9 +125,11 @@ module.exports = (app) => {
|
|||
});
|
||||
});
|
||||
// route to run a publish request on the daemon
|
||||
app.post('/api/claim-publish', multipartMiddleware, ({ body, files, ip, originalUrl, user }, res) => {
|
||||
app.post('/api/claim-publish', multipartMiddleware, ({ body, files, headers, ip, originalUrl, user }, res) => {
|
||||
logger.debug('api/claim-publish body:', body);
|
||||
logger.debug('api/claim-publish files:', files);
|
||||
const publishStartTime = Date.now();
|
||||
logger.debug('publish request started @', publishStartTime);
|
||||
let name, fileName, filePath, fileType, nsfw, license, title, description, thumbnail, channelName, channelPassword;
|
||||
// validate the body and files of the request
|
||||
try {
|
||||
|
@ -168,6 +171,9 @@ module.exports = (app) => {
|
|||
lbryTx: result,
|
||||
},
|
||||
});
|
||||
const publishEndTime = Date.now();
|
||||
logger.debug('publish request completed @', publishEndTime);
|
||||
sendGoogleAnalyticsTiming('PUBLISH', headers, ip, originalUrl, publishStartTime, publishEndTime);
|
||||
})
|
||||
.catch(error => {
|
||||
errorHandlers.handleApiError(originalUrl, ip, error, res);
|
||||
|
|
4
views/partials/maintenanceBanner.handlebars
Normal file
4
views/partials/maintenanceBanner.handlebars
Normal file
|
@ -0,0 +1,4 @@
|
|||
<div id="new-release-banner" class="row row--short row--wide">
|
||||
<p style="font-size: medium"> Hi there! Spee.ch is currently undergoing maintenance, and as a result publishing may be disabled. Please visit our <a style="
|
||||
color:white; text-decoration: underline" target="_blank" href="https://discord.gg/YjYbwhS">discord channel</a> for updates.</p>
|
||||
</div>
|
|
@ -1,3 +0,0 @@
|
|||
<div id="new-release-banner" class="row row--short row--wide">
|
||||
Hi there! You've stumbled upon the new version of Spee<h, launching soon! Send us your feedback in <a style="color:white; text-decoration: underline" target="_blank" href="https://discord.gg/YjYbwhS">our discord</a>
|
||||
</div>
|
Loading…
Reference in a new issue