mirror of
https://github.com/sasjs/server.git
synced 2026-01-12 00:30:06 +00:00
chore: merging with sessions - sas request with file upload
This commit is contained in:
@@ -5,6 +5,7 @@ import { configuration } from '../../package.json'
|
||||
import { promisify } from 'util'
|
||||
import { execFile } from 'child_process'
|
||||
import { Session } from '../types'
|
||||
import { generateFileUploadSasCode } from '../utils'
|
||||
const execFilePromise = promisify(execFile)
|
||||
|
||||
export class ExecutionController {
|
||||
@@ -12,7 +13,8 @@ export class ExecutionController {
|
||||
program = '',
|
||||
autoExec?: string,
|
||||
session?: Session,
|
||||
vars?: any
|
||||
vars?: any,
|
||||
otherArgs?: any
|
||||
) {
|
||||
if (program) {
|
||||
if (!(await fileExists(program))) {
|
||||
@@ -39,10 +41,26 @@ export class ExecutionController {
|
||||
|
||||
let webout = path.join(session.path, 'webout.txt')
|
||||
await createFile(webout, '')
|
||||
|
||||
program = `
|
||||
%let sasjsprocessmode=Stored Program;
|
||||
filename _webout "${webout}";
|
||||
${program}`
|
||||
|
||||
program = `filename _webout "${webout}";\n${program}`
|
||||
// if no files are uploaded filesNamesMap will be undefined
|
||||
if (otherArgs && otherArgs.filesNamesMap) {
|
||||
const uploadSasCode = generateFileUploadSasCode(
|
||||
otherArgs.filesNamesMap,
|
||||
session.path
|
||||
)
|
||||
|
||||
const code = path.join(session.path, 'code.sas')
|
||||
//If sas code for the file is generated it will be appended to the top of sasCode
|
||||
if (uploadSasCode.length > 0) {
|
||||
program = `${uploadSasCode}` + program
|
||||
}
|
||||
}
|
||||
|
||||
let code = path.join(session.path, 'code.sas')
|
||||
if (!(await fileExists(code))) {
|
||||
await createFile(code, program)
|
||||
}
|
||||
@@ -64,7 +82,9 @@ export class ExecutionController {
|
||||
if (await fileExists(log)) log = await readFile(log)
|
||||
else log = ''
|
||||
|
||||
if (stderr) return Promise.reject({ error: stderr, log: log })
|
||||
// if (stderr) {
|
||||
// return Promise.reject({ error: stderr, log: log })
|
||||
// }
|
||||
|
||||
if (await fileExists(webout)) webout = await readFile(webout)
|
||||
else webout = ''
|
||||
@@ -73,7 +93,7 @@ export class ExecutionController {
|
||||
(key: string) => key.toLowerCase() === '_debug'
|
||||
)
|
||||
|
||||
if (debug && vars[debug] >= 131) {
|
||||
if (debug && vars[debug] >= 131 || stderr) {
|
||||
webout = `<html><body>
|
||||
${webout}
|
||||
<div style="text-align:left">
|
||||
@@ -82,7 +102,7 @@ ${webout}
|
||||
</div>
|
||||
</body></html>`
|
||||
}
|
||||
|
||||
|
||||
session.inUse = false
|
||||
|
||||
sessionController.deleteSession(session)
|
||||
|
||||
@@ -70,7 +70,7 @@ export class SessionController {
|
||||
|
||||
this.scheduleSessionDestroy(session)
|
||||
|
||||
this.executionController.execute('', autoExec, session).catch(() => {})
|
||||
this.executionController.execute('', autoExec, session).catch((err) => {})
|
||||
|
||||
this.sessions.push(session)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user