mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Handling old data
This commit is contained in:
parent
bb23853043
commit
2f6f39c294
34 changed files with 41 additions and 94 deletions
40
utils/actions.js
Normal file → Executable file
40
utils/actions.js
Normal file → Executable file
|
@ -54,6 +54,9 @@ function ProcessIncomingRequest (data) {
|
|||
try {
|
||||
var d = JSON.parse(data)
|
||||
var allQuestions = []
|
||||
|
||||
d = ConvertToNewFormat(d)
|
||||
|
||||
for (let i = 0; i < d.allData.length; i++) {
|
||||
allQuestions.push(new classes.Question(d.allData[i].Q, d.allData[i].A, d.allData[i].data))
|
||||
}
|
||||
|
@ -152,3 +155,40 @@ function ProcessQA () {
|
|||
|
||||
return r
|
||||
}
|
||||
|
||||
function ConvertToNewFormat (d) {
|
||||
if (d.allData.length < 0) {
|
||||
return d
|
||||
}
|
||||
|
||||
try {
|
||||
if (!d.allData[0].data) {
|
||||
logger.Log('\tConverting old data to new...')
|
||||
d.allData = d.allData.map((x) => {
|
||||
if (x.I) {
|
||||
x.data = {
|
||||
type: 'image',
|
||||
images: JSON.parse(x.I)
|
||||
}
|
||||
delete x.I
|
||||
}
|
||||
return x
|
||||
})
|
||||
d.data = d.data.map((x) => {
|
||||
if (x.I) {
|
||||
x.data = {
|
||||
type: 'image',
|
||||
images: JSON.parse(x.I)
|
||||
}
|
||||
delete x.I
|
||||
}
|
||||
return x
|
||||
})
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
logger.Log('Couldnt convert old data to new!', logger.GetColor('redbg'))
|
||||
}
|
||||
|
||||
return d
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue