mirror of
https://github.com/sasjs/server.git
synced 2026-01-13 09:00:04 +00:00
feat: add api endpoint for sasjs drive
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
export * from './sas'
|
||||
export * from './deploy'
|
||||
export * from './sasjsExecutor'
|
||||
export * from './sasjsDrive'
|
||||
|
||||
24
src/controllers/sasjsDrive.ts
Normal file
24
src/controllers/sasjsDrive.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,6 @@ import dirTree from 'directory-tree'
|
||||
import path from 'path'
|
||||
|
||||
export const sasjsExecutor = () => {
|
||||
const tree = dirTree(path.join(__dirname, '..'))
|
||||
const tree = dirTree(path.join(__dirname, '..', '..', 'tmp'))
|
||||
return tree
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user