2019-07-03 08:41:01 -04:00
|
|
|
const SpellingAPIManager = require('./SpellingAPIManager')
|
2021-12-14 08:00:35 -05:00
|
|
|
const logger = require('@overleaf/logger')
|
2020-11-25 06:57:24 -05:00
|
|
|
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
|
|
|
|
2019-07-11 06:29:00 -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 = {
|
2019-07-11 06:29:00 -04:00
|
|
|
check(req, res) {
|
2019-07-03 08:41:01 -04:00
|
|
|
metrics.inc('spelling-check', 0.1)
|
2019-07-11 06:29:00 -04:00
|
|
|
const { token, wordCount } = extractCheckRequestData(req)
|
2022-05-16 08:38:18 -04:00
|
|
|
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', {
|
2019-07-11 06:29:00 -04:00
|
|
|
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)
|
|
|
|
}
|
2019-07-11 06:29:00 -04:00
|
|
|
res.send(result)
|
2019-07-03 08:41:01 -04:00
|
|
|
})
|
|
|
|
},
|
|
|
|
}
|