Skip to content

Commit

Permalink
Deliver easter egg and premium challenge from /dist folder
Browse files Browse the repository at this point in the history
  • Loading branch information
bkimminich committed Sep 19, 2018
1 parent 7820b6c commit 3f0ca5f
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 236 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ node_modules/
npm-debug.log.*
package-lock.json

# Frontend
frontend/src/assets/private/threejs-demo.html

# App
dist/
order_*.pdf
Expand Down
1 change: 1 addition & 0 deletions config/bodgeit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ application:
twitterUrl: null
facebookUrl: null
planetName: Bodgiton VI
planetOverlayMap: 'http://www.userlogos.org/files/logos/inductiveload/Google%20Code.png'
recyclePage:
topProductImage: undefined.png
bottomProductImage: thingie1.jpg
Expand Down
189 changes: 0 additions & 189 deletions frontend/src/assets/private/threejs-demo.template.html

This file was deleted.

35 changes: 25 additions & 10 deletions lib/startup/populateIndexTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,37 @@ const utils = require('../utils')

const populateIndexTemplate = () => {
if (config.get('application.logo')) {
let logo = config.get('application.logo')
if (utils.startsWith(logo, 'http')) {
const logoPath = logo
logo = decodeURIComponent(logo.substring(logo.lastIndexOf('/') + 1))
utils.downloadToFile(logoPath, 'frontend/dist/frontend/assets/public/images/' + logo)
}
customizeLogo()
}
if (config.get('application.favicon')) {
customizeFavicon()
}
if (config.get('application.theme')) {
replaceTheme()
customizeTheme()
}
if (config.get('application.cookieConsent')) {
replaceCookieConsent()
customizeCookieConsentBanner()
}
}

const customizeLogo = () => {
retrieveCustomFile('application.logo', 'frontend/dist/frontend/assets/public/images')
}

const customizeFavicon = () => {
retrieveCustomFile('application.favicon', 'frontend/dist/frontend/assets/public')
}

const retrieveCustomFile = (sourceProperty, destinationFolder) => {
let file = config.get(sourceProperty)
if (utils.startsWith(file, 'http')) {
const filePath = file
file = decodeURIComponent(file.substring(file.lastIndexOf('/') + 1))
utils.downloadToFile(filePath, destinationFolder + '/' + file)
}
}

const replaceTheme = () => {
const customizeTheme = () => {
const bodyClass = '"mat-app-background ' + config.get('application.theme') + '-theme"'
replace({
regex: /"mat-app-background .*-theme"/,
Expand All @@ -30,7 +45,7 @@ const replaceTheme = () => {
})
}

const replaceCookieConsent = () => { // FIXME Cookie banner still missing in new Angular frontend
const customizeCookieConsentBanner = () => { // FIXME Cookie banner still missing in new Angular frontend
const popupProperty = '"popup": { "background": "' + config.get('application.cookieConsent.backgroundColor') + '", "text": "' + config.get('application.cookieConsent.textColor') + '" }'
replace({
regex: /"popup": { "background": ".*", "text": ".*" }/,
Expand Down
36 changes: 17 additions & 19 deletions lib/startup/populateThreeJsTemplate.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
const fs = require('fs-extra')
const config = require('config')
const replace = require('replace')
const utils = require('../utils')

const populateThreeJsTemplate = () => {
fs.copy('frontend/src/assets/private/threejs-demo.template.html', 'frontend/src/assets/private/threejs-demo.html', { overwrite: true }, () => {
if (config.get('application.planetOverlayMap')) {
let overlay = config.get('application.planetOverlayMap')
if (utils.startsWith(overlay, 'http')) {
const overlayPath = overlay
overlay = decodeURIComponent(overlay.substring(overlay.lastIndexOf('/') + 1))
utils.downloadToFile(overlayPath, 'frontend/src/assets/private/' + overlay)
replaceImagePath(overlay)
}
if (config.get('application.planetOverlayMap')) {
let overlay = config.get('application.planetOverlayMap')
if (utils.startsWith(overlay, 'http')) {
const overlayPath = overlay
overlay = decodeURIComponent(overlay.substring(overlay.lastIndexOf('/') + 1))
utils.downloadToFile(overlayPath, 'frontend/dist/frontend/assets/private/' + overlay)
}
if (config.get('application.planetName')) {
replaceThreeJsTitleTag()
}
})
replaceImagePath(overlay)
}
if (config.get('application.planetName')) {
replaceThreeJsTitleTag()
}
}

const replaceImagePath = (overlay) => {
const textureDeclaration = 'orangeTexture = THREE.ImageUtils.loadTexture("/assets/private/' + overlay + '");'
replace({
regex: 'orangemap2k.jpg',
replacement: overlay,
paths: ['frontend/src/assets/private/threejs-demo.html'],
regex: /orangeTexture = .*;/,
replacement: textureDeclaration,
paths: ['frontend/dist/frontend/assets/private/threejs-demo.html'],
recursive: false,
silent: true
})
Expand All @@ -33,9 +31,9 @@ const replaceImagePath = (overlay) => {
const replaceThreeJsTitleTag = () => {
const threeJsTitleTag = '<title>Welcome to Planet ' + config.get('application.planetName') + '</title>'
replace({
regex: '<title>Welcome to Planet Orangeuze</title>',
regex: /<title>.*<\/title>/,
replacement: threeJsTitleTag,
paths: ['frontend/src/assets/private/threejs-demo.html'],
paths: ['frontend/dist/frontend/assets/private/threejs-demo.html'],
recursive: false,
silent: true
})
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@
"request": "~2.88.0",
"sanitize-html": "1.4.2",
"sequelize": "^4.35.1",
"serve-favicon": "~2.5",
"serve-index": "~1.9",
"socket.io": "~2.1",
"sqlite3": "^4.0.2",
Expand Down
2 changes: 1 addition & 1 deletion routes/easterEgg.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ module.exports = function serveEasterEgg () {
if (utils.notSolved(challenges.easterEggLevelTwoChallenge)) {
utils.solve(challenges.easterEggLevelTwoChallenge)
}
res.sendFile(path.resolve(__dirname, '../frontend/src/assets/private/threejs-demo.html'))
res.sendFile(path.resolve(__dirname, '../frontend/dist/frontend/assets/private/threejs-demo.html'))
}
}
2 changes: 1 addition & 1 deletion routes/premiumReward.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ module.exports = function servePremiumContent () {
if (utils.notSolved(challenges.premiumPaywallChallenge)) {
utils.solve(challenges.premiumPaywallChallenge)
}
res.sendFile(path.resolve(__dirname, '../frontend/src/assets/private/under-construction.gif'))
res.sendFile(path.resolve(__dirname, '../frontend/dist/frontend/assets/private/under-construction.gif'))
}
}
12 changes: 0 additions & 12 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,6 @@ app.use((req, res, next) => {
next()
})

/* Favicon */
let icon = 'favicon_v2.ico'
if (config.get('application.favicon')) {
icon = config.get('application.favicon')
if (utils.startsWith(icon, 'http')) {
const iconPath = icon
icon = decodeURIComponent(icon.substring(icon.lastIndexOf('/') + 1))
fs.closeSync(fs.openSync('frontend/dist/frontend/assets/public/' + icon, 'w')) // touch file so it is guaranteed to exist for favicon() call
utils.downloadToFile(iconPath, 'frontend/dist/frontend/assets/public/' + icon)
}
}

/* Security Policy */
app.get('/security.txt', verify.accessControlChallenges())
app.use('/security.txt', securityTxt({
Expand Down

0 comments on commit 3f0ca5f

Please sign in to comment.