diff --git a/.gitmodules b/.gitmodules old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/license b/license old mode 100644 new mode 100755 diff --git a/modules/main.js b/modules/main.js old mode 100644 new mode 100755 diff --git a/modules/old.js b/modules/old.js old mode 100644 new mode 100755 diff --git a/modules/qmining.js b/modules/qmining.js old mode 100644 new mode 100755 diff --git a/modules/sio.js b/modules/sio.js old mode 100644 new mode 100755 diff --git a/modules/stuff.js b/modules/stuff.js old mode 100644 new mode 100755 diff --git a/package.json b/package.json old mode 100644 new mode 100755 diff --git a/public/favicon.ico b/public/favicon.ico old mode 100644 new mode 100755 diff --git a/server.js b/server.js old mode 100644 new mode 100755 diff --git a/utils/actions.js b/utils/actions.js old mode 100644 new mode 100755 index 6673476..7250c54 --- a/utils/actions.js +++ b/utils/actions.js @@ -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 +} diff --git a/utils/changedataversion.js b/utils/changedataversion.js old mode 100644 new mode 100755 diff --git a/utils/dataUpdater.js b/utils/dataUpdater.js old mode 100644 new mode 100755 diff --git a/utils/ids.js b/utils/ids.js old mode 100644 new mode 100755 diff --git a/utils/logger.js b/utils/logger.js old mode 100644 new mode 100755 diff --git a/utils/merger.js b/utils/merger.js old mode 100644 new mode 100755 index 45796dc..a306e85 --- a/utils/merger.js +++ b/utils/merger.js @@ -41,8 +41,7 @@ function Main () { console.log('JSON data added') } catch (e) { console.log(e) - console.log('Trying with old format...') - dbs.push(ReadData(utils.ReadFile(params[i])).result) + return } } PrintLN() @@ -155,98 +154,6 @@ function MergeDatabases (dbs) { return db } -/* - * Returns a question database from the given data. - * Parameter should be raw read file in string with "\n"-s - * TODO: ??? -s are not listed as errors, tho works correctly - * */ -function ReadData (data) { - const d = data.split('\n') - const r = new classes.QuestionDB((x) => true, (x, y) => console.log(x, y)) - var logs = [] - var currSubj = '' // the current subjects name - var ExpectedIdentifier = ['+', '?'] - let currQuestion = new classes.Question() - - var i = -1 - while (i < d.length) { - let currIdentifier - let skipped = 0 - do { - if (skipped >= 1) { logs.push(i + ': ' + d[i]) } - i++ - if (i >= d.length) { - if (currQuestion.IsComplete()) { r.AddQuestion(currSubj, currQuestion) } - return { - result: r, - logs: logs - } - } - currIdentifier = d[i][0] - skipped++ - } while (!ExpectedIdentifier.includes(currIdentifier) && i < d.length) - - let currData = d[i].substring(1).trim() - - if (currIdentifier === '+') { - if (currQuestion.IsComplete()) { r.AddQuestion(currSubj, currQuestion) } - currQuestion = new classes.Question() - currSubj = currData - ExpectedIdentifier = ['?'] - continue - } - - if (currIdentifier === '?') { - if (currQuestion.IsComplete()) { - r.AddQuestion(currSubj, currQuestion) - currQuestion = new classes.Question() - } - // overwriting is allowed here, bcus: - // ?????!> - currQuestion.Q = currData - ExpectedIdentifier = ['!', '?'] - continue - } - - if (currIdentifier === '!') { - // if dont have question continue - if (!currQuestion.HasQuestion()) { throw new Error('No question! (A)') } - // dont allow overwriting - // ?!!!! - if (!currQuestion.HasAnswer()) { - currData = currData.replace('A helyes válaszok: ', '') - currData = currData.replace('A helyes válasz: ', '') - - currQuestion.A = currData - } - ExpectedIdentifier = ['?', '>', '+'] - continue - } - - if (currIdentifier === '>') { - // if dont have question or answer continue - if (!currQuestion.HasQuestion()) { throw new Error('No question! (I)') } - if (!currQuestion.HasAnswer()) { throw new Error('No asnwer! (I)') } - // dont allow overwriting - // ?!>>> - if (!currQuestion.HasImage()) { - try { - currQuestion.I = JSON.parse(currData) - } catch (e) { - currQuestion.I = currData.split(',') - } - } - ExpectedIdentifier = ['?', '+'] - continue - } - } - - return { - result: r, - logs: logs - } -} - function RemoveDuplicates (dataObj) { for (var i = 0; i < dataObj.length; i++) { RemoveDuplFromSubject(dataObj.Subjects[i]) } return dataObj diff --git a/utils/motd.js b/utils/motd.js old mode 100644 new mode 100755 diff --git a/utils/utils.js b/utils/utils.js old mode 100644 new mode 100755 diff --git a/views/main/main.ejs b/views/main/main.ejs old mode 100644 new mode 100755 diff --git a/views/qmining/alldata.ejs b/views/qmining/alldata.ejs old mode 100644 new mode 100755 diff --git a/views/qmining/allqr.ejs b/views/qmining/allqr.ejs old mode 100644 new mode 100755 diff --git a/views/qmining/aludni.ejs b/views/qmining/aludni.ejs old mode 100644 new mode 100755 diff --git a/views/qmining/b.ejs b/views/qmining/b.ejs old mode 100644 new mode 100755 diff --git a/views/qmining/main.ejs b/views/qmining/main.ejs old mode 100644 new mode 100755 diff --git a/views/qmining/man.ejs b/views/qmining/man.ejs old mode 100644 new mode 100755 diff --git a/views/qmining/qa.ejs b/views/qmining/qa.ejs old mode 100644 new mode 100755 diff --git a/views/qmining/uploaded.ejs b/views/qmining/uploaded.ejs old mode 100644 new mode 100755 diff --git a/views/shared/404.ejs b/views/shared/404.ejs old mode 100644 new mode 100755 diff --git a/views/sio/uload.ejs b/views/sio/uload.ejs old mode 100644 new mode 100755 diff --git a/views/stuff/audio.ejs b/views/stuff/audio.ejs old mode 100644 new mode 100755 diff --git a/views/stuff/folders.ejs b/views/stuff/folders.ejs old mode 100644 new mode 100755 diff --git a/views/stuff/nofile.ejs b/views/stuff/nofile.ejs old mode 100644 new mode 100755 diff --git a/views/stuff/video.ejs b/views/stuff/video.ejs old mode 100644 new mode 100755