Book first implementation + bug fixed reindex

This commit is contained in:
Luis Fernando Molina committed 2021-01-03 16:32:20 +01:00
1 parent cbbea6e583
commit 545e82a816
8 files changed
+239 -10

No files matched your search

+57
View File
@@ -464,6 +464,59 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
}
break
}
case 'Save-Book-Schema': {
getBody(processRequest)
async function processRequest(body) {
try {
let docsSchema = JSON.parse(body)
let project = requestParameters[3]
let filePath = global.env.PATH_TO_PROJECTS + '/' + project + '/Schemas/Docs-Books'
const fs = require('fs')
fs.rmdir(filePath, { recursive: true }, onDirDeleted)
function onDirDeleted(err) {
if (err && err.code === 'EBUSY') {
throw ('Can not delete the folder ' + filePath + ' because a file in it is open by some other program.')
}
try {
fs.mkdirSync(filePath)
} catch (err) {
if (err.code !== 'EEXIST') {
throw (err)
}
}
for (let i = 0; i < docsSchema.length; i++) {
let schemaDocument = docsSchema[i]
let fileContent = JSON.stringify(schemaDocument, undefined, 4)
let fileName = schemaDocument.type.toLowerCase()
for (let j = 0; j < 10; j++) {
fileName = fileName.replace(' ', '-')
}
fileName = fileName + '.json'
fs.writeFileSync(filePath + '/' + fileName, fileContent)
}
respondWithContent(JSON.stringify(global.DEFAULT_OK_RESPONSE), httpResponse)
}
} catch (err) {
console.log('[ERROR] httpInterface -> Docs -> Save-Book-Schema -> Method call produced an error.')
console.log('[ERROR] httpInterface -> Docs -> Save-Book-Schema -> err.stack = ' + err.stack)
console.log('[ERROR] httpInterface -> Docs -> Save-Book-Schema -> Params Received = ' + body)
let error = {
result: 'Fail Because',
message: err.message,
stack: err.stack
}
respondWithContent(JSON.stringify(error), httpResponse)
}
}
break
}
}
break
}
@@ -1092,6 +1145,10 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
folder = 'Docs-Topics'
break
}
case 'DocsBooksSchema': {
folder = 'Docs-Books'
break
}
}
let schemaArray = []