mirror of
https://github.com/sasjs/server.git
synced 2026-01-13 09:00:04 +00:00
chore: comments addressing
This commit is contained in:
@@ -2,39 +2,12 @@ import express from 'express'
|
||||
import { createFileTree, getSessionController, getTreeExample } from '../controllers'
|
||||
import { ExecutionResult, isRequestQuery, isFileTree } from '../types'
|
||||
import path from 'path'
|
||||
import { getTmpFilesFolderPath, getTmpFolderPath, makeFilesNamesMap } from '../utils'
|
||||
import { ExecutionController } from '../controllers'
|
||||
import { uuidv4 } from '@sasjs/utils'
|
||||
import { addExtensionIfNotFound, getTmpFilesFolderPath, getTmpFolderPath, makeFilesNamesMap } from '../utils'
|
||||
import { ExecutionController, FileUploadController } from '../controllers'
|
||||
|
||||
const multer = require('multer')
|
||||
const router = express.Router()
|
||||
|
||||
const 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, '')}`)
|
||||
}
|
||||
})
|
||||
|
||||
const upload = multer({ storage: storage })
|
||||
|
||||
//It will intercept request and generate uniqe uuid to be used as a subfolder name
|
||||
//that will store the files uploaded
|
||||
const preuploadMiddleware = async (req: any, res: any, next: any) => {
|
||||
let session
|
||||
|
||||
const sessionController = getSessionController()
|
||||
session = await sessionController.getSession()
|
||||
session.inUse = true
|
||||
|
||||
req.sasSession = session
|
||||
|
||||
next()
|
||||
}
|
||||
const fileUploadController = new FileUploadController()
|
||||
|
||||
router.get('/', async (_, res) => {
|
||||
res.status(200).send('Welcome to @sasjs/server API')
|
||||
@@ -102,14 +75,14 @@ router.get('/SASjsExecutor/do', async (req, res) => {
|
||||
}
|
||||
})
|
||||
|
||||
router.post('/SASjsExecutor/do', preuploadMiddleware, upload.any(), async (req: any, res: any) => {
|
||||
router.post('/SASjsExecutor/do', fileUploadController.preuploadMiddleware, fileUploadController.getMulterUploadObject().any(), async (req: any, res: any) => {
|
||||
if (isRequestQuery(req.query)) {
|
||||
let sasCodePath = path
|
||||
.join(getTmpFilesFolderPath(), req.query._program)
|
||||
.replace(new RegExp('/', 'g'), path.sep)
|
||||
|
||||
// If no extension provided, add .sas extension
|
||||
sasCodePath += !sasCodePath.includes('.') ? '.sas' : ''
|
||||
sasCodePath += addExtensionIfNotFound(sasCodePath, 'sas')
|
||||
|
||||
let filesNamesMap = null
|
||||
|
||||
|
||||
Reference in New Issue
Block a user