1
0
mirror of https://github.com/sasjs/server.git synced 2025-12-10 19:34:34 +00:00

chore: modify the implementation files and executor api

This commit is contained in:
2021-10-18 19:50:30 +00:00
parent 91e2e2bc4a
commit a42a1693c2
3 changed files with 25 additions and 7 deletions

View File

@@ -22,7 +22,7 @@ const Main = (props: any) => {
if (props.selectedFilePath !== '') {
setIsLoading(true)
axios
.get(`${baseUrl}/SASjsApi/files?filepath=${props.selectedFilePath}`)
.get(`${baseUrl}/SASjsApi/files?filePath=${props.selectedFilePath}`)
.then((res: any) => {
setIsLoading(false)
setFileContent(res.data.fileContent)

View File

@@ -7,7 +7,12 @@ import {
sasjsDrive,
ExecutionController
} from '../controllers'
import { ExecutionResult, isRequestQuery, isFileTree } from '../types'
import {
ExecutionResult,
isExecutionQuery,
isFileQuery,
isFileTree
} from '../types'
import { getTmpFilesFolderPath } from '../utils'
const router = express.Router()
@@ -45,11 +50,17 @@ router.post('/deploy', async (req, res) => {
})
router.get('/SASjsApi/files', async (req, res) => {
if (req.query.filepath) {
const fileContent = await sasjsDrive(req.query.filepath as string, 'read')
if (isFileQuery(req.query)) {
const filePath = path
.join(getTmpFilesFolderPath(), req.query.filePath)
.replace(new RegExp('/', 'g'), path.sep)
const fileContent = await sasjsDrive(filePath as string, 'read')
res.status(200).send({ status: 'success', fileContent: fileContent })
} else {
throw 'Invalid Request: File path is not provided.'
res.status(400).send({
status: 'failure',
message: 'please provide valid file path'
})
}
})
@@ -64,7 +75,7 @@ router.get('/SASjsApi/executor', async (req, res) => {
})
router.get('/SASjsExecutor/do', async (req, res) => {
if (isRequestQuery(req.query)) {
if (isExecutionQuery(req.query)) {
const sasCodePath = path
.join(getTmpFilesFolderPath(), req.query._program)
.replace(new RegExp('/', 'g'), path.sep)

View File

@@ -6,5 +6,12 @@ export interface ExecutionQuery {
_debug?: boolean
}
export const isRequestQuery = (arg: any): arg is ExecutionQuery =>
export interface FileQuery {
filePath: string
}
export const isExecutionQuery = (arg: any): arg is ExecutionQuery =>
arg && !Array.isArray(arg) && typeof arg._program === 'string'
export const isFileQuery = (arg: any): arg is FileQuery =>
arg && !Array.isArray(arg) && typeof arg.filePath === 'string'