From 703c075de3c233499aed2c8be42e8c08df88cd7f Mon Sep 17 00:00:00 2001 From: bill bittner Date: Tue, 12 Dec 2017 15:20:51 -0800 Subject: [PATCH 01/10] added middleware log of headers --- speech.js | 2 +- testpage.html | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/speech.js b/speech.js index 7e7a4e5f..c2717258 100644 --- a/speech.js +++ b/speech.js @@ -33,7 +33,7 @@ app.use(bodyParser.json()); // 'body parser' for parsing application/json app.use(bodyParser.urlencoded({ extended: true })); // 'body parser' for parsing application/x-www-form-urlencoded app.use((req, res, next) => { // custom logging middleware to log all incoming http requests logger.verbose(`Request on ${req.originalUrl} from ${req.ip}`); - logger.debug('req.body:', req.body); + logger.debug('req.headers:', req.headers); next(); }); diff --git a/testpage.html b/testpage.html index 65dcdb74..ca43ee36 100644 --- a/testpage.html +++ b/testpage.html @@ -5,13 +5,13 @@ Test Page - - - - - - - - + + + + + + + + - \ No newline at end of file + -- 2.45.2 From ac14231f66a7293dc278cdbea43aaeab7f3ec0a3 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Wed, 13 Dec 2017 14:55:26 -0800 Subject: [PATCH 02/10] added narrow image check for show to serve flip --- routes/serve-routes.js | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/routes/serve-routes.js b/routes/serve-routes.js index cab39ed5..b32ba70a 100644 --- a/routes/serve-routes.js +++ b/routes/serve-routes.js @@ -44,8 +44,14 @@ function showChannelPageToClient (channelName, channelClaimId, originalUrl, ip, }); } -function clientAcceptsHtml (headers) { - return headers['accept'] && headers['accept'].split(',').includes('text/html'); +function clientAcceptsHtml ({accept}) { + return accept && accept.match(/text\/html/); +} + +function clientWantsAsset ({accept}) { + const imageIsWanted = accept && accept.match(/image\/.*/) && !accept.match(/text\/html/) && !accept.match(/text\/\*/); // checks if an image is accepted, but not a video + const videoIsWanted = false; + return imageIsWanted || videoIsWanted; } function determineResponseType (isServeRequest, headers) { @@ -57,7 +63,8 @@ function determineResponseType (isServeRequest, headers) { } } else { responseType = SHOW; - if (!clientAcceptsHtml(headers)) { // this is in case someone embeds a show url + if (clientWantsAsset(headers)) { // this is in case someone embeds a show url + logger.debug('Show request actually want\'s an asset!'); responseType = SERVE; } } @@ -68,8 +75,8 @@ function showAssetToClient (claimId, name, res) { return Promise .all([db.Claim.resolveClaim(name, claimId), db.Claim.getShortClaimIdFromLongClaimId(claimId, name)]) .then(([claimInfo, shortClaimId]) => { - logger.debug('claimInfo:', claimInfo); - logger.debug('shortClaimId:', shortClaimId); + // logger.debug('claimInfo:', claimInfo); + // logger.debug('shortClaimId:', shortClaimId); return serveHelpers.showFile(claimInfo, shortClaimId, res); }) .catch(error => { @@ -81,8 +88,8 @@ function showLiteAssetToClient (claimId, name, res) { return Promise .all([db.Claim.resolveClaim(name, claimId), db.Claim.getShortClaimIdFromLongClaimId(claimId, name)]) .then(([claimInfo, shortClaimId]) => { - logger.debug('claimInfo:', claimInfo); - logger.debug('shortClaimId:', shortClaimId); + // logger.debug('claimInfo:', claimInfo); + // logger.debug('shortClaimId:', shortClaimId); return serveHelpers.showFileLite(claimInfo, shortClaimId, res); }) .catch(error => { @@ -93,7 +100,7 @@ function showLiteAssetToClient (claimId, name, res) { function serveAssetToClient (claimId, name, res) { return getLocalFileRecord(claimId, name) .then(fileInfo => { - logger.debug('fileInfo:', fileInfo); + // logger.debug('fileInfo:', fileInfo); if (fileInfo === NO_FILE) { return res.status(307).redirect(`/api/claim-get/${name}/${claimId}`); } -- 2.45.2 From 7fd4a6cb8f3df2e4f5f51ba2a46005ec02336eea Mon Sep 17 00:00:00 2001 From: bill bittner Date: Wed, 13 Dec 2017 15:09:01 -0800 Subject: [PATCH 03/10] added check for whether video is requested --- routes/serve-routes.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/routes/serve-routes.js b/routes/serve-routes.js index b32ba70a..fea8b8ef 100644 --- a/routes/serve-routes.js +++ b/routes/serve-routes.js @@ -48,9 +48,9 @@ function clientAcceptsHtml ({accept}) { return accept && accept.match(/text\/html/); } -function clientWantsAsset ({accept}) { +function clientWantsAsset ({accept, range}) { const imageIsWanted = accept && accept.match(/image\/.*/) && !accept.match(/text\/html/) && !accept.match(/text\/\*/); // checks if an image is accepted, but not a video - const videoIsWanted = false; + const videoIsWanted = accept && range; return imageIsWanted || videoIsWanted; } -- 2.45.2 From f7f2d1072b25f5dabd6ede4e613cbcdec1a8cd2c Mon Sep 17 00:00:00 2001 From: bill bittner Date: Wed, 13 Dec 2017 15:32:58 -0800 Subject: [PATCH 04/10] cards work on twitter for images, but not video) --- models/claim.js | 12 ++++++------ routes/serve-routes.js | 6 ++++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/models/claim.js b/models/claim.js index 5a6a6819..2fb62387 100644 --- a/models/claim.js +++ b/models/claim.js @@ -8,7 +8,7 @@ function determineFileExtensionFromContentType (contentType) { switch (contentType) { case 'image/jpeg': case 'image/jpg': - return 'jpg'; + return 'jpeg'; case 'image/png': return 'png'; case 'image/gif': @@ -16,8 +16,8 @@ function determineFileExtensionFromContentType (contentType) { case 'video/mp4': return 'mp4'; default: - logger.debug('setting unknown file type as file extension jpg'); - return 'jpg'; + logger.debug('setting unknown file type as file extension jpeg'); + return 'jpeg'; } }; @@ -25,7 +25,7 @@ function determineContentTypeFromFileExtension (fileExtension) { switch (fileExtension) { case 'jpeg': case 'jpg': - return 'image/jpg'; + return 'image/jpeg'; case 'png': return 'image/png'; case 'gif': @@ -33,8 +33,8 @@ function determineContentTypeFromFileExtension (fileExtension) { case 'mp4': return 'video/mp4'; default: - logger.debug('setting unknown file type as type image/jpg'); - return 'image/jpg'; + logger.debug('setting unknown file type as type image/jpeg'); + return 'image/jpeg'; } }; diff --git a/routes/serve-routes.js b/routes/serve-routes.js index fea8b8ef..cbefd64c 100644 --- a/routes/serve-routes.js +++ b/routes/serve-routes.js @@ -49,8 +49,10 @@ function clientAcceptsHtml ({accept}) { } function clientWantsAsset ({accept, range}) { - const imageIsWanted = accept && accept.match(/image\/.*/) && !accept.match(/text\/html/) && !accept.match(/text\/\*/); // checks if an image is accepted, but not a video - const videoIsWanted = accept && range; + const imageIsWanted = accept && accept.match(/image\/.*/) && !accept.match(/text\/html/) && !accept.match(/text\/\*/); + const videoIsWanted = false; // accept && range; + logger.debug('image is wanted:', imageIsWanted); + logger.debug('video is wanted:', videoIsWanted); return imageIsWanted || videoIsWanted; } -- 2.45.2 From d6d11ea80748b445d61dc919a719c617203682ab Mon Sep 17 00:00:00 2001 From: bill bittner Date: Wed, 13 Dec 2017 18:30:09 -0800 Subject: [PATCH 05/10] added check for browser request --- helpers/handlebarsHelpers.js | 32 ++++++++++++++++---------------- routes/serve-routes.js | 12 +++++++----- views/layouts/channel.handlebars | 12 ++++++------ views/layouts/main.handlebars | 12 ++++++------ 4 files changed, 35 insertions(+), 33 deletions(-) diff --git a/helpers/handlebarsHelpers.js b/helpers/handlebarsHelpers.js index d2258e03..a2118b61 100644 --- a/helpers/handlebarsHelpers.js +++ b/helpers/handlebarsHelpers.js @@ -17,27 +17,27 @@ module.exports = { return new Handlebars.SafeString(gaCode); }, addOpenGraph ({ ogTitle, contentType, ogDescription, thumbnail, showUrl, source, ogThumbnailContentType }) { - const ogTitleTag = ``; - const ogUrlTag = ``; - const ogSiteNameTag = ``; - const ogDescriptionTag = ``; - const ogImageWidthTag = ''; - const ogImageHeightTag = ''; + const ogTitleTag = ``; + const ogUrlTag = ``; + const ogSiteNameTag = ``; + const ogDescriptionTag = ``; + const ogImageWidthTag = ''; + const ogImageHeightTag = ''; const basicTags = `${ogTitleTag} ${ogUrlTag} ${ogSiteNameTag} ${ogDescriptionTag} ${ogImageWidthTag} ${ogImageHeightTag}`; - let ogImageTag = ``; - let ogImageTypeTag = ``; - let ogTypeTag = ``; + let ogImageTag = ``; + let ogImageTypeTag = ``; + let ogTypeTag = ``; if (contentType === 'video/mp4') { - const ogVideoTag = ``; - const ogVideoSecureUrlTag = ``; - const ogVideoTypeTag = ``; - ogImageTag = ``; - ogImageTypeTag = ``; - ogTypeTag = ``; + const ogVideoTag = ``; + const ogVideoSecureUrlTag = ``; + const ogVideoTypeTag = ``; + ogImageTag = ``; + ogImageTypeTag = ``; + ogTypeTag = ``; return new Handlebars.SafeString(`${basicTags} ${ogImageTag} ${ogImageTypeTag} ${ogTypeTag} ${ogVideoTag} ${ogVideoSecureUrlTag} ${ogVideoTypeTag}`); } else { if (contentType === 'image/gif') { - ogTypeTag = ``; + ogTypeTag = ``; }; return new Handlebars.SafeString(`${basicTags} ${ogImageTag} ${ogImageTypeTag} ${ogTypeTag}`); } diff --git a/routes/serve-routes.js b/routes/serve-routes.js index cbefd64c..9098d6da 100644 --- a/routes/serve-routes.js +++ b/routes/serve-routes.js @@ -48,11 +48,13 @@ function clientAcceptsHtml ({accept}) { return accept && accept.match(/text\/html/); } +function requestIsFromBrowser (headers) { + return headers['user-agent'] && headers['user-agent'].match(/Mozilla/); +}; + function clientWantsAsset ({accept, range}) { const imageIsWanted = accept && accept.match(/image\/.*/) && !accept.match(/text\/html/) && !accept.match(/text\/\*/); - const videoIsWanted = false; // accept && range; - logger.debug('image is wanted:', imageIsWanted); - logger.debug('video is wanted:', videoIsWanted); + const videoIsWanted = accept && range; return imageIsWanted || videoIsWanted; } @@ -65,8 +67,8 @@ function determineResponseType (isServeRequest, headers) { } } else { responseType = SHOW; - if (clientWantsAsset(headers)) { // this is in case someone embeds a show url - logger.debug('Show request actually want\'s an asset!'); + if (clientWantsAsset(headers) && requestIsFromBrowser(headers)) { // this is in case someone embeds a show url + logger.debug('Show request actually wants an asset!'); responseType = SERVE; } } diff --git a/views/layouts/channel.handlebars b/views/layouts/channel.handlebars index c2832136..1088d728 100644 --- a/views/layouts/channel.handlebars +++ b/views/layouts/channel.handlebars @@ -4,12 +4,12 @@ {{ placeCommonHeaderTags }} - - - - - - + + + + + + diff --git a/views/layouts/main.handlebars b/views/layouts/main.handlebars index 782143fe..276b0033 100644 --- a/views/layouts/main.handlebars +++ b/views/layouts/main.handlebars @@ -4,12 +4,12 @@ {{ placeCommonHeaderTags }} - - - - - - + + + + + + -- 2.45.2 From 60562898649ca7293e84cc9172bc5f4c2aef2e32 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Thu, 14 Dec 2017 10:07:05 -0800 Subject: [PATCH 06/10] updated logging --- 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 9098d6da..49db38a3 100644 --- a/routes/serve-routes.js +++ b/routes/serve-routes.js @@ -68,7 +68,7 @@ function determineResponseType (isServeRequest, headers) { } else { responseType = SHOW; if (clientWantsAsset(headers) && requestIsFromBrowser(headers)) { // this is in case someone embeds a show url - logger.debug('Show request actually wants an asset!'); + logger.debug('Show request came from browser and wants an image/video; changing response to serve.'); responseType = SERVE; } } -- 2.45.2 From 19a6bf93e05cf568c1986fdf3ee9252ae5618949 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Thu, 14 Dec 2017 10:43:36 -0800 Subject: [PATCH 07/10] removed headers logging --- speech.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/speech.js b/speech.js index c2717258..70f4e4c7 100644 --- a/speech.js +++ b/speech.js @@ -33,7 +33,7 @@ app.use(bodyParser.json()); // 'body parser' for parsing application/json app.use(bodyParser.urlencoded({ extended: true })); // 'body parser' for parsing application/x-www-form-urlencoded app.use((req, res, next) => { // custom logging middleware to log all incoming http requests logger.verbose(`Request on ${req.originalUrl} from ${req.ip}`); - logger.debug('req.headers:', req.headers); + // logger.debug('req.headers:', req.headers); next(); }); -- 2.45.2 From df53760aeaab2a83f536fdccef3347b7e9233416 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Thu, 14 Dec 2017 12:32:20 -0800 Subject: [PATCH 08/10] updated host to be pulled from config file --- config/speechConfig.js.example | 10 ++++++++++ helpers/errorHandlers.js | 2 +- helpers/handlebarsHelpers.js | 8 ++++---- helpers/publishHelpers.js | 14 ++++++------- helpers/serveHelpers.js | 4 +++- models/claim.js | 23 +++++++++++----------- public/assets/js/assetConstructor.js | 4 ++-- public/assets/js/createChannelFunctions.js | 4 ++-- routes/api-routes.js | 20 +++++++++---------- routes/page-routes.js | 6 ++++-- routes/serve-routes.js | 2 +- testpage.html | 12 +++++------ views/embed.handlebars | 2 +- views/partials/assetInfo.handlebars | 14 ++++++------- 14 files changed, 70 insertions(+), 55 deletions(-) diff --git a/config/speechConfig.js.example b/config/speechConfig.js.example index f485fb34..9b891b25 100644 --- a/config/speechConfig.js.example +++ b/config/speechConfig.js.example @@ -22,4 +22,14 @@ module.exports = { files: { uploadDirectory: null, // enter file path to where uploads/publishes should be stored }, + site: { + name : 'Spee.ch', + host : 'https://spee.ch', + description: 'Decentralized video and content hosting.', + }, + publishing: { + defaultTitle : 'Spee.h', + defaultThumbnail : 'https://spee.ch/assets/img/video_thumb_default.png', + defaultDescription: 'Open-source, decentralized image and video sharing.', + }, }; diff --git a/helpers/errorHandlers.js b/helpers/errorHandlers.js index 4a825399..9a5b24d1 100644 --- a/helpers/errorHandlers.js +++ b/helpers/errorHandlers.js @@ -21,7 +21,7 @@ module.exports = { } else { message = error.response; } - // check for spee.ch thrown errors + // check for thrown errors } else if (error.message) { status = 400; message = error.message; diff --git a/helpers/handlebarsHelpers.js b/helpers/handlebarsHelpers.js index a2118b61..8ae90462 100644 --- a/helpers/handlebarsHelpers.js +++ b/helpers/handlebarsHelpers.js @@ -1,13 +1,13 @@ const Handlebars = require('handlebars'); -const config = require('../config/speechConfig.js'); +const { site, analytics } = require('../config/speechConfig.js'); module.exports = { placeCommonHeaderTags () { - const headerBoilerplate = `Spee.ch`; + const headerBoilerplate = `${site.title}`; return new Handlebars.SafeString(headerBoilerplate); }, googleAnalytics () { - const googleApiKey = config.analytics.googleId; + const googleApiKey = analytics.googleId; const gaCode = `