forked from juice-shop/juice-shop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontinueCode.ts
52 lines (47 loc) · 2.03 KB
/
continueCode.ts
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
* Copyright (c) 2014-2023 Bjoern Kimminich & the OWASP Juice Shop contributors.
* SPDX-License-Identifier: MIT
*/
import Hashids = require('hashids/cjs')
import { type Request, type Response } from 'express'
import { ChallengeModel } from '../models/challenge'
const sequelize = require('sequelize')
const challenges = require('../data/datacache').challenges
const Op = sequelize.Op
module.exports.continueCode = function continueCode () {
const hashids = new Hashids('this is my salt', 60, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890')
return (req: Request, res: Response) => {
const ids = []
for (const name in challenges) {
if (Object.prototype.hasOwnProperty.call(challenges, name)) {
if (challenges[name].solved) ids.push(challenges[name].id)
}
}
const continueCode = ids.length > 0 ? hashids.encode(ids) : undefined
res.json({ continueCode })
}
}
module.exports.continueCodeFindIt = function continueCodeFindIt () {
const hashids = new Hashids('this is the salt for findIt challenges', 60, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890')
return async (req: Request, res: Response) => {
const ids = []
const challenges = await ChallengeModel.findAll({ where: { codingChallengeStatus: { [Op.gte]: 1 } } })
for (const challenge of challenges) {
ids.push(challenge.id)
}
const continueCode = ids.length > 0 ? hashids.encode(ids) : undefined
res.json({ continueCode })
}
}
module.exports.continueCodeFixIt = function continueCodeFixIt () {
const hashids = new Hashids('yet another salt for the fixIt challenges', 60, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890')
return async (req: Request, res: Response) => {
const ids = []
const challenges = await ChallengeModel.findAll({ where: { codingChallengeStatus: { [Op.gte]: 2 } } })
for (const challenge of challenges) {
ids.push(challenge.id)
}
const continueCode = ids.length > 0 ? hashids.encode(ids) : undefined
res.json({ continueCode })
}
}