forked from juice-shop/juice-shop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrestoreProgress.js
26 lines (25 loc) · 983 Bytes
/
restoreProgress.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const Hashids = require('hashids')
const hashids = new Hashids('this is my salt', 60, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890')
const challenges = require('../data/datacache').challenges
const utils = require('../lib/utils')
module.exports = function restoreProgress () {
return ({ params }, res) => {
const continueCode = params.continueCode
const ids = hashids.decode(continueCode)
if (utils.notSolved(challenges.continueCodeChallenge) && ids.indexOf(999) > -1) {
utils.solve(challenges.continueCodeChallenge)
res.end()
} else if (ids.length > 0) {
for (const name in challenges) {
if (challenges.hasOwnProperty(name)) {
if (ids.includes(challenges[ name ].id)) {
utils.solve(challenges[ name ], true)
}
}
}
res.json({ data: ids.length + ' solved challenges have been restored.' })
} else {
res.status(404).send('Invalid continue code.')
}
}
}