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

Merge pull request #51 from sasjs/cli-issue-1108

feat: return json response with the log ob job execution
This commit is contained in:
Yury Shkoda
2022-02-15 11:08:17 +03:00
committed by GitHub
6 changed files with 14 additions and 10 deletions

View File

@@ -153,7 +153,7 @@ export class DriveController {
} }
const getFileTree = () => { const getFileTree = () => {
const tree = new ExecutionController().buildDirectorytree() const tree = new ExecutionController().buildDirectoryTree()
return { status: 'success', tree } return { status: 'success', tree }
} }

View File

@@ -5,11 +5,15 @@ import { readFile, fileExists, createFile, moveFile } from '@sasjs/utils'
import { PreProgramVars, TreeNode } from '../../types' import { PreProgramVars, TreeNode } from '../../types'
import { generateFileUploadSasCode, getTmpFilesFolderPath } from '../../utils' import { generateFileUploadSasCode, getTmpFilesFolderPath } from '../../utils'
export interface ExecutionVars {
[key: string]: string | number | undefined
}
export class ExecutionController { export class ExecutionController {
async executeFile( async executeFile(
programPath: string, programPath: string,
preProgramVariables: PreProgramVars, preProgramVariables: PreProgramVars,
vars: { [key: string]: string | number | undefined }, vars: ExecutionVars,
otherArgs?: any, otherArgs?: any,
returnJson?: boolean returnJson?: boolean
) { ) {
@@ -29,7 +33,7 @@ export class ExecutionController {
async executeProgram( async executeProgram(
program: string, program: string,
preProgramVariables: PreProgramVars, preProgramVariables: PreProgramVars,
vars: { [key: string]: string | number | undefined }, vars: ExecutionVars,
otherArgs?: any, otherArgs?: any,
returnJson?: boolean returnJson?: boolean
) { ) {
@@ -55,6 +59,7 @@ export class ExecutionController {
`${computed}%let ${key}=${vars[key]};\n`, `${computed}%let ${key}=${vars[key]};\n`,
'' ''
) )
const preProgramVarStatments = ` const preProgramVarStatments = `
%let _sasjs_tokenfile=${tokenFile}; %let _sasjs_tokenfile=${tokenFile};
%let _sasjs_username=${preProgramVariables?.username}; %let _sasjs_username=${preProgramVariables?.username};
@@ -138,7 +143,7 @@ ${program}`
: webout : webout
} }
buildDirectorytree() { buildDirectoryTree() {
const root: TreeNode = { const root: TreeNode = {
name: 'files', name: 'files',
relativePath: '', relativePath: '',

View File

@@ -18,7 +18,7 @@ export class FileUploadController {
//It will intercept request and generate unique uuid to be used as a subfolder name //It will intercept request and generate unique uuid to be used as a subfolder name
//that will store the files uploaded //that will store the files uploaded
public preuploadMiddleware = async (req: any, res: any, next: any) => { public preUploadMiddleware = async (req: any, res: any, next: any) => {
let session let session
const sessionController = getSessionController() const sessionController = getSessionController()

View File

@@ -1,7 +1,7 @@
import express from 'express' import express from 'express'
import path from 'path' import path from 'path'
import { Request, Security, Route, Tags, Post, Body, Get, Query } from 'tsoa' import { Request, Security, Route, Tags, Post, Body, Get, Query } from 'tsoa'
import { ExecutionController } from './internal' import { ExecutionController, ExecutionVars } from './internal'
import { PreProgramVars } from '../types' import { PreProgramVars } from '../types'
import { getTmpFilesFolderPath, makeFilesNamesMap } from '../utils' import { getTmpFilesFolderPath, makeFilesNamesMap } from '../utils'
@@ -66,7 +66,7 @@ const executeReturnRaw = async (
req: express.Request, req: express.Request,
_program: string _program: string
): Promise<string> => { ): Promise<string> => {
const query = req.query as { [key: string]: string | number | undefined } const query = req.query as ExecutionVars
const sasCodePath = const sasCodePath =
path path
.join(getTmpFilesFolderPath(), _program) .join(getTmpFilesFolderPath(), _program)

View File

@@ -1,6 +1,5 @@
import express from 'express' import express from 'express'
import { SessionController } from '../../controllers' import { SessionController } from '../../controllers'
import { authenticateAccessToken } from '../../middlewares'
const sessionRouter = express.Router() const sessionRouter = express.Router()

View File

@@ -1,5 +1,5 @@
import express from 'express' import express from 'express'
import { executeProgramRawValidation, runSASValidation } from '../../utils' import { executeProgramRawValidation } from '../../utils'
import { STPController } from '../../controllers/' import { STPController } from '../../controllers/'
import { FileUploadController } from '../../controllers/internal' import { FileUploadController } from '../../controllers/internal'
@@ -26,7 +26,7 @@ stpRouter.get('/execute', async (req, res) => {
stpRouter.post( stpRouter.post(
'/execute', '/execute',
fileUploadController.preuploadMiddleware, fileUploadController.preUploadMiddleware,
fileUploadController.getMulterUploadObject().any(), fileUploadController.getMulterUploadObject().any(),
async (req: any, res: any) => { async (req: any, res: any) => {
const { error: errQ, value: query } = executeProgramRawValidation(req.query) const { error: errQ, value: query } = executeProgramRawValidation(req.query)