46 lines
1.1 KiB
JavaScript
46 lines
1.1 KiB
JavaScript
require('dotenv').config();
|
|
const debug = require('debug')('soundbirder:api');
|
|
const debugLocale = require('debug')('soundbirder:locale');
|
|
const debugResponses = require('debug')('soundbirder:api:responses');
|
|
const quizzController = require('./quizz');
|
|
|
|
const QUIZZ_SIZE = process.env.QUIZZ_SIZE ? process.env.QUIZZ_SIZE : 5;
|
|
|
|
function check(req, res) {
|
|
}
|
|
|
|
function quizz(req, res) {
|
|
debug('Generating quizz');
|
|
const { lat, lng } = req.body;
|
|
const locale = req.i18n.locale;
|
|
debugLocale("Locale:", locale);
|
|
quizzController.generateQuizz({ lat, lng }, locale, QUIZZ_SIZE)
|
|
.then(({ species, correct, audio }) => {
|
|
req.session.correct = correct;
|
|
res.json({ species, audio });
|
|
debug("Quizz sent");
|
|
})
|
|
.catch(error => {
|
|
debug("Faced error while generating quizz");
|
|
res.json({ error });
|
|
throw error;
|
|
});
|
|
}
|
|
|
|
|
|
function getHome(req, res) {
|
|
res.render('api', {
|
|
title: "SoundBirder api",
|
|
version: 0
|
|
});
|
|
}
|
|
|
|
const game = {
|
|
check,
|
|
quizz
|
|
}
|
|
|
|
module.exports = {
|
|
getHome,
|
|
game
|
|
} |