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