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

chore: always adding sas extension

This commit is contained in:
Mihajlo Medjedovic
2021-10-19 10:37:23 +00:00
parent f374acae6e
commit a09e90b010
3 changed files with 3 additions and 26 deletions

View File

@@ -7,7 +7,6 @@ import {
import { ExecutionResult, isRequestQuery, isFileTree } from '../types'
import path from 'path'
import {
addSasExtensionIfNotFound,
getTmpFilesFolderPath,
getTmpFolderPath,
makeFilesNamesMap
@@ -63,7 +62,7 @@ router.get('/SASjsExecutor/do', async (req, res) => {
.replace(new RegExp('/', 'g'), path.sep)
// If no extension provided, add .sas extension
sasCodePath += addSasExtensionIfNotFound(sasCodePath)
sasCodePath += '.sas'
await new ExecutionController()
.execute(sasCodePath, undefined, undefined, { ...req.query })
@@ -96,7 +95,7 @@ router.post(
.replace(new RegExp('/', 'g'), path.sep)
// If no extension provided, add .sas extension
sasCodePath += addSasExtensionIfNotFound(sasCodePath)
sasCodePath += '.sas'
let filesNamesMap = null

View File

@@ -23,15 +23,4 @@ export const generateUniqueFileName = (fileName: string, extension = '') =>
'-',
new Date().getTime(),
extension
].join('')
export const addSasExtensionIfNotFound = (value: string) => {
const extension = 'sas'
const valueSplit = value.split('.')
if (valueSplit.length < 2) return `.${extension}`
const hasExt = valueSplit[valueSplit.length - 1].length === 3
return !hasExt ? `.${extension}` : ''
}
].join('')

View File

@@ -1,11 +0,0 @@
import { addSasExtensionIfNotFound } from '..'
describe('file utils', () => {
it('should add extension if missing', async () => {
expect(addSasExtensionIfNotFound('test')).toEqual('.sas')
expect(addSasExtensionIfNotFound('test.test')).toEqual('.sas')
expect(addSasExtensionIfNotFound('test.sas')).toEqual('')
expect(addSasExtensionIfNotFound('test.test.test')).toEqual('.sas')
expect(addSasExtensionIfNotFound('test.test.test.sas')).toEqual('')
})
})