mirror of
https://github.com/overleaf/overleaf.git
synced 2024-10-24 21:12:38 -04:00
5e773ce950
Migrate from `settings-sharelatex` to `@overleaf/settings` GitOrigin-RevId: 9a298ba26382180c1351683c5fddc9004418c1e6
85 lines
2.2 KiB
JavaScript
85 lines
2.2 KiB
JavaScript
const request = require('request')
|
|
const Settings = require('@overleaf/settings')
|
|
const OError = require('@overleaf/o-error')
|
|
|
|
const TIMEOUT = 10 * 1000
|
|
|
|
module.exports = {
|
|
getUserDictionary(userId, callback) {
|
|
const url = `${Settings.apis.spelling.url}/user/${userId}`
|
|
request.get({ url: url, timeout: TIMEOUT }, (error, response) => {
|
|
if (error) {
|
|
return callback(
|
|
OError.tag(error, 'error getting user dictionary', { error, userId })
|
|
)
|
|
}
|
|
|
|
if (response.statusCode < 200 || response.statusCode >= 300) {
|
|
return callback(
|
|
new OError(
|
|
'Non-success code from spelling API when getting user dictionary',
|
|
{ userId, statusCode: response.statusCode }
|
|
)
|
|
)
|
|
}
|
|
|
|
callback(null, JSON.parse(response.body))
|
|
})
|
|
},
|
|
|
|
deleteWordFromUserDictionary(userId, word, callback) {
|
|
const url = `${Settings.apis.spelling.url}/user/${userId}/unlearn`
|
|
request.post(
|
|
{
|
|
url: url,
|
|
json: {
|
|
word,
|
|
},
|
|
timeout: TIMEOUT,
|
|
},
|
|
(error, response) => {
|
|
if (error) {
|
|
return callback(
|
|
OError.tag(error, 'error deleting word from user dictionary', {
|
|
userId,
|
|
word,
|
|
})
|
|
)
|
|
}
|
|
|
|
if (response.statusCode < 200 || response.statusCode >= 300) {
|
|
return callback(
|
|
new OError(
|
|
'Non-success code from spelling API when removing word from user dictionary',
|
|
{ userId, word, statusCode: response.statusCode }
|
|
)
|
|
)
|
|
}
|
|
|
|
callback()
|
|
}
|
|
)
|
|
},
|
|
|
|
deleteUserDictionary(userId, callback) {
|
|
const url = `${Settings.apis.spelling.url}/user/${userId}`
|
|
request.delete({ url: url, timeout: TIMEOUT }, (error, response) => {
|
|
if (error) {
|
|
return callback(
|
|
OError.tag(error, 'error deleting user dictionary', { userId })
|
|
)
|
|
}
|
|
|
|
if (response.statusCode < 200 || response.statusCode >= 300) {
|
|
return callback(
|
|
new OError(
|
|
'Non-success code from spelling API when removing user dictionary',
|
|
{ userId, statusCode: response.statusCode }
|
|
)
|
|
)
|
|
}
|
|
|
|
callback()
|
|
})
|
|
},
|
|
}
|