({ request, user }: RequestHandlerParams)
| 16 | } |
| 17 | |
| 18 | async function post({ request, user }: RequestHandlerParams) { |
| 19 | const isPublicFileSharingAllowed = await AppConfig.isPublicFileSharingAllowed(); |
| 20 | |
| 21 | if (!isPublicFileSharingAllowed) { |
| 22 | return new Response('Forbidden', { status: 403 }); |
| 23 | } |
| 24 | |
| 25 | if (!(await AppConfig.isAppEnabled('files'))) { |
| 26 | return new Response('Forbidden', { status: 403 }); |
| 27 | } |
| 28 | |
| 29 | const requestBody = await request.clone().json() as RequestBody; |
| 30 | |
| 31 | if ( |
| 32 | !requestBody.fileShareId || !requestBody.pathInView || !requestBody.pathInView.trim() || |
| 33 | !requestBody.pathInView.startsWith('/') || requestBody.pathInView.includes('../') |
| 34 | ) { |
| 35 | return new Response('Bad Request', { status: 400 }); |
| 36 | } |
| 37 | |
| 38 | const fileShare = await FileShareModel.getById(requestBody.fileShareId); |
| 39 | |
| 40 | if (!fileShare || fileShare.user_id !== user!.id) { |
| 41 | return new Response('Not Found', { status: 404 }); |
| 42 | } |
| 43 | |
| 44 | await FileShareModel.delete(requestBody.fileShareId); |
| 45 | |
| 46 | const newFiles = await FileModel.list(user!.id, requestBody.pathInView); |
| 47 | const newDirectories = await DirectoryModel.list(user!.id, requestBody.pathInView); |
| 48 | |
| 49 | const responseBody: ResponseBody = { success: true, newFiles, newDirectories }; |
| 50 | |
| 51 | return new Response(JSON.stringify(responseBody)); |
| 52 | } |
| 53 | |
| 54 | export default page({ |
| 55 | post, |
nothing calls this directly
no test coverage detected