overleaf/services/spelling/app/js/SpellingAPIController.js
Jakob Ackermann 2465a32451 Merge pull request #6234 from overleaf/jpa-web-owns-spelling-preferences
[misc] move ownership of spellingPreferences collection to web

GitOrigin-RevId: f2584a1119a578c3df15371c6798923a4f2d15ae
2022-01-07 09:03:11 +00:00

31 lines
955 B
JavaScript

const SpellingAPIManager = require('./SpellingAPIManager')
const logger = require('@overleaf/logger')
const metrics = require('@overleaf/metrics')
const OError = require('@overleaf/o-error')
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 }
}
module.exports = {
check(req, res) {
metrics.inc('spelling-check', 0.1)
const { token, wordCount } = extractCheckRequestData(req)
logger.info({ token, wordCount }, 'running check')
SpellingAPIManager.runRequest(token, req.body, function (error, result) {
if (error != null) {
logger.error(
OError.tag(error, 'error processing spelling request', {
user_id: token,
wordCount,
})
)
return res.sendStatus(500)
}
res.send(result)
})
},
}