Skip to content

Commit 23e0ed7

Browse files
committed
Debug
1 parent 160a0d4 commit 23e0ed7

1 file changed

Lines changed: 21 additions & 5 deletions

File tree

  • programmerbar-web/src/routes/(app)/slack-command

‎programmerbar-web/src/routes/(app)/slack-command/+server.ts‎

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { env } from '$env/dynamic/private';
21
import { STATUS, StatusService } from '$lib/services/status.service';
32
import type { RequestHandler } from './$types';
43

@@ -27,29 +26,46 @@ const getStatusNumber = (command: Command) => {
2726
const isCommand = (command: string | null): command is Command =>
2827
Object.values(COMMAND).includes(command as Command);
2928

30-
export const POST: RequestHandler = async ({ locals, request }) => {
29+
export const POST: RequestHandler = async ({ locals, request, platform }) => {
3130
const formData = await request.formData();
3231
const command = formData.get('command') as string;
3332

33+
console.log(Object.fromEntries(formData.entries()));
34+
3435
if (!isCommand(command)) {
36+
console.log('Invalid command:', command);
37+
3538
return new Response('Invalid command', { status: 400 });
3639
}
3740

3841
if (command === COMMAND.STATUS) {
3942
const status = await locals.statusService.get();
4043
const text = StatusService.getMessage(status);
4144

45+
console.log('Status command, current status:', status);
46+
4247
return Response.json({
4348
response_type: 'in_channel',
4449
text
4550
});
4651
}
4752

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 });
5064
}
5165

52-
if (formData.get('channel_id') !== env.SLACK_CHANNEL_ID) {
66+
if (channelId !== slackChannelId) {
67+
console.log('Invalid channel:', channelId);
68+
5369
return new Response('Invalid channel', { status: 403 });
5470
}
5571

0 commit comments

Comments
 (0)