|
1 | | -import { env } from '$env/dynamic/private'; |
2 | 1 | import { STATUS, StatusService } from '$lib/services/status.service'; |
3 | 2 | import type { RequestHandler } from './$types'; |
4 | 3 |
|
@@ -27,29 +26,46 @@ const getStatusNumber = (command: Command) => { |
27 | 26 | const isCommand = (command: string | null): command is Command => |
28 | 27 | Object.values(COMMAND).includes(command as Command); |
29 | 28 |
|
30 | | -export const POST: RequestHandler = async ({ locals, request }) => { |
| 29 | +export const POST: RequestHandler = async ({ locals, request, platform }) => { |
31 | 30 | const formData = await request.formData(); |
32 | 31 | const command = formData.get('command') as string; |
33 | 32 |
|
| 33 | + console.log(Object.fromEntries(formData.entries())); |
| 34 | + |
34 | 35 | if (!isCommand(command)) { |
| 36 | + console.log('Invalid command:', command); |
| 37 | + |
35 | 38 | return new Response('Invalid command', { status: 400 }); |
36 | 39 | } |
37 | 40 |
|
38 | 41 | if (command === COMMAND.STATUS) { |
39 | 42 | const status = await locals.statusService.get(); |
40 | 43 | const text = StatusService.getMessage(status); |
41 | 44 |
|
| 45 | + console.log('Status command, current status:', status); |
| 46 | + |
42 | 47 | return Response.json({ |
43 | 48 | response_type: 'in_channel', |
44 | 49 | text |
45 | 50 | }); |
46 | 51 | } |
47 | 52 |
|
48 | | - if (formData.get('token') !== env.SLACK_VERIFICATION_TOKEN) { |
49 | | - return new Response('Invalid token', { status: 403 }); |
| 53 | + const token = formData.get('token') as string; |
| 54 | + const channelId = formData.get('channel_id') as string; |
| 55 | + |
| 56 | + const cfEnv = platform!.env; |
| 57 | + const verificationToken = cfEnv.SLACK_VERIFICATION_TOKEN; |
| 58 | + const slackChannelId = cfEnv.SLACK_CHANNEL_ID; |
| 59 | + |
| 60 | + if (token !== verificationToken) { |
| 61 | + console.log('Invalid token:', token); |
| 62 | + |
| 63 | + return new Response('Invalid token', { status: 401 }); |
50 | 64 | } |
51 | 65 |
|
52 | | - if (formData.get('channel_id') !== env.SLACK_CHANNEL_ID) { |
| 66 | + if (channelId !== slackChannelId) { |
| 67 | + console.log('Invalid channel:', channelId); |
| 68 | + |
53 | 69 | return new Response('Invalid channel', { status: 403 }); |
54 | 70 | } |
55 | 71 |
|
|
0 commit comments