1
0
mirror of https://github.com/sasjs/server.git synced 2026-01-15 18:00:05 +00:00

fix: update sasjs drive controller from function base to class base

This commit is contained in:
2021-10-19 15:11:15 +00:00
parent 299319e2db
commit 3fe475d477
2 changed files with 13 additions and 22 deletions

View File

@@ -1,24 +1,15 @@
import { fileExists, readFile, createFile } from '@sasjs/utils' import { fileExists, readFile, createFile } from '@sasjs/utils'
export const sasjsDrive = async ( export class SASjsDriveController {
filePath: string, async readFile(filePath: string) {
action: string, if (await fileExists(filePath)) {
newFileContent?: string return await readFile(filePath)
) => { }
let fileContent }
const isFileExists = await fileExists(filePath)
if (isFileExists) { async updateFile(filePath: string, fileContent: string) {
switch (action) { if (await fileExists(filePath)) {
case 'read': return await createFile(filePath, fileContent)
fileContent = await readFile(filePath)
return fileContent
case 'update':
if (newFileContent) {
await createFile(filePath, newFileContent)
}
break
default:
break
} }
} }
} }

View File

@@ -4,7 +4,7 @@ import {
createFileTree, createFileTree,
getTreeExample, getTreeExample,
sasjsExecutor, sasjsExecutor,
sasjsDrive, SASjsDriveController,
ExecutionController ExecutionController
} from '../controllers' } from '../controllers'
import { import {
@@ -54,7 +54,7 @@ router.get('/SASjsApi/files', async (req, res) => {
const filePath = path const filePath = path
.join(getTmpFilesFolderPath(), req.query.filePath) .join(getTmpFilesFolderPath(), req.query.filePath)
.replace(new RegExp('/', 'g'), path.sep) .replace(new RegExp('/', 'g'), path.sep)
const fileContent = await sasjsDrive(filePath as string, 'read') const fileContent = await new SASjsDriveController().readFile(filePath)
res.status(200).send({ status: 'success', fileContent: fileContent }) res.status(200).send({ status: 'success', fileContent: fileContent })
} else { } else {
res.status(400).send({ res.status(400).send({
@@ -68,7 +68,7 @@ router.post('/SASjsApi/files', async (req, res) => {
const filePath = path const filePath = path
.join(getTmpFilesFolderPath(), req.body.filePath) .join(getTmpFilesFolderPath(), req.body.filePath)
.replace(new RegExp('/', 'g'), path.sep) .replace(new RegExp('/', 'g'), path.sep)
await sasjsDrive(filePath, 'update', req.body.fileContent) await new SASjsDriveController().updateFile(filePath, req.body.fileContent)
res.status(200).send({ status: 'success' }) res.status(200).send({ status: 'success' })
}) })