diff --git a/Web/src/containers/SASjsDrive/main.tsx b/Web/src/containers/SASjsDrive/main.tsx index 80be724..fd90179 100644 --- a/Web/src/containers/SASjsDrive/main.tsx +++ b/Web/src/containers/SASjsDrive/main.tsx @@ -22,7 +22,7 @@ const Main = (props: any) => { if (props.selectedFilePath !== '') { setIsLoading(true) axios - .get(`${baseUrl}/SASjsApi/files?filepath=${props.selectedFilePath}`) + .get(`${baseUrl}/SASjsApi/files?filePath=${props.selectedFilePath}`) .then((res: any) => { setIsLoading(false) setFileContent(res.data.fileContent) diff --git a/src/routes/index.ts b/src/routes/index.ts index 8148bdd..9f37342 100644 --- a/src/routes/index.ts +++ b/src/routes/index.ts @@ -7,7 +7,12 @@ import { sasjsDrive, ExecutionController } from '../controllers' -import { ExecutionResult, isRequestQuery, isFileTree } from '../types' +import { + ExecutionResult, + isExecutionQuery, + isFileQuery, + isFileTree +} from '../types' import { getTmpFilesFolderPath } from '../utils' const router = express.Router() @@ -45,11 +50,17 @@ router.post('/deploy', async (req, res) => { }) router.get('/SASjsApi/files', async (req, res) => { - if (req.query.filepath) { - const fileContent = await sasjsDrive(req.query.filepath as string, 'read') + if (isFileQuery(req.query)) { + const filePath = path + .join(getTmpFilesFolderPath(), req.query.filePath) + .replace(new RegExp('/', 'g'), path.sep) + const fileContent = await sasjsDrive(filePath as string, 'read') res.status(200).send({ status: 'success', fileContent: fileContent }) } else { - throw 'Invalid Request: File path is not provided.' + res.status(400).send({ + status: 'failure', + message: 'please provide valid file path' + }) } }) @@ -64,7 +75,7 @@ router.get('/SASjsApi/executor', async (req, res) => { }) router.get('/SASjsExecutor/do', async (req, res) => { - if (isRequestQuery(req.query)) { + if (isExecutionQuery(req.query)) { const sasCodePath = path .join(getTmpFilesFolderPath(), req.query._program) .replace(new RegExp('/', 'g'), path.sep) diff --git a/src/types/Request.ts b/src/types/Request.ts index 6bc7e2b..5e34c15 100644 --- a/src/types/Request.ts +++ b/src/types/Request.ts @@ -6,5 +6,12 @@ export interface ExecutionQuery { _debug?: boolean } -export const isRequestQuery = (arg: any): arg is ExecutionQuery => +export interface FileQuery { + filePath: string +} + +export const isExecutionQuery = (arg: any): arg is ExecutionQuery => arg && !Array.isArray(arg) && typeof arg._program === 'string' + +export const isFileQuery = (arg: any): arg is FileQuery => + arg && !Array.isArray(arg) && typeof arg.filePath === 'string'