1
0
mirror of https://github.com/sasjs/server.git synced 2026-01-07 06:30:06 +00:00

feat: add api end point for delete folder

This commit is contained in:
2022-07-19 22:41:03 +05:00
parent 3e53f70928
commit 08e0c61e0f
3 changed files with 72 additions and 0 deletions

View File

@@ -22,6 +22,7 @@ import {
moveFile,
createFolder,
deleteFile as deleteFileOnSystem,
deleteFolder as deleteFolderOnSystem,
folderExists,
listFilesInFolder,
listSubFoldersInFolder,
@@ -140,6 +141,17 @@ export class DriveController {
return getFolder(_folderPath)
}
/**
*
* @summary Delete folder from SASjs Drive
* @query _folderPath Location of folder
* @example _folderPath "/Public/somefolder/"
*/
@Delete('/folder')
public async deleteFolder(@Query() _folderPath: string) {
return deleteFolder(_folderPath)
}
/**
*
* @summary Delete file from SASjs Drive
@@ -315,6 +327,26 @@ const deleteFile = async (filePath: string) => {
return { status: 'success' }
}
const deleteFolder = async (folderPath: string) => {
const driveFolderPath = getFilesFolder()
const folderPathFull = path
.join(getFilesFolder(), folderPath)
.replace(new RegExp('/', 'g'), path.sep)
if (!folderPathFull.includes(driveFolderPath)) {
throw new Error('Cannot delete file outside drive.')
}
if (!(await fileExists(folderPathFull))) {
throw new Error('Folder does not exist.')
}
await deleteFolderOnSystem(folderPathFull)
return { status: 'success' }
}
const saveFile = async (
filePath: string,
multerFile: Express.Multer.File