mirror of
https://github.com/overleaf/overleaf.git
synced 2024-09-23 02:55:13 -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
59 lines
1.4 KiB
JavaScript
59 lines
1.4 KiB
JavaScript
const express = require('express')
|
|
const app = express()
|
|
|
|
const MockSpellingApi = {
|
|
words: {},
|
|
|
|
run() {
|
|
app.get('/user/:userId', (req, res) => {
|
|
const { userId } = req.params
|
|
const words = this.words[userId] || []
|
|
res.json(words)
|
|
})
|
|
|
|
app.delete('/user/:userId', (req, res) => {
|
|
const { userId } = req.params
|
|
this.words.delete(userId)
|
|
res.sendStatus(200)
|
|
})
|
|
|
|
app.post('/user/:userId/learn', (req, res) => {
|
|
const word = req.body.word
|
|
const { userId } = req.params
|
|
if (word) {
|
|
this.words[userId] = this.words[userId] || []
|
|
if (!this.words[userId].includes(word)) {
|
|
this.words[userId].push(word)
|
|
}
|
|
}
|
|
res.sendStatus(200)
|
|
})
|
|
|
|
app.post('/user/:userId/unlearn', (req, res) => {
|
|
const word = req.body.word
|
|
const { userId } = req.params
|
|
if (word && this.words[userId]) {
|
|
const wordIndex = this.words[userId].indexOf(word)
|
|
if (wordIndex !== -1) {
|
|
this.words[userId].splice(wordIndex, 1)
|
|
}
|
|
}
|
|
res.sendStatus(200)
|
|
})
|
|
|
|
app
|
|
.listen(3005, error => {
|
|
if (error) {
|
|
throw error
|
|
}
|
|
})
|
|
.on('error', error => {
|
|
console.error('error starting MockSpellingApi:', error.message)
|
|
process.exit(1)
|
|
})
|
|
}
|
|
}
|
|
|
|
MockSpellingApi.run()
|
|
|
|
module.exports = MockSpellingApi
|