From acbf94a6861455aed274ef194a6aab5e12951492 Mon Sep 17 00:00:00 2001 From: YULIUS KURNIAWAN KRISTIANTO Date: Mon, 22 Jan 2018 18:05:47 +0700 Subject: [PATCH 1/8] Update errorHandlers.js deamon is incorrect billbitt. the correct words is daemon --- helpers/errorHandlers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helpers/errorHandlers.js b/helpers/errorHandlers.js index 9a5b24d1..e170a9aa 100644 --- a/helpers/errorHandlers.js +++ b/helpers/errorHandlers.js @@ -7,7 +7,7 @@ module.exports = { if (error.code === 'ECONNREFUSED') { status = 503; message = 'Connection refused. The daemon may not be running.'; - // check for errors from the deamon + // check for errors from the daemon } else if (error.response) { status = error.response.status || 500; if (error.response.data) { -- 2.45.2 From ecf968ecc2160aab8c13e8a406e8c410e0f3fd11 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Mon, 22 Jan 2018 15:23:13 -0800 Subject: [PATCH 2/8] updated release banner to maintenance banner --- views/partials/maintenanceBanner.handlebars | 4 ++++ views/partials/releaseBanner.handlebars | 3 --- 2 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 views/partials/maintenanceBanner.handlebars delete mode 100644 views/partials/releaseBanner.handlebars diff --git a/views/partials/maintenanceBanner.handlebars b/views/partials/maintenanceBanner.handlebars new file mode 100644 index 00000000..2adb7536 --- /dev/null +++ b/views/partials/maintenanceBanner.handlebars @@ -0,0 +1,4 @@ +
+

Hi there! Spee.ch is currently undergoing maintenance, and as a result publishing may be disabled. Please visit our discord channel for updates.

+
diff --git a/views/partials/releaseBanner.handlebars b/views/partials/releaseBanner.handlebars deleted file mode 100644 index e23a60a5..00000000 --- a/views/partials/releaseBanner.handlebars +++ /dev/null @@ -1,3 +0,0 @@ -
- Hi there! You've stumbled upon the new version of Spee<h, launching soon! Send us your feedback in our discord -
\ No newline at end of file -- 2.45.2 From 118ff2deb32ee12d68f13b2cce6c690915b9da8d Mon Sep 17 00:00:00 2001 From: bill bittner Date: Mon, 22 Jan 2018 16:14:05 -0800 Subject: [PATCH 3/8] added GA timing event for publish --- .../statsHelpers.js | 69 +++++++------------ routes/api-routes.js | 7 +- 2 files changed, 30 insertions(+), 46 deletions(-) rename controllers/statsController.js => helpers/statsHelpers.js (58%) diff --git a/controllers/statsController.js b/helpers/statsHelpers.js similarity index 58% rename from controllers/statsController.js rename to helpers/statsHelpers.js index 68215767..d6d559a0 100644 --- a/controllers/statsController.js +++ b/helpers/statsHelpers.js @@ -1,7 +1,7 @@ const logger = require('winston'); const ua = require('universal-analytics'); const config = require('../config/speechConfig.js'); -const db = require('../models'); +const db = require('../models/index'); const googleApiKey = config.analytics.googleId; module.exports = { @@ -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,28 @@ 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 time = endTime - startTime; + let params; + switch (action) { + case 'PUBLISH': + params = { + userTimingCategory : 'lbrynet', + userTimingVariableName: 'publish', + userTimingTime : time, + 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); + } }); }, }; diff --git a/routes/api-routes.js b/routes/api-routes.js index bd9ac3e1..976e183d 100644 --- a/routes/api-routes.js +++ b/routes/api-routes.js @@ -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,10 @@ 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 startTime = Date.now(); let name, fileName, filePath, fileType, nsfw, license, title, description, thumbnail, channelName, channelPassword; // validate the body and files of the request try { @@ -168,6 +170,9 @@ module.exports = (app) => { lbryTx: result, }, }); + const endTime = Date.now(); + console.log('publish end time', endTime); + sendGoogleAnalyticsTiming('PUBLISH', headers, ip, originalUrl, startTime, endTime); }) .catch(error => { errorHandlers.handleApiError(originalUrl, ip, error, res); -- 2.45.2 From a468485d3353471474516dd1b615c474cbada99c Mon Sep 17 00:00:00 2001 From: bill bittner Date: Mon, 22 Jan 2018 20:09:28 -0800 Subject: [PATCH 4/8] updated logging --- helpers/statsHelpers.js | 5 +++-- routes/api-routes.js | 9 +++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/helpers/statsHelpers.js b/helpers/statsHelpers.js index d6d559a0..b4e486b3 100644 --- a/helpers/statsHelpers.js +++ b/helpers/statsHelpers.js @@ -63,14 +63,14 @@ module.exports = { sendGoogleAnalyticsTiming (action, headers, ip, originalUrl, startTime, endTime) { const visitorId = ip.replace(/\./g, '-'); const visitor = ua(googleApiKey, visitorId, { strictCidFormat: false, https: true }); - const time = endTime - startTime; + const publishDurration = endTime - startTime; let params; switch (action) { case 'PUBLISH': params = { userTimingCategory : 'lbrynet', userTimingVariableName: 'publish', - userTimingTime : time, + userTimingTime : publishDurration, uip : ip, ua : headers['user-agent'], ul : headers['accept-language'], @@ -82,6 +82,7 @@ module.exports = { if (err) { logger.error('Google Analytics Event Error >>', err); } + logger.info(`publish completed successfully in ${publishDurration}ms`); }); }, }; diff --git a/routes/api-routes.js b/routes/api-routes.js index 976e183d..c22f19cb 100644 --- a/routes/api-routes.js +++ b/routes/api-routes.js @@ -128,7 +128,8 @@ module.exports = (app) => { 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 startTime = Date.now(); + 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 { @@ -170,9 +171,9 @@ module.exports = (app) => { lbryTx: result, }, }); - const endTime = Date.now(); - console.log('publish end time', endTime); - sendGoogleAnalyticsTiming('PUBLISH', headers, ip, originalUrl, startTime, endTime); + 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); -- 2.45.2 From 5b2a10b741689fb11da2dccd37e95bcedd9ccafb Mon Sep 17 00:00:00 2001 From: bill bittner Date: Mon, 22 Jan 2018 21:48:32 -0800 Subject: [PATCH 5/8] cleaned up import statement --- helpers/statsHelpers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helpers/statsHelpers.js b/helpers/statsHelpers.js index b4e486b3..9dc41645 100644 --- a/helpers/statsHelpers.js +++ b/helpers/statsHelpers.js @@ -1,7 +1,7 @@ const logger = require('winston'); const ua = require('universal-analytics'); const config = require('../config/speechConfig.js'); -const db = require('../models/index'); +const db = require('../models'); const googleApiKey = config.analytics.googleId; module.exports = { -- 2.45.2 From 3aefd433030b48a6b9756c4b64838ab07226da42 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Mon, 22 Jan 2018 22:00:04 -0800 Subject: [PATCH 6/8] fixed broken import require link --- routes/serve-routes.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/serve-routes.js b/routes/serve-routes.js index f2610f0b..3baf1f6e 100644 --- a/routes/serve-routes.js +++ b/routes/serve-routes.js @@ -2,7 +2,7 @@ const logger = require('winston'); const { getClaimId, getChannelViewData, getLocalFileRecord } = require('../controllers/serveController.js'); const serveHelpers = require('../helpers/serveHelpers.js'); const { handleRequestError } = require('../helpers/errorHandlers.js'); -const { postToStats } = require('../controllers/statsController.js'); +const { postToStats } = require('../helpers/statsHelpers.js'); const db = require('../models'); const lbryUri = require('../helpers/lbryUri.js'); -- 2.45.2 From bac7930983945c67f14ae4383cb4c6d9e3144f6a Mon Sep 17 00:00:00 2001 From: bill bittner Date: Mon, 22 Jan 2018 22:05:16 -0800 Subject: [PATCH 7/8] added back needed stats Controller --- controllers/statsController.js | 41 ++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 controllers/statsController.js diff --git a/controllers/statsController.js b/controllers/statsController.js new file mode 100644 index 00000000..75ddfb9c --- /dev/null +++ b/controllers/statsController.js @@ -0,0 +1,41 @@ +const logger = require('winston'); +const db = require('../models'); + +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); + }); + }); + }, +}; -- 2.45.2 From 97e4c9234fa1285abf34117d0a0a0f39bcf424e1 Mon Sep 17 00:00:00 2001 From: Maxime St-Pierre Date: Thu, 18 Jan 2018 14:12:05 -0500 Subject: [PATCH 8/8] Remove the hardcoded lbry API address --- config/speechConfig.js.example | 4 ++++ helpers/lbryApi.js | 15 +++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/config/speechConfig.js.example b/config/speechConfig.js.example index 904db832..5af319dd 100644 --- a/config/speechConfig.js.example +++ b/config/speechConfig.js.example @@ -35,4 +35,8 @@ module.exports = { testChannel : '@testpublishchannel', // a channel to make test publishes in testChannelPassword: 'password', // password for the test channel }, + api: { + apiUri: 'localhost', + apiPort: '5279', + }, }; diff --git a/helpers/lbryApi.js b/helpers/lbryApi.js index 0474ca36..a8fd1b35 100644 --- a/helpers/lbryApi.js +++ b/helpers/lbryApi.js @@ -1,5 +1,8 @@ const axios = require('axios'); const logger = require('winston'); +const config = require('../config/speechConfig.js'); +const { apiUri, apiPort } = config.api; +const lbryApiUrl = 'http://' + apiUri + ':' + apiPort; function handleLbrynetResponse ({ data }, resolve, reject) { logger.debug('lbry api data:', data); @@ -22,7 +25,7 @@ module.exports = { logger.debug(`lbryApi >> Publishing claim to "${publishParams.name}"`); return new Promise((resolve, reject) => { axios - .post('http://localhost:5279/lbryapi', { + .post(lbryApiUrl, { method: 'publish', params: publishParams, }) @@ -38,7 +41,7 @@ module.exports = { logger.debug(`lbryApi >> Getting Claim for "${uri}"`); return new Promise((resolve, reject) => { axios - .post('http://localhost:5279/lbryapi', { + .post(lbryApiUrl, { method: 'get', params: { uri, timeout: 20 }, }) @@ -54,7 +57,7 @@ module.exports = { logger.debug(`lbryApi >> Getting claim_list for "${claimName}"`); return new Promise((resolve, reject) => { axios - .post('http://localhost:5279/lbryapi', { + .post(lbryApiUrl, { method: 'claim_list', params: { name: claimName }, }) @@ -71,7 +74,7 @@ module.exports = { // console.log('resolving uri', uri); return new Promise((resolve, reject) => { axios - .post('http://localhost:5279/lbryapi', { + .post(lbryApiUrl, { method: 'resolve', params: { uri }, }) @@ -91,7 +94,7 @@ module.exports = { logger.debug('lbryApi >> Retrieving the download directory path from lbry daemon...'); return new Promise((resolve, reject) => { axios - .post('http://localhost:5279/lbryapi', { + .post(lbryApiUrl, { method: 'settings_get', }) .then(({ data }) => { @@ -110,7 +113,7 @@ module.exports = { createChannel (name) { return new Promise((resolve, reject) => { axios - .post('http://localhost:5279/lbryapi', { + .post(lbryApiUrl, { method: 'channel_new', params: { channel_name: name, -- 2.45.2