Skip to content

Commit

Permalink
Merge pull request #59 from ClickPop/release/1.0.0-alpha.3
Browse files Browse the repository at this point in the history
Release/1.0.0 alpha.3
  • Loading branch information
seanmetzgar authored Nov 20, 2020
2 parents 68392b5 + a4109c2 commit 681f041
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 18 deletions.
8 changes: 5 additions & 3 deletions middleware/restrictAccess.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const isbot = require('isbot');
const DeviceDetector = require('device-detector-js');

module.exports = async (req, _, next) => {
const userAgent = req.get('user-agent');
let userAgent = req.get('user-agent');
let detector = new DeviceDetector();
let bot = detector.botParser.parse(userAgent);

if (isbot(userAgent)) {
if (bot) {
return next({
status: 403,
errors: [
Expand Down
18 changes: 18 additions & 0 deletions models/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 9 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down Expand Up @@ -30,16 +30,19 @@
"docker-down:combined": "docker-compose down && cd client/ && yarn docker-down"
},
"keywords": [],
"author": "ClickPopMedia",
"author": "ClickPop",
"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",
Expand All @@ -65,14 +68,14 @@
"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",
"faker": "^5.1.0",
"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",
Expand Down
5 changes: 3 additions & 2 deletions scripts/develop.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
cd backtalk-develop
docker-compose up -d --build --force-recreate
# rm .env
docker-compose down
docker-compose up -d --build
rm .env
3 changes: 2 additions & 1 deletion scripts/production.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 681f041

Please sign in to comment.