mirror of
https://github.com/overleaf/overleaf.git
synced 2024-10-31 21:21:03 -04:00
81103c93e6
* Add support for deletion of words from user dictionary to admin-panel Co-authored-by: Jessica Lawshe <jessica.lawshe@overleaf.com> * Add confirmation modal to dictionary word deletion * Improve dictionary view with some helpful text * Add MockSpellingApi * Handle errors more cleanly in SpellingHandler GitOrigin-RevId: a7d7f8bad120a15b0eaa7d77b5ee804998477ed1
94 lines
2.5 KiB
JavaScript
94 lines
2.5 KiB
JavaScript
const request = require('request')
|
|
const Settings = require('settings-sharelatex')
|
|
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(
|
|
new OError({
|
|
message: 'error getting user dictionary',
|
|
info: { error, userId }
|
|
}).withCause(error)
|
|
)
|
|
}
|
|
|
|
if (response.statusCode < 200 || response.statusCode >= 300) {
|
|
return callback(
|
|
new OError({
|
|
message:
|
|
'Non-success code from spelling API when getting user dictionary',
|
|
info: { 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(
|
|
new OError({
|
|
message: 'error deleting word from user dictionary',
|
|
info: { error, userId, word }
|
|
}).withCause(error)
|
|
)
|
|
}
|
|
|
|
if (response.statusCode < 200 || response.statusCode >= 300) {
|
|
return callback(
|
|
new OError({
|
|
message:
|
|
'Non-success code from spelling API when removing word from user dictionary',
|
|
info: { 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(
|
|
new OError({
|
|
message: 'error deleting user dictionary',
|
|
info: { userId }
|
|
}).withCause(error)
|
|
)
|
|
}
|
|
|
|
if (response.statusCode < 200 || response.statusCode >= 300) {
|
|
return callback(
|
|
new OError({
|
|
message:
|
|
'Non-success code from spelling API when removing user dictionary',
|
|
info: { userId, statusCode: response.statusCode }
|
|
})
|
|
)
|
|
}
|
|
|
|
callback()
|
|
})
|
|
}
|
|
}
|