2022-12-20 07:11:25 -05:00
|
|
|
import logger from '@overleaf/logger'
|
|
|
|
import metrics from '@overleaf/metrics'
|
|
|
|
import OError from '@overleaf/o-error'
|
|
|
|
import * as SpellingAPIManager from './SpellingAPIManager.js'
|
2019-07-03 08:41:01 -04:00
|
|
|
|
2019-07-11 06:29:00 -04:00
|
|
|
function extractCheckRequestData(req) {
|
2022-12-20 07:11:25 -05:00
|
|
|
const token = req.params?.user_id
|
|
|
|
const wordCount = req.body?.words?.length
|
2019-07-11 06:29:00 -04:00
|
|
|
return { token, wordCount }
|
|
|
|
}
|
|
|
|
|
2022-12-20 07:11:25 -05:00
|
|
|
export function check(req, res) {
|
|
|
|
metrics.inc('spelling-check', 0.1)
|
|
|
|
const { token, wordCount } = extractCheckRequestData(req)
|
|
|
|
logger.debug({ token, wordCount }, 'running check')
|
|
|
|
SpellingAPIManager.runRequest(token, req.body, (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)
|
|
|
|
})
|
2019-07-03 08:41:01 -04:00
|
|
|
}
|