mirror of
https://github.com/sasjs/server.git
synced 2025-12-10 11:24:35 +00:00
chore(refactor-api): remove sasjsExecutor file and move code to ExecutionController
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
import path from 'path'
|
||||
import fs from 'fs'
|
||||
import { getSessionController } from './'
|
||||
import { readFile, fileExists, createFile } from '@sasjs/utils'
|
||||
import path from 'path'
|
||||
import { configuration } from '../../package.json'
|
||||
import { promisify } from 'util'
|
||||
import { execFile } from 'child_process'
|
||||
import { Session } from '../types'
|
||||
import { generateFileUploadSasCode } from '../utils'
|
||||
import { Session, TreeNode } from '../types'
|
||||
import { generateFileUploadSasCode, getTmpFilesFolderPath } from '../utils'
|
||||
|
||||
const execFilePromise = promisify(execFile)
|
||||
|
||||
export class ExecutionController {
|
||||
@@ -105,4 +107,41 @@ ${webout}
|
||||
|
||||
return Promise.resolve(webout)
|
||||
}
|
||||
|
||||
buildDirectorytree() {
|
||||
const root: TreeNode = {
|
||||
name: 'files',
|
||||
relativePath: '',
|
||||
absolutePath: getTmpFilesFolderPath(),
|
||||
children: []
|
||||
}
|
||||
|
||||
const stack = [root]
|
||||
|
||||
while (stack.length) {
|
||||
const currentNode = stack.pop()
|
||||
|
||||
if (currentNode) {
|
||||
const children = fs.readdirSync(currentNode.absolutePath)
|
||||
|
||||
for (let child of children) {
|
||||
const absoluteChildPath = `${currentNode.absolutePath}/${child}`
|
||||
const relativeChildPath = `${currentNode.relativePath}/${child}`
|
||||
const childNode: TreeNode = {
|
||||
name: child,
|
||||
relativePath: relativeChildPath,
|
||||
absolutePath: absoluteChildPath,
|
||||
children: []
|
||||
}
|
||||
currentNode.children.push(childNode)
|
||||
|
||||
if (fs.statSync(childNode.absolutePath).isDirectory()) {
|
||||
stack.push(childNode)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return root
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
export * from './deploy'
|
||||
export * from './sasjsExecutor'
|
||||
export * from './sasjsDrive'
|
||||
export * from './Session'
|
||||
export * from './Execution'
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
import fs from 'fs'
|
||||
import { TreeNode } from '../types'
|
||||
import { getTmpFilesFolderPath } from '../utils'
|
||||
|
||||
export const sasjsExecutor = () => {
|
||||
const root: TreeNode = {
|
||||
name: 'files',
|
||||
relativePath: '',
|
||||
absolutePath: getTmpFilesFolderPath(),
|
||||
children: []
|
||||
}
|
||||
|
||||
const stack = [root]
|
||||
|
||||
while (stack.length) {
|
||||
const currentNode = stack.pop()
|
||||
|
||||
if (currentNode) {
|
||||
const children = fs.readdirSync(currentNode.absolutePath)
|
||||
|
||||
for (let child of children) {
|
||||
const absoluteChildPath = `${currentNode.absolutePath}/${child}`
|
||||
const relativeChildPath = `${currentNode.relativePath}/${child}`
|
||||
const childNode: TreeNode = {
|
||||
name: child,
|
||||
relativePath: relativeChildPath,
|
||||
absolutePath: absoluteChildPath,
|
||||
children: []
|
||||
}
|
||||
currentNode.children.push(childNode)
|
||||
|
||||
if (fs.statSync(childNode.absolutePath).isDirectory()) {
|
||||
stack.push(childNode)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return root
|
||||
}
|
||||
@@ -3,7 +3,6 @@ import path from 'path'
|
||||
import {
|
||||
createFileTree,
|
||||
getTreeExample,
|
||||
sasjsExecutor,
|
||||
SASjsDriveController,
|
||||
ExecutionController,
|
||||
FileUploadController
|
||||
@@ -73,7 +72,7 @@ router.post('/SASjsApi/files', async (req, res) => {
|
||||
})
|
||||
|
||||
router.get('/SASjsApi/executor', async (req, res) => {
|
||||
const tree = sasjsExecutor()
|
||||
const tree = new ExecutionController().buildDirectorytree()
|
||||
res.status(200).send({ status: 'success', tree })
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user