({ request, user }: RequestHandlerParams)
| 15 | } |
| 16 | |
| 17 | async function post({ request, user }: RequestHandlerParams) { |
| 18 | if ( |
| 19 | !(await AppConfig.isAppEnabled('files')) && !(await AppConfig.isAppEnabled('photos')) && |
| 20 | !(await AppConfig.isAppEnabled('notes')) |
| 21 | ) { |
| 22 | return new Response('Forbidden', { status: 403 }); |
| 23 | } |
| 24 | |
| 25 | const requestBody = await request.clone().json() as RequestBody; |
| 26 | |
| 27 | if ( |
| 28 | !requestBody.parentPath || !requestBody.name?.trim() || !requestBody.parentPath.startsWith('/') || |
| 29 | requestBody.parentPath.includes('../') |
| 30 | ) { |
| 31 | return new Response('Bad Request', { status: 400 }); |
| 32 | } |
| 33 | |
| 34 | const deletedDirectory = await DirectoryModel.delete( |
| 35 | user!.id, |
| 36 | requestBody.parentPath, |
| 37 | requestBody.name.trim(), |
| 38 | ); |
| 39 | |
| 40 | const newDirectories = await DirectoryModel.list(user!.id, requestBody.parentPath); |
| 41 | |
| 42 | const responseBody: ResponseBody = { success: deletedDirectory, newDirectories }; |
| 43 | |
| 44 | return new Response(JSON.stringify(responseBody)); |
| 45 | } |
| 46 | |
| 47 | export default page({ |
| 48 | post, |
nothing calls this directly
no test coverage detected