Skip to content
Permalink
Browse files
Merge remote-tracking branch 'origin' into feature/game-category-filter
  • Loading branch information
ricardob committed Dec 2, 2019
2 parents ccd5cca + 1642dd8 commit 4d6831f7d96463c99882444ce9bed15a0b59070a
Show file tree
Hide file tree
Showing 71 changed files with 4,664 additions and 1,984 deletions.
@@ -1,4 +1,9 @@
#!/bin/sh

echo "running the 'pre-commit' script"

echo "running eslint..."
./node_modules/.bin/eslint .

echo "running tests..."
npm test
@@ -3,4 +3,7 @@ node_modules/
coverage/
*.db
screenshots/*
docs/
docs/

# ignore uploaded user images
public/images/upload_*
@@ -6,11 +6,13 @@ To install the packages needed to run this package run: `npm install`.

Run `npm run build-db` to create the database structure.

Run `npm run add-data` to fill database with game data.

## Running

To run the server, run `npm start`.

To live-reloading, run `npm run watch`.
To start live-reloading, run `npm run watch`.

## Debugging

@@ -28,4 +30,5 @@ This project is split into a few folders:
- `public/`: contains the site's front-end static pages and JavaScript.
- `utils/`: contains shared utility code.
- `views/`: contains dynamic HTML templates.
- `./`: contains code that is used directly by the Koa app.
- `tests/`: contains all tests for the project.
- `./`: contains code that is used directly by the Koa app.
18 app.js
@@ -17,7 +17,12 @@ const handlebars = new Views(
path.join(__dirname, '/views'),
{
map: { hbs: 'handlebars' },
extension: 'hbs'
extension: 'hbs',
options: {
partials: {
navbar: `${__dirname}/views/partials/navbar.hbs`
}
}
}
)
app.use(session({key: 'session_id', renew: true}, app))
@@ -33,7 +38,6 @@ app.use(serve({
base: '/public/'
}))
app.use(bodyParser())
// app.use(serve(path.join(__dirname, 'public')))
app.use(session({key: 'session_id', renew: true}, app))

// db stuff
@@ -47,12 +51,14 @@ const login = require('./controllers/login')
const home = require('./controllers/home')
const logout = require('./controllers/logout')
const game = require('./controllers/game')
const homepage = require('./controllers/homepage')
const signup = require('./controllers/signup')
const list = require('./controllers/list')
const approval = require('./controllers/approval')
const adding = require('./controllers/adding')

// routers
app.use(home.routes())
app.use(handlebars)
app.use(game.routes())
app.use(login.routes())
app.use(list.routes())
app.use(approval.routes())
@@ -61,5 +67,9 @@ app.use(game.routes())
app.use(list.routes())
app.use(approval.routes())
app.use(adding.routes())
app.use(homepage.routes())
app.use(signup.routes())
app.use(home.routes())

module.exports = app

@@ -0,0 +1,79 @@
/* eslint-disable max-statements */
/* eslint-disable max-lines-per-function */
/* eslint-disable complexity */
'use strict'

const request = require('request')
const path = require('path')
const Game = require(path.join(__dirname, '/../models/game'))
const db = require(path.join(__dirname, '/../db'))
const dbctx = new db.SqliteDbContext(path.join(__dirname, '/../app.db'))

//Automatically inserted data
request('https://api.steampowered.com/ISteamApps/GetAppList/v2/', async(error, response, body) => {
const allGames = JSON.parse(body)
let i = 1
const gameAmount = 200 //change according to how many games you want to add
for(i; i<gameAmount; i++) {
const gameid = allGames.applist.apps[i].appid //getting the appID to insert into next URL as a string
gameid.toString()
request(`https://store.steampowered.com/api/appdetails/?appids=${gameid}` , async(error, response, body) => {
//console.log(gameid)
const statusInt = 200
if (response.statusCode !== statusInt) {
//if the api doesn't load the page, skip
return
}
try {
const gameObj = JSON.parse(body)
if(gameObj[gameid].success === false) {
//checking if it found the game
return
}
if(!gameObj[gameid].data.hasOwnProperty('developers')) {
//checking if the developer property exists
return
}
if(!gameObj[gameid].data.hasOwnProperty('screenshots')) {
//if game has no screenshots, skip
return
}
const gameData = gameObj[gameid].data
if(gameData.type !== 'game') {
return
}
//Creating Game Object
let game = new Game(
gameData.name,
gameData.short_description,
gameData.about_the_game.replace(/<[^>]*>?/gm, ''),
gameData.release_date.date,
gameData.developers[0], //not every game has developers listed so it repeats the publisher
gameData.publishers[0],
1,
'yes',
gameData.header_image,
gameData.screenshots[0].path_thumbnail)
game.categories = []
let category
for(let i=0; i<gameData.genres.length; i++) {
gameData.genres[i].id = -1
gameData.genres[i].name = gameData.genres[i].description
delete gameData.genres[i].description
try{
category = await dbctx.createCategory(gameData.genres[i])
} catch(err) {
category = await dbctx.getCategory(gameData.genres[i].name)
}
game.categories.push(category)
}
game = await dbctx.createGame(game)
const pltfrm = 38
const platform = await dbctx.getPlatform(pltfrm)
await dbctx.linkGamePlatform(game, platform)
} catch(err) {
throw new Error(`Game: https://store.steampowered.com/api/appdetails/?appids=${gameid} ${err}`)
}
})
}
})
@@ -0,0 +1,207 @@
INSERT INTO `games` VALUES
(1,
'The Last of Us',
'Hope is the key to survival.',
'Set in the post-apocalyptic United States, the game tells the story of survivors Joel and Ellie as they work together to survive their westward journey across what remains of the country to find a possible cure for the modern fungal plague that has nearly decimated the entire human race.',
'04/06/2013',
'Naughty Dog',
'Sony Computer Entertainment',
1,
'yes',
'tlou.jpg',
'tlousplash.jpg');

INSERT INTO `games` VALUES
(2,
'The Legend of Zelda: Breath of the Wild',
'Step into a world of discovery, exploration and adventure.',
'No kingdom. No memories. After a 100-year slumber, Link wakes up alone in a world he no longer remembers. Now the legendary hero must explore a vast and dangerous land and regain his memories before Hyrule is lost forever. Armed only with what he can scavenge, Link sets out to find answers and the resources needed to survive.',
'03/03/2017',
'Nintendo EPD',
'Nintendo',
2,
'yes',
'botw.jpg',
'botwsplash.jpg');

INSERT INTO `games` VALUES
(3,
"Marvel's Spider-Man",
'Be Greater.',
'After eight years behind the mask, Peter Parker is a crime-fighting expert. Feel the full power of a more experienced Spider-Man with improvisational combat, dynamic acrobatics, fluid urban traversal, and environmental interactions. A rookie no longer, this is the most masterful Spider-Man you’ve ever played.',
'07/09/2018',
'Insomniac Games',
'Sony Interactive Entertainment',
2,
'yes',
'spiderman.jpg',
'spidermansplash.jpg');

INSERT INTO `games` VALUES
(4,
"Football Manager 2020",
'Your club, your way.',
'Manage your football club, your way. Every decision counts in FM20 with new features rewarding planning and progression like never before, empowering managers to develop both your club’s and your own unique managerial identity.',
'19/11/2019',
'Sports Interactive',
'SEGA',
1,
'yes',
'fm20poster.jpg',
'fm20splash.jpg');

INSERT INTO `games` VALUES
(5,
"Star Wars Jedi: Fallen Order",
'Become a Jedi.',
'The Empire seeks to eradicate all Jedi after the execution of Order 66. You, a Jedi Padawan-turned-fugitive, must fight for your survival as you explore the mysteries of a long-extinct civilization in hopes of rebuilding the Jedi Order.',
'15/11/2019',
'Respawn Entertainment',
'Electronic Arts',
2,
'yes',
'starwarsjfoposter.jpg',
'starwarsjfosplash.jpg');

INSERT INTO `games` VALUES
(6,
"Minecraft",
'Minecraft is a game about placing blocks and going on adventures.',
'Explore randomly generated worlds and build amazing things from the simplest of homes to the grandest of castles. Play in creative mode with unlimited resources or mine deep into the world in survival mode, crafting weapons and armor to fend off the dangerous mobs.',
'18/11/2011',
'Mojang',
'Mojang',
2,
'yes',
'minecraft.jpg',
'minecraftsplash.png');

INSERT INTO 'platforms' VALUES (1, 'Atari 2600');
INSERT INTO 'platforms' VALUES (2, 'Color TV-Game');
INSERT INTO 'platforms' VALUES (3, 'Magnavox Odyssey');
INSERT INTO 'platforms' VALUES (4, 'Intellivision');
INSERT INTO 'platforms' VALUES (5, 'Atari 5200');
INSERT INTO 'platforms' VALUES (6, 'ColecoVision');
INSERT INTO 'platforms' VALUES (7, 'Nintendo Entertainment System');
INSERT INTO 'platforms' VALUES (8, 'Master System');
INSERT INTO 'platforms' VALUES (9, 'TurboGrafx-16');
INSERT INTO 'platforms' VALUES (10, 'Sega Genesis');
INSERT INTO 'platforms' VALUES (11, 'Atari Lynx');
INSERT INTO 'platforms' VALUES (12, 'Game Boy');
INSERT INTO 'platforms' VALUES (13, 'SNES');
INSERT INTO 'platforms' VALUES (14, 'Sega Game Gear');
INSERT INTO 'platforms' VALUES (15, 'Philips CD-i');
INSERT INTO 'platforms' VALUES (16, 'Sega Pico');
INSERT INTO 'platforms' VALUES (17, 'Sega Saturn');
INSERT INTO 'platforms' VALUES (18, 'PlayStation');
INSERT INTO 'platforms' VALUES (19, 'Nintendo 64');
INSERT INTO 'platforms' VALUES (20, 'Dreamcast');
INSERT INTO 'platforms' VALUES (21, 'WonderSwan');
INSERT INTO 'platforms' VALUES (22, 'PlayStation 2');
INSERT INTO 'platforms' VALUES (23, 'Xbox');
INSERT INTO 'platforms' VALUES (24, 'Game Boy Advance');
INSERT INTO 'platforms' VALUES (25, 'GameCube');
INSERT INTO 'platforms' VALUES (26, 'N-Gage');
INSERT INTO 'platforms' VALUES (27, 'Nintendo DS');
INSERT INTO 'platforms' VALUES (28, 'PlayStation Portable');
INSERT INTO 'platforms' VALUES (29, 'Xbox 360');
INSERT INTO 'platforms' VALUES (30, 'Nintendo Wii');
INSERT INTO 'platforms' VALUES (31, 'PlayStation 3');
INSERT INTO 'platforms' VALUES (32, 'Nintendo 3DS ');
INSERT INTO 'platforms' VALUES (33, 'PlayStation Vita');
INSERT INTO 'platforms' VALUES (34, 'Wii U');
INSERT INTO 'platforms' VALUES (35, 'Xbox One');
INSERT INTO 'platforms' VALUES (36, 'PlayStation 4');
INSERT INTO 'platforms' VALUES (37, 'Nintendo Switch');
INSERT INTO 'platforms' VALUES (38, 'Microsoft Windows');
INSERT INTO 'platforms' VALUES (39, 'macOS');
INSERT INTO 'platforms' VALUES (40, 'iOS');
INSERT INTO 'platforms' VALUES (41, 'Google Stadia');
INSERT INTO 'platforms' VALUES (42, 'Linux');

INSERT INTO 'categories' ('name') VALUES ('Action');
INSERT INTO 'categories' ('name') VALUES ('Platformer');
INSERT INTO 'categories' ('name') VALUES ('Shooter');
INSERT INTO 'categories' ('name') VALUES ('Fighting');
INSERT INTO 'categories' ('name') VALUES ('Stealth');
INSERT INTO 'categories' ('name') VALUES ('Survival');
INSERT INTO 'categories' ('name') VALUES ('Sandbox');
INSERT INTO 'categories' ('name') VALUES ('Rhythm');
INSERT INTO 'categories' ('name') VALUES ('Horror');
INSERT INTO 'categories' ('name') VALUES ('Visual Novel');
INSERT INTO 'categories' ('name') VALUES ('RPG');
INSERT INTO 'categories' ('name') VALUES ('MMORPG');
INSERT INTO 'categories' ('name') VALUES ('Action RPG');
INSERT INTO 'categories' ('name') VALUES ('Rougelike');
INSERT INTO 'categories' ('name') VALUES ('Tower Defence');
INSERT INTO 'categories' ('name') VALUES ('Racing');
INSERT INTO 'categories' ('name') VALUES ('Puzzle');
INSERT INTO 'categories' ('name') VALUES ('Indie');
INSERT INTO 'categories' ('name') VALUES ('Adventure');
INSERT INTO 'categories' ('name') VALUES ('Sports');
INSERT INTO 'categories' ('name') VALUES ('Simulation');
INSERT INTO 'categories' ('name') VALUES ('Stratgey');
INSERT INTO 'categories' ('name') VALUES ('Open World');




INSERT INTO
`gamePlatforms`
VALUES
(1, 31),
(1, 36),

(2, 34),
(2, 37),
(3, 36),

(4, 38),
(4, 37),
(4, 39),
(4, 40),
(4, 41),

(5, 35),
(5, 36),
(5, 38),

(6, 38),
(6, 39),
(6, 29),
(6, 31),
(6, 33),
(6, 34),
(6, 35),
(6, 36),
(6, 37),
(6, 40),
(6, 42);

INSERT INTO
`gameCategories`
VALUES
(1, 1),
(1, 3),
(1, 5),
(1, 6),
(1, 9),
(2, 6),
(2, 23),
(2, 11),
(2, 19),
(3, 1),
(3, 2),
(3, 23),
(4, 20),
(4, 21),
(4, 22),
(5, 1),
(5, 19),
(6, 6),
(6, 7),
(6, 18),
(6, 19);

INSERT INTO `users` (`username`, `hash`, `isAdmin`) VALUES ('admin', '$2b$12$niVK8DnXKSyYzAIOUun2C.PZ51waVc2NU/e7DQ9cYM6zxNwUiiOCG', 'yes');
INSERT INTO `users` (`username`, `hash`, `isAdmin`) VALUES ('user', '$2b$12$niVK8DnXKSyYzAIOUun2C.PZ51waVc2NU/e7DQ9cYM6zxNwUiiOCG', 'no');
@@ -9,6 +9,8 @@ const sqlite = require('sqlite')
const { runSQLScript } = require('./utils')

sqlite.open('app.db').then(async db => {
const sqlPath = path.join(__dirname, 'build_db.sql')
await runSQLScript(db, sqlPath)
const buildSQL = path.join(__dirname, 'build_db.sql')
const dataSQL = path.join(__dirname, 'add_data.sql')
await runSQLScript(db, buildSQL)
await runSQLScript(db, dataSQL)
})

0 comments on commit 4d6831f

Please sign in to comment.