Conditions | 6 |
Paths | 5 |
Total Lines | 19 |
Code Lines | 10 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
19 | public function publish(Request $request): array |
||
20 | { |
||
21 | if ($request->headers->get('webhook-signature') === null) { |
||
|
|||
22 | throw new BadRequestHttpException('Header not set'); |
||
23 | } |
||
24 | |||
25 | $signature = hash_hmac('sha1', $request->getContent(), config('storyblok.webhook_secret')); |
||
26 | |||
27 | if ($request->header('webhook-signature') === $signature) { |
||
28 | if ($request->all()['action'] === 'published') { |
||
29 | StoryblokPublished::dispatch($request->all()); |
||
30 | } else if ($request->all()['action'] === 'unpublished' || $request->all()['action'] === 'deleted') { |
||
31 | StoryblokUnpublished::dispatch($request->all()); |
||
32 | } |
||
33 | |||
34 | return ['success' => true]; |
||
35 | } |
||
36 | |||
37 | throw new BadRequestHttpException('Signature has invalid format'); |
||
38 | } |
||
40 |