mirror of
https://github.com/sasjs/server.git
synced 2026-01-12 08:40:04 +00:00
fix: update sasjs drive controller from function base to class base
This commit is contained in:
@@ -1,24 +1,15 @@
|
||||
import { fileExists, readFile, createFile } from '@sasjs/utils'
|
||||
|
||||
export const sasjsDrive = async (
|
||||
filePath: string,
|
||||
action: string,
|
||||
newFileContent?: string
|
||||
) => {
|
||||
let fileContent
|
||||
const isFileExists = await fileExists(filePath)
|
||||
if (isFileExists) {
|
||||
switch (action) {
|
||||
case 'read':
|
||||
fileContent = await readFile(filePath)
|
||||
return fileContent
|
||||
case 'update':
|
||||
if (newFileContent) {
|
||||
await createFile(filePath, newFileContent)
|
||||
}
|
||||
break
|
||||
default:
|
||||
break
|
||||
export class SASjsDriveController {
|
||||
async readFile(filePath: string) {
|
||||
if (await fileExists(filePath)) {
|
||||
return await readFile(filePath)
|
||||
}
|
||||
}
|
||||
|
||||
async updateFile(filePath: string, fileContent: string) {
|
||||
if (await fileExists(filePath)) {
|
||||
return await createFile(filePath, fileContent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user