1
0
mirror of https://github.com/sasjs/server.git synced 2026-01-12 08:40:04 +00:00

chore: Merge branch 'master into homepage-sasjs-executor

This commit is contained in:
2021-10-19 17:08:41 +00:00
10 changed files with 380 additions and 32 deletions

View File

@@ -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))) {
@@ -40,7 +42,23 @@ export class ExecutionController {
let webout = path.join(session.path, 'webout.txt')
await createFile(webout, '')
program = `filename _webout "${webout}";\n${program}`
program = `
%let sasjsprocessmode=Stored Program;
filename _webout "${webout}";
${program}`
// if no files are uploaded filesNamesMap will be undefined
if (otherArgs && otherArgs.filesNamesMap) {
const uploadSasCode = await generateFileUploadSasCode(
otherArgs.filesNamesMap,
session.path
)
//If sas code for the file is generated it will be appended to the top of sasCode
if (uploadSasCode.length > 0) {
program = `${uploadSasCode}` + program
}
}
const code = path.join(session.path, 'code.sas')
if (!(await fileExists(code))) {
@@ -64,8 +82,6 @@ export class ExecutionController {
if (await fileExists(log)) log = await readFile(log)
else log = ''
if (stderr) return Promise.reject({ error: stderr, log: log })
if (await fileExists(webout)) webout = await readFile(webout)
else webout = ''
@@ -73,7 +89,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">

View File

@@ -0,0 +1,36 @@
import { uuidv4 } from '@sasjs/utils'
import { getSessionController } from '.'
const multer = require('multer')
export class FileUploadController {
private storage = multer.diskStorage({
destination: function (req: any, file: any, cb: any) {
//Sending the intercepted files to the sessions subfolder
cb(null, req.sasSession.path)
},
filename: function (req: any, file: any, cb: any) {
//req_file prefix + unique hash added to sas request files
cb(null, `req_file_${uuidv4().replace(/-/gm, '')}`)
}
})
private upload = multer({ storage: this.storage })
//It will intercept request and generate unique uuid to be used as a subfolder name
//that will store the files uploaded
public preuploadMiddleware = async (req: any, res: any, next: any) => {
let session
const sessionController = getSessionController()
session = await sessionController.getSession()
session.inUse = true
req.sasSession = session
next()
}
public getMulterUploadObject() {
return this.upload
}
}

View File

@@ -3,3 +3,4 @@ export * from './sasjsExecutor'
export * from './sasjsDrive'
export * from './Session'
export * from './Execution'
export * from './FileUploadController'