Merge Develop into Master
This commit is contained in:
1 parent
2d7ed1d085
commit
2bb78c50fb
4223 files changed
+1207152
-16544
No files matched your search
+547
-135
@@ -132,6 +132,25 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
|
||||
respondWithContent(JSON.stringify(serverResponse), httpResponse)
|
||||
return
|
||||
}
|
||||
case 'signData': {
|
||||
|
||||
let serverResponse = await WEB3_SERVER.signData(
|
||||
params.privateKey,
|
||||
params.data
|
||||
)
|
||||
|
||||
respondWithContent(JSON.stringify(serverResponse), httpResponse)
|
||||
return
|
||||
}
|
||||
case 'recoverAddress': {
|
||||
|
||||
let serverResponse = await WEB3_SERVER.recoverAddress(
|
||||
params.signature
|
||||
)
|
||||
|
||||
respondWithContent(JSON.stringify(serverResponse), httpResponse)
|
||||
return
|
||||
}
|
||||
default: {
|
||||
respondWithContent(JSON.stringify({ error: 'Method ' + params.method + ' is invalid.' }), httpResponse)
|
||||
}
|
||||
@@ -505,40 +524,64 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
|
||||
|
||||
for (let i = 0; i < docsSchema.length; i++) {
|
||||
let schemaDocument = docsSchema[i]
|
||||
/*
|
||||
For some type of schemas we will save the file at an extra
|
||||
folder derived from the document's type.
|
||||
*/
|
||||
let fileName = schemaDocument.type.toLowerCase()
|
||||
for (let j = 0; j < 10; j++) {
|
||||
fileName = cleanFileName(fileName)
|
||||
}
|
||||
let pageNumber = '00' + schemaDocument.pageNumber
|
||||
|
||||
let newFilepath = filePath
|
||||
switch (category) {
|
||||
case 'Topic': {
|
||||
fileName = schemaDocument.topic.toLowerCase() + '-' + pageNumber.substring(pageNumber.length - 3, pageNumber.length) + '-' + schemaDocument.type.toLowerCase()
|
||||
fileName = cleanFileName(fileName)
|
||||
newFilepath = createPrefixDirectories(filePath, schemaDocument.topic)
|
||||
break
|
||||
}
|
||||
case 'Tutorial': {
|
||||
fileName = schemaDocument.tutorial.toLowerCase() + '-' + pageNumber.substring(pageNumber.length - 3, pageNumber.length) + '-' + schemaDocument.type.toLowerCase()
|
||||
fileName = cleanFileName(fileName)
|
||||
newFilepath = createPrefixDirectories(filePath, schemaDocument.tutorial)
|
||||
break
|
||||
}
|
||||
case 'Review': {
|
||||
fileName = schemaDocument.review.toLowerCase() + '-' + pageNumber.substring(pageNumber.length - 3, pageNumber.length) + '-' + schemaDocument.type.toLowerCase()
|
||||
fileName = cleanFileName(fileName)
|
||||
newFilepath = createPrefixDirectories(filePath, schemaDocument.review)
|
||||
break
|
||||
}
|
||||
case 'Node': {
|
||||
newFilepath = createPrefixDirectories(filePath, schemaDocument.type)
|
||||
break
|
||||
}
|
||||
case 'Concept': {
|
||||
newFilepath = createPrefixDirectories(filePath, schemaDocument.type)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
function createPrefixDirectories(filePath, schemaTextToUse) {
|
||||
let firstLetter = schemaTextToUse.substring(0, 1)
|
||||
createNewDir(filePath + '/' + firstLetter)
|
||||
let extraWord = schemaTextToUse.split(' ')[0]
|
||||
createNewDir(filePath + '/' + firstLetter + '/' + extraWord)
|
||||
return filePath + '/' + firstLetter + '/' + extraWord + '/' + cleanFileName(schemaTextToUse)
|
||||
}
|
||||
|
||||
fileName = fileName + '.json'
|
||||
|
||||
if (schemaDocument.deleted === true) {
|
||||
try {
|
||||
fs.unlinkSync(filePath + '/' + fileName)
|
||||
console.log('[SUCCESS] ' + filePath + '/' + fileName + ' deleted.')
|
||||
fs.unlinkSync(newFilepath + '/' + fileName)
|
||||
console.log('[SUCCESS] ' + newFilepath + '/' + fileName + ' deleted.')
|
||||
} catch (err) {
|
||||
noErrorsDuringSaving = false
|
||||
console.log('[ERROR] httpInterface -> Docs -> Save -> ' + filePath + '/' + fileName + ' could not be deleted.')
|
||||
console.log('[ERROR] httpInterface -> Docs -> Save -> Resolve the issue that is preventing the Client to delete this file. Look at the error message below as a guide. At the UI you will need to delete this page again in order for the Client to retry next time you execute the docs.save command.')
|
||||
console.log('[ERROR] httpInterface -> Docs -> Save -> err.stack = ' + err.stack)
|
||||
console.log('[ERROR] httpInterface -> Docs -> Delete -> ' + newFilepath + '/' + fileName + ' could not be deleted.')
|
||||
console.log('[ERROR] httpInterface -> Docs -> Delete -> Resolve the issue that is preventing the Client to delete this file. Look at the error message below as a guide. At the UI you will need to delete this page again in order for the Client to retry next time you execute the docs.save command.')
|
||||
console.log('[ERROR] httpInterface -> Docs -> Delete -> err.stack = ' + err.stack)
|
||||
}
|
||||
} else {
|
||||
if (schemaDocument.updated === true || schemaDocument.created === true) {
|
||||
@@ -548,28 +591,32 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
|
||||
schemaDocument.updated = undefined
|
||||
schemaDocument.created = undefined
|
||||
let fileContent = JSON.stringify(schemaDocument, undefined, 4)
|
||||
try {
|
||||
fs.mkdirSync(filePath)
|
||||
} catch (err) {
|
||||
if (err.message.indexOf('file already exists') < 0) {
|
||||
throw (err)
|
||||
}
|
||||
}
|
||||
fs.writeFileSync(filePath + '/' + fileName, fileContent)
|
||||
createNewDir(newFilepath)
|
||||
fs.writeFileSync(newFilepath + '/' + fileName, fileContent)
|
||||
if (created === true) {
|
||||
console.log('[SUCCESS] ' + filePath + '/' + fileName + ' created.')
|
||||
console.log('[SUCCESS] ' + newFilepath + '/' + fileName + ' created.')
|
||||
} else {
|
||||
if (updated === true) {
|
||||
console.log('[SUCCESS] ' + filePath + '/' + fileName + ' updated.')
|
||||
console.log('[SUCCESS] ' + newFilepath + '/' + fileName + ' updated.')
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
noErrorsDuringSaving = false
|
||||
console.log('[ERROR] httpInterface -> Docs -> Save -> ' + filePath + '/' + fileName + ' could not be created / updated.')
|
||||
console.log('[ERROR] httpInterface -> Docs -> Save -> ' + newFilepath + '/' + fileName + ' could not be created / updated.')
|
||||
console.log('[ERROR] httpInterface -> Docs -> Save -> err.stack = ' + err.stack)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function createNewDir(path) {
|
||||
try {
|
||||
fs.mkdirSync(path)
|
||||
} catch (err) {
|
||||
if (err.message.indexOf('file already exists') < 0) {
|
||||
throw (err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return noErrorsDuringSaving
|
||||
@@ -619,37 +666,43 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
|
||||
contribute()
|
||||
|
||||
async function contribute() {
|
||||
await doGit()
|
||||
if (error !== undefined) {
|
||||
const { lookpath } = require('lookpath');
|
||||
const gitpath = await lookpath('git');
|
||||
if (gitpath === undefined) {
|
||||
console.log('[ERROR] `git` not installed.')
|
||||
} else {
|
||||
await doGit()
|
||||
if (error !== undefined) {
|
||||
|
||||
let docs = {
|
||||
project: 'Superalgos',
|
||||
category: 'Topic',
|
||||
type: 'App Error - Contribution Not Sent',
|
||||
anchor: undefined,
|
||||
placeholder: {}
|
||||
let docs = {
|
||||
project: 'Foundations',
|
||||
category: 'Topic',
|
||||
type: 'App Error - Contribution Not Sent',
|
||||
anchor: undefined,
|
||||
placeholder: {}
|
||||
}
|
||||
|
||||
respondWithDocsObject(docs, error)
|
||||
return
|
||||
}
|
||||
|
||||
respondWithDocsObject(docs, error)
|
||||
return
|
||||
}
|
||||
await doGithub()
|
||||
if (error !== undefined) {
|
||||
|
||||
await doGithub()
|
||||
if (error !== undefined) {
|
||||
let docs = {
|
||||
project: 'Foundations',
|
||||
category: 'Topic',
|
||||
type: 'App Error - Contribution Not Sent',
|
||||
anchor: undefined,
|
||||
placeholder: {}
|
||||
}
|
||||
console.log('respond with docs ')
|
||||
|
||||
let docs = {
|
||||
project: 'Superalgos',
|
||||
category: 'Topic',
|
||||
type: 'App Error - Contribution Not Sent',
|
||||
anchor: undefined,
|
||||
placeholder: {}
|
||||
respondWithDocsObject(docs, error)
|
||||
return
|
||||
}
|
||||
console.log('respond with docs ')
|
||||
|
||||
respondWithDocsObject(docs, error)
|
||||
return
|
||||
respondWithContent(JSON.stringify(global.DEFAULT_OK_RESPONSE), httpResponse)
|
||||
}
|
||||
respondWithContent(JSON.stringify(global.DEFAULT_OK_RESPONSE), httpResponse)
|
||||
}
|
||||
|
||||
async function doGit() {
|
||||
@@ -681,7 +734,7 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
|
||||
|
||||
const octokit = new Octokit({
|
||||
auth: token,
|
||||
userAgent: 'Superalgos Beta 10'
|
||||
userAgent: 'Superalgos Beta 11'
|
||||
})
|
||||
|
||||
const repo = 'Superalgos'
|
||||
@@ -720,7 +773,8 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
|
||||
console.log('[ERROR] httpInterface -> App -> Contribute -> err.stack = ' + err.stack)
|
||||
console.log('[ERROR] httpInterface -> App -> Contribute -> commitMessage = ' + commitMessage)
|
||||
console.log('[ERROR] httpInterface -> App -> Contribute -> username = ' + username)
|
||||
console.log('[ERROR] httpInterface -> App -> Contribute -> token = ' + token)
|
||||
console.log('[ERROR] httpInterface -> App -> Contribute -> token starts with = ' + token.substring(0, 10) + '...')
|
||||
console.log('[ERROR] httpInterface -> App -> Contribute -> token ends with = ' + '...' + token.substring(token.length - 10))
|
||||
console.log('[ERROR] httpInterface -> App -> Contribute -> currentBranch = ' + currentBranch)
|
||||
console.log('[ERROR] httpInterface -> App -> Contribute -> contributionsBranch = ' + contributionsBranch)
|
||||
|
||||
@@ -740,26 +794,32 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
|
||||
update()
|
||||
|
||||
async function update() {
|
||||
let result = await doGit()
|
||||
|
||||
if (result.error === undefined) {
|
||||
let customResponse = {
|
||||
result: global.CUSTOM_OK_RESPONSE.result,
|
||||
message: result.message
|
||||
}
|
||||
respondWithContent(JSON.stringify(customResponse), httpResponse)
|
||||
const { lookpath } = require('lookpath');
|
||||
const gitpath = await lookpath('git');
|
||||
if (gitpath === undefined) {
|
||||
console.log('[ERROR] `git` not installed.')
|
||||
} else {
|
||||
let result = await doGit()
|
||||
|
||||
if (result.error === undefined) {
|
||||
let customResponse = {
|
||||
result: global.CUSTOM_OK_RESPONSE.result,
|
||||
message: result.message
|
||||
}
|
||||
respondWithContent(JSON.stringify(customResponse), httpResponse)
|
||||
} else {
|
||||
|
||||
let docs = {
|
||||
project: 'Foundations',
|
||||
category: 'Topic',
|
||||
type: 'App Error - Update Failed',
|
||||
anchor: undefined,
|
||||
placeholder: {}
|
||||
}
|
||||
|
||||
respondWithDocsObject(docs, result.error)
|
||||
|
||||
let docs = {
|
||||
project: 'Superalgos',
|
||||
category: 'Topic',
|
||||
type: 'App Error - Update Failed',
|
||||
anchor: undefined,
|
||||
placeholder: {}
|
||||
}
|
||||
|
||||
respondWithDocsObject(docs, result.error)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -786,9 +846,6 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
|
||||
} catch (err) {
|
||||
console.log('[ERROR] httpInterface -> App -> Update -> Method call produced an error.')
|
||||
console.log('[ERROR] httpInterface -> App -> Update -> err.stack = ' + err.stack)
|
||||
console.log('[ERROR] httpInterface -> App -> Update -> commitMessage = ' + commitMessage)
|
||||
console.log('[ERROR] httpInterface -> App -> Update -> username = ' + username)
|
||||
console.log('[ERROR] httpInterface -> App -> Update -> token = ' + token)
|
||||
|
||||
let error = {
|
||||
result: 'Fail Because',
|
||||
@@ -808,20 +865,26 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
|
||||
checkout()
|
||||
|
||||
async function checkout() {
|
||||
await doGit()
|
||||
|
||||
if (error === undefined) {
|
||||
respondWithContent(JSON.stringify(global.DEFAULT_OK_RESPONSE), httpResponse)
|
||||
const { lookpath } = require('lookpath');
|
||||
const gitpath = await lookpath('git');
|
||||
if (gitpath === undefined) {
|
||||
console.log('[ERROR] `git` not installed.')
|
||||
} else {
|
||||
let docs = {
|
||||
project: 'Superalgos',
|
||||
category: 'Topic',
|
||||
type: 'Switching Branches - Current Branch Not Changed',
|
||||
anchor: undefined,
|
||||
placeholder: {}
|
||||
}
|
||||
await doGit()
|
||||
|
||||
respondWithDocsObject(docs, error)
|
||||
if (error === undefined) {
|
||||
respondWithContent(JSON.stringify(global.DEFAULT_OK_RESPONSE), httpResponse)
|
||||
} else {
|
||||
let docs = {
|
||||
project: 'Foundations',
|
||||
category: 'Topic',
|
||||
type: 'Switching Branches - Current Branch Not Changed',
|
||||
anchor: undefined,
|
||||
placeholder: {}
|
||||
}
|
||||
|
||||
respondWithDocsObject(docs, error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -845,9 +908,68 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
|
||||
} catch (err) {
|
||||
console.log('[ERROR] httpInterface -> App -> Update -> Method call produced an error.')
|
||||
console.log('[ERROR] httpInterface -> App -> Update -> err.stack = ' + err.stack)
|
||||
console.log('[ERROR] httpInterface -> App -> Update -> commitMessage = ' + commitMessage)
|
||||
console.log('[ERROR] httpInterface -> App -> Update -> username = ' + username)
|
||||
console.log('[ERROR] httpInterface -> App -> Update -> token = ' + token)
|
||||
|
||||
let error = {
|
||||
result: 'Fail Because',
|
||||
message: err.message,
|
||||
stack: err.stack
|
||||
}
|
||||
respondWithContent(JSON.stringify(error), httpResponse)
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
case 'Branch': {
|
||||
try {
|
||||
branch()
|
||||
|
||||
async function branch() {
|
||||
const { lookpath } = require('lookpath');
|
||||
const gitpath = await lookpath('git');
|
||||
if (gitpath === undefined) {
|
||||
console.log('[ERROR] `git` not installed.')
|
||||
} else {
|
||||
let result = await doGit()
|
||||
|
||||
if (result.error === undefined) {
|
||||
let customResponse = {
|
||||
result: global.CUSTOM_OK_RESPONSE.result,
|
||||
message: result
|
||||
}
|
||||
respondWithContent(JSON.stringify(customResponse), httpResponse)
|
||||
} else {
|
||||
let docs = {
|
||||
project: 'Foundations',
|
||||
category: 'Topic',
|
||||
type: 'App Error - Could Not Get Current Branch',
|
||||
anchor: undefined,
|
||||
placeholder: {}
|
||||
}
|
||||
|
||||
respondWithDocsObject(docs, error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function doGit() {
|
||||
const simpleGit = require('simple-git');
|
||||
const options = {
|
||||
baseDir: process.cwd(),
|
||||
binary: 'git',
|
||||
maxConcurrentProcesses: 6,
|
||||
}
|
||||
const git = simpleGit(options)
|
||||
try {
|
||||
return await git.branch()
|
||||
} catch (err) {
|
||||
console.log('[ERROR] Error reading current branch.')
|
||||
console.log(err.stack)
|
||||
}
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
console.log('[ERROR] httpInterface -> App -> Update -> Method call produced an error.')
|
||||
console.log('[ERROR] httpInterface -> App -> Update -> err.stack = ' + err.stack)
|
||||
|
||||
let error = {
|
||||
result: 'Fail Because',
|
||||
@@ -897,6 +1019,176 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
|
||||
}
|
||||
break
|
||||
|
||||
case 'Gov': {
|
||||
switch (requestParameters[2]) { // switch by command
|
||||
case 'getGithubStars': {
|
||||
getProfiles('activity', 'listStargazersForRepo')
|
||||
break
|
||||
}
|
||||
case 'getGithubWatchers': {
|
||||
getProfiles('activity', 'listWatchersForRepo')
|
||||
break
|
||||
}
|
||||
case 'getGithubForks': {
|
||||
getProfiles('repos', 'listForks')
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
function getProfiles(endpoint, method) {
|
||||
try {
|
||||
const GITHUB_API_WAITING_TIME = 250
|
||||
const repository = unescape(requestParameters[3])
|
||||
const username = unescape(requestParameters[4])
|
||||
const token = unescape(requestParameters[5])
|
||||
let error
|
||||
let githubListArray = []
|
||||
|
||||
getRepoInfo()
|
||||
|
||||
async function getRepoInfo() {
|
||||
await doGithub()
|
||||
if (error !== undefined) {
|
||||
|
||||
let docs = {
|
||||
project: 'Governance',
|
||||
category: 'Topic',
|
||||
type: 'Gov Error - Get Repository Information',
|
||||
anchor: undefined,
|
||||
placeholder: {}
|
||||
}
|
||||
|
||||
respondWithDocsObject(docs, error)
|
||||
return
|
||||
}
|
||||
|
||||
respondWithContent(JSON.stringify(githubListArray), httpResponse)
|
||||
}
|
||||
|
||||
async function doGithub() {
|
||||
|
||||
const { Octokit } = require("@octokit/rest")
|
||||
|
||||
const octokit = new Octokit({
|
||||
auth: token,
|
||||
userAgent: 'Superalgos Beta 11'
|
||||
})
|
||||
await getList()
|
||||
|
||||
async function getList() {
|
||||
const repo = repository
|
||||
const owner = 'Superalgos'
|
||||
const per_page = 100 // Max
|
||||
let page = 0
|
||||
let lastPage = false
|
||||
|
||||
while (lastPage === false) {
|
||||
try {
|
||||
page++
|
||||
await sleep(GITHUB_API_WAITING_TIME)
|
||||
let listResponse = await octokit[endpoint][method]({
|
||||
owner,
|
||||
repo,
|
||||
per_page,
|
||||
page
|
||||
});
|
||||
|
||||
if (listResponse.data.length < 100) {
|
||||
lastPage = true
|
||||
}
|
||||
|
||||
for (let i = 0; i < listResponse.data.length; i++) {
|
||||
let listItem = listResponse.data[i]
|
||||
let githubUsername
|
||||
switch(endpoint) {
|
||||
case 'activity' : {
|
||||
githubUsername = listItem.login
|
||||
break
|
||||
}
|
||||
case 'repos' : {
|
||||
githubUsername = listItem.owner.login
|
||||
break
|
||||
}
|
||||
}
|
||||
//console.log(listItem)
|
||||
|
||||
githubListArray.push(githubUsername)
|
||||
}
|
||||
console.log('[INFO] httpInterface -> Gov -> getRepoInfo -> doGithub -> getList -> ' + method + ' Page = ' + page)
|
||||
console.log('[INFO] httpInterface -> Gov -> getRepoInfo -> doGithub -> getList -> ' + method + ' Received = ' + listResponse.data.length)
|
||||
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
|
||||
if (err.stack.indexOf('last page') >= 0) {
|
||||
return
|
||||
} else {
|
||||
console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> getList ->Method call produced an error.')
|
||||
console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> getList ->err.stack = ' + err.stack)
|
||||
console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> getList ->repository = ' + repository)
|
||||
console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> getList ->username = ' + username)
|
||||
console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> getList ->token starts with = ' + token.substring(0, 10) + '...')
|
||||
console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> doGithub -> getList ->token ends with = ' + '...' + token.substring(token.length - 10))
|
||||
error = err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> Method call produced an error.')
|
||||
console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> err.stack = ' + err.stack)
|
||||
console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> repository = ' + repository)
|
||||
console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> username = ' + username)
|
||||
console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> token starts with = ' + token.substring(0, 10) + '...')
|
||||
console.log('[ERROR] httpInterface -> Gov -> getRepoInfo -> token ends with = ' + '...' + token.substring(token.length - 10))
|
||||
|
||||
let error = {
|
||||
result: 'Fail Because',
|
||||
message: err.message,
|
||||
stack: err.stack
|
||||
}
|
||||
respondWithContent(JSON.stringify(error), httpResponse)
|
||||
}
|
||||
}
|
||||
function respondWithDocsObject(docs, error) {
|
||||
|
||||
if (error.message !== undefined) {
|
||||
docs.placeholder.errorMessage = {
|
||||
style: 'Error',
|
||||
text: error.message
|
||||
}
|
||||
}
|
||||
if (error.stack !== undefined) {
|
||||
docs.placeholder.errorStack = {
|
||||
style: 'Javascript',
|
||||
text: error.stack
|
||||
}
|
||||
}
|
||||
if (error.code !== undefined) {
|
||||
docs.placeholder.errorCode = {
|
||||
style: 'Json',
|
||||
text: error.code
|
||||
}
|
||||
}
|
||||
|
||||
docs.placeholder.errorDetails = {
|
||||
style: 'Json',
|
||||
text: JSON.stringify(error, undefined, 4)
|
||||
}
|
||||
|
||||
let customResponse = {
|
||||
result: global.CUSTOM_FAIL_RESPONSE.result,
|
||||
docs: docs
|
||||
}
|
||||
|
||||
respondWithContent(JSON.stringify(customResponse), httpResponse)
|
||||
|
||||
}
|
||||
}
|
||||
break
|
||||
|
||||
case 'LegacyPlotter.js':
|
||||
{
|
||||
respondWithFile(global.env.PATH_TO_CLIENT + 'WebServer/LegacyPlotter.js', httpResponse)
|
||||
@@ -948,6 +1240,7 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
|
||||
}
|
||||
|
||||
path = unescape(path)
|
||||
|
||||
respondWithImage(path, httpResponse)
|
||||
}
|
||||
break
|
||||
@@ -1041,24 +1334,44 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
|
||||
}
|
||||
break
|
||||
|
||||
case 'ProjectNames':
|
||||
{
|
||||
let projects = getDirectories(global.env.PATH_TO_PROJECTS)
|
||||
respondWithContent(JSON.stringify(projects), httpResponse)
|
||||
}
|
||||
break
|
||||
|
||||
case 'Schema':
|
||||
{
|
||||
sendSchema(global.env.PATH_TO_PROJECTS + '/' + requestParameters[2] + '/Schemas/', requestParameters[3])
|
||||
}
|
||||
break
|
||||
|
||||
case 'DirContent':
|
||||
{
|
||||
let folderPath = unescape(requestParameters[2])
|
||||
if (requestParameters[3] !== undefined) {
|
||||
folderPath = folderPath + '/' + requestParameters[3]
|
||||
}
|
||||
|
||||
if (requestParameters[4] !== undefined) {
|
||||
folderPath = folderPath + '/' + requestParameters[4]
|
||||
}
|
||||
|
||||
if (requestParameters[5] !== undefined) {
|
||||
folderPath = folderPath + '/' + requestParameters[5]
|
||||
}
|
||||
let folder
|
||||
if (requestParameters[2] === 'Root') {
|
||||
folder = folderPath.replace('Root', '../Superalgos/')
|
||||
} else {
|
||||
folder = global.env.PATH_TO_PROJECTS + '/' + folderPath
|
||||
}
|
||||
|
||||
getAllFilesInDirectoryAndSubdirectories(folder, onFilesReady)
|
||||
|
||||
function onFilesReady(files) {
|
||||
respondWithContent(JSON.stringify(files), httpResponse)
|
||||
}
|
||||
}
|
||||
break
|
||||
|
||||
case 'IconNames':
|
||||
{
|
||||
let projects = getDirectories(global.env.PATH_TO_PROJECTS)
|
||||
const fs = require('fs')
|
||||
|
||||
let icons = []
|
||||
let totalProjects = projects.length
|
||||
let projectCounter = 0
|
||||
@@ -1068,9 +1381,14 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
|
||||
|
||||
const folder = global.env.PATH_TO_PROJECTS + '/' + project + '/Icons/'
|
||||
|
||||
fs.readdir(folder, (err, files) => {
|
||||
getAllFilesInDirectoryAndSubdirectories(folder, onFilesReady)
|
||||
|
||||
function onFilesReady(files) {
|
||||
for (let j = 0; j < files.length; j++) {
|
||||
let file = files[j]
|
||||
for (let i = 0; i < 10; i++) {
|
||||
file = file.replace('/', '\\')
|
||||
}
|
||||
icons.push([project, file])
|
||||
}
|
||||
|
||||
@@ -1078,7 +1396,7 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
|
||||
if (projectCounter === totalProjects) {
|
||||
respondWithContent(JSON.stringify(icons), httpResponse)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
break
|
||||
@@ -1092,6 +1410,9 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
|
||||
let folder = global.env.PATH_TO_PROJECTS + '/' + project + '/Plugins/' + pluginType
|
||||
|
||||
fs.readdir(folder, (err, files) => {
|
||||
if (files === undefined) {
|
||||
files = []
|
||||
}
|
||||
respondWithContent(JSON.stringify(files), httpResponse)
|
||||
})
|
||||
}
|
||||
@@ -1107,6 +1428,35 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
|
||||
}
|
||||
break
|
||||
|
||||
case 'SavePlugin':
|
||||
getBody(processRequest)
|
||||
|
||||
async function processRequest(body) {
|
||||
try {
|
||||
let plugin = JSON.parse(body)
|
||||
let project = requestParameters[2]
|
||||
let folder = requestParameters[3]
|
||||
let fileName = requestParameters[4]
|
||||
let filePath = global.env.PATH_TO_PROJECTS + '/' + project + '/Plugins/' + folder
|
||||
let fileContent = JSON.stringify(plugin, undefined, 4)
|
||||
const fs = require('fs')
|
||||
fs.writeFileSync(filePath + '/' + fileName + '.json', fileContent)
|
||||
respondWithContent(JSON.stringify(global.DEFAULT_OK_RESPONSE), httpResponse)
|
||||
} catch (err) {
|
||||
console.log('[ERROR] httpInterface -> SavePlugin -> Method call produced an error.')
|
||||
console.log('[ERROR] httpInterface -> SavePlugin -> err.stack = ' + err.stack)
|
||||
console.log('[ERROR] httpInterface -> SavePlugin -> Params Received = ' + body)
|
||||
|
||||
let error = {
|
||||
result: 'Fail Because',
|
||||
message: err.message,
|
||||
stack: err.stack
|
||||
}
|
||||
respondWithContent(JSON.stringify(error), httpResponse)
|
||||
}
|
||||
}
|
||||
break
|
||||
|
||||
case 'Workspace.js':
|
||||
{
|
||||
let fs = require('fs')
|
||||
@@ -1237,7 +1587,7 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
|
||||
|
||||
function onFileWritten(err) {
|
||||
if (err) {
|
||||
console.log('[ERROR] SaveWorkspace -> onFileWritten -> Error writting the Workspace file. fileName = ' + fileName)
|
||||
console.log('[ERROR] SaveWorkspace -> onFileWritten -> Error writing the Workspace file. fileName = ' + fileName)
|
||||
console.log('[ERROR] SaveWorkspace -> onFileWritten -> err.stack = ' + err.stack)
|
||||
let error = {
|
||||
result: 'Fail Because',
|
||||
@@ -1251,7 +1601,7 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
console.log('[ERROR] SaveWorkspace -> Error writting the Workspace file. fileName = ' + fileName)
|
||||
console.log('[ERROR] SaveWorkspace -> Error writing the Workspace file. fileName = ' + fileName)
|
||||
console.log('[ERROR] SaveWorkspace -> err.stack = ' + err.stack)
|
||||
let error = {
|
||||
result: 'Fail Because',
|
||||
@@ -1392,6 +1742,12 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
|
||||
}
|
||||
break
|
||||
|
||||
case 'governance.css':
|
||||
{
|
||||
sendStyleSheet('governance.css')
|
||||
}
|
||||
break
|
||||
|
||||
case 'context-menu.css':
|
||||
{
|
||||
sendStyleSheet('context-menu.css')
|
||||
@@ -1496,57 +1852,73 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
|
||||
|
||||
function sendSchema(filePath, schemaType) {
|
||||
let fs = require('fs')
|
||||
try {
|
||||
let folder = ''
|
||||
switch (schemaType) {
|
||||
case 'AppSchema': {
|
||||
folder = 'App-Schema'
|
||||
break
|
||||
}
|
||||
case 'DocsNodeSchema': {
|
||||
folder = 'Docs-Nodes'
|
||||
break
|
||||
}
|
||||
case 'DocsConceptSchema': {
|
||||
folder = 'Docs-Concepts'
|
||||
break
|
||||
}
|
||||
case 'DocsTopicSchema': {
|
||||
folder = 'Docs-Topics'
|
||||
break
|
||||
}
|
||||
case 'DocsTutorialSchema': {
|
||||
folder = 'Docs-Tutorials'
|
||||
break
|
||||
}
|
||||
case 'DocsReviewSchema': {
|
||||
folder = 'Docs-Reviews'
|
||||
break
|
||||
}
|
||||
case 'DocsBookSchema': {
|
||||
folder = 'Docs-Books'
|
||||
break
|
||||
}
|
||||
try {
|
||||
let folder = ''
|
||||
switch (schemaType) {
|
||||
case 'AppSchema': {
|
||||
folder = 'App-Schema'
|
||||
break
|
||||
}
|
||||
case 'DocsNodeSchema': {
|
||||
folder = 'Docs-Nodes'
|
||||
break
|
||||
}
|
||||
case 'DocsConceptSchema': {
|
||||
folder = 'Docs-Concepts'
|
||||
break
|
||||
}
|
||||
case 'DocsTopicSchema': {
|
||||
folder = 'Docs-Topics'
|
||||
break
|
||||
}
|
||||
case 'DocsTutorialSchema': {
|
||||
folder = 'Docs-Tutorials'
|
||||
break
|
||||
}
|
||||
case 'DocsReviewSchema': {
|
||||
folder = 'Docs-Reviews'
|
||||
break
|
||||
}
|
||||
case 'DocsBookSchema': {
|
||||
folder = 'Docs-Books'
|
||||
break
|
||||
}
|
||||
}
|
||||
getAllFilesInDirectoryAndSubdirectories(filePath + folder, onFilesReady)
|
||||
function onFilesReady(files) {
|
||||
|
||||
let schemaArray = []
|
||||
let fileList = fs.readdirSync(filePath + '/' + folder)
|
||||
for (let k = 0; k < fileList.length; k++) {
|
||||
let name = fileList[k]
|
||||
let fileContent = fs.readFileSync(filePath + '/' + folder + '/' + name)
|
||||
let schemaDocument = JSON.parse(fileContent)
|
||||
for (let k = 0; k < files.length; k++) {
|
||||
let name = files[k]
|
||||
let nameSplitted = name.split(folder)
|
||||
let fileName = nameSplitted[1]
|
||||
for (let i = 0; i < 10; i++) {
|
||||
fileName = fileName.replace('\\', '/')
|
||||
}
|
||||
let fileToRead = filePath + folder + fileName
|
||||
|
||||
let fileContent = fs.readFileSync(fileToRead)
|
||||
let schemaDocument
|
||||
try {
|
||||
schemaDocument = JSON.parse(fileContent)
|
||||
} catch (err) {
|
||||
console.log('[ERROR] httpInterface -> sendSchema -> Error Parsing JSON File: ' + fileToRead + ' .Error = ' + err.stack)
|
||||
respondWithContent("[]", httpResponse)
|
||||
return
|
||||
}
|
||||
schemaArray.push(schemaDocument)
|
||||
}
|
||||
let schema = JSON.stringify(schemaArray)
|
||||
respondWithContent(schema, httpResponse)
|
||||
} catch (err) {
|
||||
if (err.message.indexOf('no such file or directory') < 0) {
|
||||
console.log('Could not send Schema:', filePath, schemaType)
|
||||
console.log(err.stack)
|
||||
}
|
||||
respondWithContent("[]", httpResponse)
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
if (err.message.indexOf('no such file or directory') < 0) {
|
||||
console.log('Could not send Schema:', filePath, schemaType)
|
||||
console.log(err.stack)
|
||||
}
|
||||
respondWithContent("[]", httpResponse)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function sendStyleSheet(fileName) {
|
||||
@@ -1727,4 +2099,44 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
|
||||
return []
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getAllFilesInDirectoryAndSubdirectories(dir, callback) {
|
||||
const { promisify } = require('util');
|
||||
const { resolve } = require('path');
|
||||
const fs = require('fs');
|
||||
const readdir = promisify(fs.readdir);
|
||||
const stat = promisify(fs.stat);
|
||||
|
||||
getFiles(dir)
|
||||
.then(files => {
|
||||
let splittedDir = dir.split('/')
|
||||
let lastFolder = splittedDir[splittedDir.length - 2]
|
||||
let pathAndNames = []
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
let file = files[i]
|
||||
let pathName = file.substring(file.indexOf(lastFolder) + lastFolder.length, file.length)
|
||||
pathName = pathName.substring(1, pathName.length)
|
||||
pathAndNames.push(pathName)
|
||||
}
|
||||
callback(pathAndNames)
|
||||
})
|
||||
.catch(e => {
|
||||
callback([])
|
||||
});
|
||||
|
||||
async function getFiles(dir) {
|
||||
const subdirs = await readdir(dir);
|
||||
const files = await Promise.all(subdirs.map(async (subdir) => {
|
||||
const res = resolve(dir, subdir);
|
||||
return (await stat(res)).isDirectory() ? getFiles(res) : res;
|
||||
}));
|
||||
return files.reduce((a, f) => a.concat(f), []);
|
||||
}
|
||||
}
|
||||
|
||||
function sleep(ms) {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(resolve, ms)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user