mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Added clear questions api
This commit is contained in:
parent
a8d4a35eb8
commit
f651536354
2 changed files with 83 additions and 3 deletions
|
@ -1,4 +1,5 @@
|
|||
import fs from 'fs'
|
||||
import { fork } from 'child_process'
|
||||
|
||||
import logger from '../../../utils/logger'
|
||||
import utils from '../../../utils/utils'
|
||||
|
@ -600,7 +601,7 @@ function setup(data: SubmoduleData): any {
|
|||
|
||||
if (!req.body.questions) {
|
||||
res.json({
|
||||
message: `ask something! { question:'' ,subject:'', location:'' }`,
|
||||
message: `ask something! { questions:'' ,subject:'', location:'' }`,
|
||||
result: [],
|
||||
recievedData: JSON.stringify(req.body),
|
||||
success: false,
|
||||
|
@ -1006,6 +1007,57 @@ function setup(data: SubmoduleData): any {
|
|||
})
|
||||
})
|
||||
|
||||
let questionCleaner = null
|
||||
app.get('/clearQuestions', (req: Request, res) => {
|
||||
// TODO: dont allow multiple instances
|
||||
// TODO: get status of it cleaning
|
||||
logger.LogReq(req)
|
||||
const user: User = req.session.user
|
||||
const status: any = req.query.status
|
||||
|
||||
if (status) {
|
||||
if (!questionCleaner) {
|
||||
res.json({
|
||||
msg: 'question cleaner not running',
|
||||
success: false,
|
||||
})
|
||||
return
|
||||
}
|
||||
questionCleaner.once('message', function (response) {
|
||||
res.json({
|
||||
msg: response,
|
||||
success: true,
|
||||
})
|
||||
})
|
||||
|
||||
questionCleaner.send({ data: 'asd' })
|
||||
return
|
||||
}
|
||||
|
||||
if (questionCleaner) {
|
||||
res.json({
|
||||
msg: 'question cleaner already running',
|
||||
success: false,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
questionCleaner = fork(
|
||||
`${process.cwd()}/src/standaloneUtils/rmDuplicates.js`,
|
||||
['-s', `${process.cwd()}/${questionDbs[0].path}`]
|
||||
)
|
||||
questionCleaner.on('exit', function (code) {
|
||||
console.log('EXIT', code)
|
||||
questionCleaner = null
|
||||
})
|
||||
|
||||
res.json({
|
||||
user: user,
|
||||
success: true,
|
||||
msg: 'OK',
|
||||
})
|
||||
})
|
||||
|
||||
return {
|
||||
dailyAction: () => {
|
||||
backupData(questionDbs)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue