Skip to content

Commit

Permalink
fix(execute): added atribute indicating stp api
Browse files Browse the repository at this point in the history
  • Loading branch information
YuryShkoda committed May 2, 2023
1 parent bd1b580 commit e78f87f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ CORS=
WHITELIST=
# HELMET Cross Origin Embedder Policy
# Sets the Cross-Origin-Embedder-Policy header to require-corp when `true`
# Sets the Cross-Origin-Embedder-Policy header to require-corp when `true`
# options: [true|false] default: true
# Docs: https://helmetjs.github.io/#reference (`crossOriginEmbedderPolicy`)
HELMET_COEP=
Expand Down
28 changes: 17 additions & 11 deletions api/src/controllers/internal/Execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ interface ExecuteFileParams {
session?: Session
runTime: RunTimeType
forceStringResult?: boolean
isStp?: boolean
}

interface ExecuteProgramParams extends Omit<ExecuteFileParams, 'programPath'> {
Expand All @@ -44,7 +45,8 @@ export class ExecutionController {
returnJson,
session,
runTime,
forceStringResult
forceStringResult,
isStp
}: ExecuteFileParams) {
const program = await readFile(programPath)

Expand All @@ -56,7 +58,8 @@ export class ExecutionController {
returnJson,
session,
runTime,
forceStringResult
forceStringResult,
isStp
})
}

Expand All @@ -67,7 +70,8 @@ export class ExecutionController {
otherArgs,
session: sessionByFileUpload,
runTime,
forceStringResult
forceStringResult,
isStp
}: ExecuteProgramParams): Promise<ExecuteReturnRaw> {
const sessionController = getSessionController(runTime)

Expand All @@ -77,9 +81,7 @@ export class ExecutionController {
session.consumed = true

const logPath = path.join(session.path, 'log.log')
const printOutputPath = path.join(session.path, 'output.lst')
const headersPath = path.join(session.path, 'stpsrv_header.txt')

const weboutPath = path.join(session.path, 'webout.txt')
const tokenFile = path.join(session.path, 'reqHeaders.txt')

Expand All @@ -103,9 +105,6 @@ export class ExecutionController {
)

const log = (await fileExists(logPath)) ? await readFile(logPath) : ''
const printOutput = (await fileExists(printOutputPath))
? await readFile(printOutputPath)
: ''
const headersContent = (await fileExists(headersPath))
? await readFile(headersPath)
: ''
Expand Down Expand Up @@ -134,9 +133,16 @@ export class ExecutionController {
resultParts.push(process.logsUUID)
resultParts.push(log)

if (printOutput) {
resultParts.push(process.logsUUID)
resultParts.push(printOutput)
if (!isStp) {
const printOutputPath = path.join(session.path, 'output.lst')
const printOutput = (await fileExists(printOutputPath))
? await readFile(printOutputPath)
: ''

if (printOutput) {
resultParts.push(process.logsUUID)
resultParts.push(printOutput)
}
}

return {
Expand Down
13 changes: 7 additions & 6 deletions api/src/controllers/stp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { Request, Security, Route, Tags, Post, Body, Get, Query } from 'tsoa'
import { ExecutionController, ExecutionVars } from './internal'
import {
getPreProgramVariables,
HTTPHeaders,
LogLine,
makeFilesNamesMap,
getRunTimeAndFilePath
} from '../utils'
Expand Down Expand Up @@ -39,7 +37,8 @@ export class STPController {
@Query() _program: string
): Promise<string | Buffer> {
const vars = request.query as ExecutionVars
return execute(request, _program, vars)

return execute(request, _program, vars, undefined, true)
}

/**
Expand Down Expand Up @@ -67,15 +66,16 @@ export class STPController {
: null
const otherArgs = { filesNamesMap: filesNamesMap }

return execute(request, program!, vars, otherArgs)
return execute(request, program!, vars, otherArgs, true)
}
}

const execute = async (
req: express.Request,
_program: string,
vars: ExecutionVars,
otherArgs?: any
otherArgs?: any,
isStp?: boolean
): Promise<string | Buffer> => {
try {
const { codePath, runTime } = await getRunTimeAndFilePath(_program)
Expand All @@ -87,7 +87,8 @@ const execute = async (
preProgramVariables: getPreProgramVariables(req),
vars,
otherArgs,
session: req.sasjsSession
session: req.sasjsSession,
isStp
}
)

Expand Down

0 comments on commit e78f87f

Please sign in to comment.