2019-07-03 12:41:01 +00:00
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Sanity-check the conversion and remove this comment.
|
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* DS207: Consider shorter variations of null checks
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
|
|
|
const ASpell = require('./ASpell')
|
2019-07-11 10:29:00 +00:00
|
|
|
const { callbackify } = require('util')
|
2020-06-03 09:14:44 +00:00
|
|
|
const OError = require('@overleaf/o-error')
|
2019-07-03 12:41:01 +00:00
|
|
|
|
2019-07-11 10:29:00 +00:00
|
|
|
// The max number of words checked in a single request
|
|
|
|
const REQUEST_LIMIT = 10000
|
2019-07-03 12:41:01 +00:00
|
|
|
|
2022-01-06 10:41:31 +00:00
|
|
|
const SpellingAPIManager = {}
|
2019-07-11 10:29:00 +00:00
|
|
|
|
|
|
|
const promises = {
|
|
|
|
async runRequest(token, request) {
|
|
|
|
if (!request.words) {
|
2020-06-03 09:14:44 +00:00
|
|
|
throw new OError('malformed JSON')
|
2019-07-11 10:29:00 +00:00
|
|
|
}
|
|
|
|
const lang = request.language || 'en'
|
|
|
|
|
|
|
|
// only the first 10K words are checked
|
|
|
|
const wordSlice = request.words.slice(0, REQUEST_LIMIT)
|
|
|
|
|
2019-07-16 06:51:15 +00:00
|
|
|
const misspellings = await ASpell.promises.checkWords(lang, wordSlice)
|
2022-01-06 10:41:31 +00:00
|
|
|
return { misspellings }
|
2021-07-13 11:04:47 +00:00
|
|
|
},
|
2019-07-11 10:29:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SpellingAPIManager.runRequest = callbackify(promises.runRequest)
|
|
|
|
SpellingAPIManager.promises = promises
|
|
|
|
|
|
|
|
module.exports = SpellingAPIManager
|