mirror of
https://github.com/sasjs/server.git
synced 2026-04-10 07:33:13 +00:00
fix(api-cdrive-oller): throw erow error when file not found
This commit is contained in:
19
api/src/controllers/Drive.ts
Normal file
19
api/src/controllers/Drive.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { fileExists, readFile, createFile } from '@sasjs/utils'
|
||||
|
||||
export class DriveController {
|
||||
async readFile(filePath: string) {
|
||||
await this.validateFilePath(filePath)
|
||||
return await readFile(filePath)
|
||||
}
|
||||
|
||||
async updateFile(filePath: string, fileContent: string) {
|
||||
await this.validateFilePath(filePath)
|
||||
return await createFile(filePath, fileContent)
|
||||
}
|
||||
|
||||
private async validateFilePath(filePath: string) {
|
||||
if (!(await fileExists(filePath))) {
|
||||
throw 'DriveController: File does not exists.'
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
export * from './deploy'
|
||||
export * from './sasjsDrive'
|
||||
export * from './Drive'
|
||||
export * from './Session'
|
||||
export * from './Execution'
|
||||
export * from './FileUploadController'
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
import { fileExists, readFile, createFile } from '@sasjs/utils'
|
||||
|
||||
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