From 794162b5502f35015992c45aeb292aac1f3947ee Mon Sep 17 00:00:00 2001 From: Sean Metzgar Date: Thu, 19 Nov 2020 15:36:45 -0500 Subject: [PATCH 1/5] =?UTF-8?q?=E2=9C=A8=20Adds=20device=20details=20to=20?= =?UTF-8?q?Response=20models=20-=20=E2=9E=95=20Adds=20`device-detector-js`?= =?UTF-8?q?=20npm=20package=20-=20=E2=9E=96=20Removes=20`isbot`=20npm=20pa?= =?UTF-8?q?ckage=20=20=20-=20`isbot`=20functionality=20replaced=20by=20`de?= =?UTF-8?q?vice-detector-js`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- middleware/restrictAccess.js | 8 +++++--- models/response.js | 18 ++++++++++++++++++ package-lock.json | 12 ++++++------ package.json | 16 +++++++++++----- 4 files changed, 40 insertions(+), 14 deletions(-) diff --git a/middleware/restrictAccess.js b/middleware/restrictAccess.js index 2e6a837..a6d4616 100644 --- a/middleware/restrictAccess.js +++ b/middleware/restrictAccess.js @@ -1,9 +1,11 @@ -const isbot = require('isbot'); +const BotDetector = require('device-detector-js/dist/parsers/bot'); module.exports = async (req, _, next) => { - const userAgent = req.get('user-agent'); + let userAgent = req.get('user-agent'); + let detector = new BotDetector(); + let bot = detector.parse(userAgent); - if (isbot(userAgent)) { + if (bot) { return next({ status: 403, errors: [ diff --git a/models/response.js b/models/response.js index 66c3791..2793bbb 100644 --- a/models/response.js +++ b/models/response.js @@ -5,6 +5,7 @@ const ip6addr = require('ip6addr'); const hashIds = require('../helpers/hashIds'); var iso31661 = require('iso-3166'); var iso31662 = require('iso-3166/2'); +const DeviceDetector = require('device-detector-js'); module.exports = (sequelize, DataTypes) => { class Response extends Model {} @@ -132,6 +133,23 @@ module.exports = (sequelize, DataTypes) => { ); }, }, + device: { + type: DataTypes.VIRTUAL, + get() { + let rVal = null; + let device = new DeviceDetector(); + if (this.userAgent !== null && typeof this.userAgent === 'string') { + let decodedDevice = device.parse(this.userAgent); + rVal = typeof decodedDevice === 'object' ? decodedDevice : null; + } + return rVal; + }, + set(value) { + throw new Error( + `Cannot explicitly set the \`device\` property. Value: \`${value}\` rejected.`, + ); + }, + }, }, { sequelize, diff --git a/package-lock.json b/package-lock.json index c353fc8..9f6bf02 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "backtalk-api", - "version": "1.0.0-alpha.1", + "version": "1.0.0-alpha.2", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -2500,6 +2500,11 @@ "integrity": "sha512-TLz+x/vEXm/Y7P7wn1EJFNLxYpUD4TgMosxY6fAVJUnJMbupHBOncxyWUG9OpTaH9EBD7uFI5LfEgmMOc54DsA==", "dev": true }, + "device-detector-js": { + "version": "2.2.5", + "resolved": "https://registry.npmjs.org/device-detector-js/-/device-detector-js-2.2.5.tgz", + "integrity": "sha512-TW9TJRjzCv0TD5hKiVcgqxq5egT14NVwPg7jBv84h4qjpc4weVtEuYEtMfgtXAsV+NUU9oKSme2Gvm4nSoNn+A==" + }, "diff-sequences": { "version": "25.2.6", "resolved": "https://registry.npmjs.org/diff-sequences/-/diff-sequences-25.2.6.tgz", @@ -4229,11 +4234,6 @@ "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=", "dev": true }, - "isbot": { - "version": "3.0.11", - "resolved": "https://registry.npmjs.org/isbot/-/isbot-3.0.11.tgz", - "integrity": "sha512-NnuUS6/wYpGi+uSIpu5lgB/nXKWMgRBNYhDKq1+semrG3eAObiLplBSApXY3ezUjd743QEZOUCGQ0ijdE6uiFg==" - }, "isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", diff --git a/package.json b/package.json index df14a43..fed82c6 100644 --- a/package.json +++ b/package.json @@ -30,16 +30,22 @@ "docker-down:combined": "docker-compose down && cd client/ && yarn docker-down" }, "keywords": [], - "author": "ClickPopMedia", + "author": { + "name": "ClickPop", + "url": "https://clickpopmedia.com/" + }, "contributors": [ { - "name": "Graham Vasquez" + "name": "Graham Vasquez", + "url": "https://github.com/gv14982" }, { - "name": "Sean Metzgar" + "name": "Sean Metzgar", + "url": "https://github.com/seanmetzgar" }, { - "name": "Chris Vasquez" + "name": "Chris Vasquez", + "url": "https://github.com/cvasquez" } ], "license": "ISC", @@ -65,6 +71,7 @@ "cookie-parser": "^1.4.5", "cors": "^2.8.5", "cross-env": "^7.0.2", + "device-detector-js": "^2.2.5", "dotenv": "^8.2.0", "express": "^4.17.1", "express-validator": "^6.6.1", @@ -72,7 +79,6 @@ "geoip-lite": "^1.4.2", "hashids": "^2.2.1", "ip6addr": "^0.2.3", - "isbot": "3.0.11", "iso-3166": "3.1.0", "jsonwebtoken": "^8.5.1", "morgan": "^1.10.0", From 9411ec6bd003bf28b27489a741f4dca74c1bea1e Mon Sep 17 00:00:00 2001 From: Sean Metzgar Date: Thu, 19 Nov 2020 23:13:37 -0500 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=9A=91=20Fix=20issue=20with=20bot=20d?= =?UTF-8?q?etection=20breaking=20dev=20server?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- middleware/restrictAccess.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/middleware/restrictAccess.js b/middleware/restrictAccess.js index a6d4616..ba7393b 100644 --- a/middleware/restrictAccess.js +++ b/middleware/restrictAccess.js @@ -1,9 +1,9 @@ -const BotDetector = require('device-detector-js/dist/parsers/bot'); +const DeviceDetector = require('device-detector-js'); module.exports = async (req, _, next) => { let userAgent = req.get('user-agent'); - let detector = new BotDetector(); - let bot = detector.parse(userAgent); + let detector = new DeviceDetector(); + let bot = detector.botParser.parse(userAgent); if (bot) { return next({ From d4997c44ef7726c906ae9c5472a11d2fb8ce0a70 Mon Sep 17 00:00:00 2001 From: Sean Metzgar Date: Thu, 19 Nov 2020 23:28:01 -0500 Subject: [PATCH 3/5] Fix bug --- package.json | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/package.json b/package.json index fed82c6..9f97098 100644 --- a/package.json +++ b/package.json @@ -30,10 +30,7 @@ "docker-down:combined": "docker-compose down && cd client/ && yarn docker-down" }, "keywords": [], - "author": { - "name": "ClickPop", - "url": "https://clickpopmedia.com/" - }, + "author": "ClickPop", "contributors": [ { "name": "Graham Vasquez", From 76d9207898ce6f4db7598c498ab23b2b7c9f9537 Mon Sep 17 00:00:00 2001 From: Graham Vasquez Date: Thu, 19 Nov 2020 23:37:51 -0500 Subject: [PATCH 4/5] =?UTF-8?q?=F0=9F=9A=91=20Adjusted=20deploy=20scripts?= =?UTF-8?q?=20to=20avoid=20a=20possible=20issue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/develop.sh | 5 +++-- scripts/production.sh | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/scripts/develop.sh b/scripts/develop.sh index aed0acb..e0453a4 100644 --- a/scripts/develop.sh +++ b/scripts/develop.sh @@ -1,4 +1,5 @@ #!/bin/bash cd backtalk-develop -docker-compose up -d --build --force-recreate -# rm .env \ No newline at end of file +docker-compose down +docker-compose up -d --build +rm .env \ No newline at end of file diff --git a/scripts/production.sh b/scripts/production.sh index 7d84825..dfde076 100644 --- a/scripts/production.sh +++ b/scripts/production.sh @@ -1,4 +1,5 @@ #!/bin/bash cd backtalk-api -docker-compose up -d --build --force-recreate +docker-compose down +docker-compose up -d --build rm .env \ No newline at end of file From a4109c27036e3b7ab43f835f3b7b0d083b41b473 Mon Sep 17 00:00:00 2001 From: Sean Metzgar Date: Fri, 20 Nov 2020 01:13:06 -0500 Subject: [PATCH 5/5] =?UTF-8?q?=F0=9F=94=96=20Version=201.0.0-alpha.3=20-?= =?UTF-8?q?=20Adds=20device=20details=20to=20Response=20model?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9f97098..1d87e96 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "backtalk-api", - "version": "1.0.0-alpha.2", + "version": "1.0.0-alpha.3", "description": "API Service for backtalk.io", "main": "./server/server.js", "scripts": {