overleaf/services/spelling/app/js/SpellingAPIController.js

32 lines
956 B
JavaScript
Raw Normal View History

2019-07-03 08:41:01 -04:00
const SpellingAPIManager = require('./SpellingAPIManager')
const logger = require('@overleaf/logger')
const metrics = require('@overleaf/metrics')
2020-06-03 05:14:44 -04:00
const OError = require('@overleaf/o-error')
2019-07-03 08:41:01 -04:00
function extractCheckRequestData(req) {
const token = req.params ? req.params.user_id : undefined
const wordCount =
req.body && req.body.words ? req.body.words.length : undefined
return { token, wordCount }
}
2019-07-03 08:41:01 -04:00
module.exports = {
check(req, res) {
2019-07-03 08:41:01 -04:00
metrics.inc('spelling-check', 0.1)
const { token, wordCount } = extractCheckRequestData(req)
logger.debug({ token, wordCount }, 'running check')
2020-08-10 12:23:15 -04:00
SpellingAPIManager.runRequest(token, req.body, function (error, result) {
2019-07-03 08:41:01 -04:00
if (error != null) {
2020-06-03 05:14:44 -04:00
logger.error(
OError.tag(error, 'error processing spelling request', {
user_id: token,
2021-07-13 07:04:47 -04:00
wordCount,
2020-06-03 05:14:44 -04:00
})
2019-07-03 08:41:01 -04:00
)
return res.sendStatus(500)
}
res.send(result)
2019-07-03 08:41:01 -04:00
})
},
}