|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Meema\MediaRecognition\Http\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use Aws\Sns\Message; |
|
6
|
|
|
use Illuminate\Routing\Controller; |
|
7
|
|
|
use Meema\MediaRecognition\Events\VideoFacialAnalysisIsCompleted; |
|
8
|
|
|
use Meema\MediaRecognition\Events\VideoLabelAnalysisIsCompleted; |
|
9
|
|
|
use Meema\MediaRecognition\Events\VideoModerationIsCompleted; |
|
10
|
|
|
use Meema\MediaRecognition\Events\VideoTextAnalysisIsCompleted; |
|
11
|
|
|
use Meema\MediaRecognition\Facades\Recognize; |
|
12
|
|
|
|
|
13
|
|
|
class IncomingWebhookController extends Controller |
|
14
|
|
|
{ |
|
15
|
|
|
public function __construct() |
|
16
|
|
|
{ |
|
17
|
|
|
$this->middleware('verify-signature'); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @throws \Exception |
|
22
|
|
|
*/ |
|
23
|
|
|
public function __invoke() |
|
24
|
|
|
{ |
|
25
|
|
|
$message = json_decode(Message::fromRawPostData()['Message'], true); |
|
26
|
|
|
|
|
27
|
|
|
if ($message['Status'] !== 'SUCCEEDED') { |
|
28
|
|
|
return; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
$arr = explode('_', $message['JobTag']); |
|
32
|
|
|
$type = $arr[0]; |
|
33
|
|
|
$mediaId = (int) $arr[1]; |
|
34
|
|
|
|
|
35
|
|
|
try { |
|
36
|
|
|
$this->fireEventFor($type, $message, $mediaId); |
|
37
|
|
|
} catch (\Exception $e) { |
|
38
|
|
|
throw new \Exception($e); |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @param string $type |
|
44
|
|
|
* @param array $message |
|
45
|
|
|
* @param int $mediaId |
|
46
|
|
|
* @throws \Exception |
|
47
|
|
|
*/ |
|
48
|
|
|
public function fireEventFor(string $type, array $message, int $mediaId) |
|
49
|
|
|
{ |
|
50
|
|
|
switch ($type) { |
|
51
|
|
|
case 'labels': |
|
52
|
|
|
Recognize::getLabelsByJobId($message['JobId'], $mediaId); |
|
53
|
|
|
event(new VideoLabelAnalysisIsCompleted($message)); |
|
54
|
|
|
break; |
|
55
|
|
|
case 'faces': |
|
56
|
|
|
Recognize::getFacesByJobId($message['JobId'], $mediaId); |
|
57
|
|
|
event(new VideoFacialAnalysisIsCompleted($message)); |
|
58
|
|
|
break; |
|
59
|
|
|
case 'moderation': |
|
60
|
|
|
Recognize::getContentModerationByJobId($message['JobId'], $mediaId); |
|
61
|
|
|
event(new VideoModerationIsCompleted($message)); |
|
62
|
|
|
break; |
|
63
|
|
|
case 'ocr': |
|
64
|
|
|
Recognize::getTextDetectionByJobId($message['JobId'], $mediaId); |
|
65
|
|
|
event(new VideoTextAnalysisIsCompleted($message)); |
|
66
|
|
|
break; |
|
67
|
|
|
default: |
|
68
|
|
|
throw new \Exception(); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|