UserDynamicObserver.php
1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
namespace App\Observers;
use App\Helpers\UploadHelper;
use App\Jobs\MediaTranscodeJob;
use App\Models\UserDynamic;
use Illuminate\Support\Str;
class UserDynamicObserver
{
public bool $afterCommit = true;
/**
* @throws \JsonException
*/
public function created(UserDynamic $dynamic): void
{
if ($dynamic->getAttribute('type') !== 'image' && !Str::endsWith($dynamic->getAttribute('url'), ['.mp3', '.mp4'])) {
if ($dynamic->getAttribute('type') === 'audio') {
MediaTranscodeJob::dispatch($dynamic->getAttribute('url'), [
"TemplateId" => "S00000001-300050",
"OutputObject" => UploadHelper::getFileName('audio') . '.mp3',
"UserData" => json_encode(['event_id' => $dynamic->getKey(), 'event_type' => class_basename($dynamic), 'event_attribute' => 'properties->url'], JSON_THROW_ON_ERROR)
]);
}
if ($dynamic->getAttribute('type') === 'video') {
MediaTranscodeJob::dispatch($dynamic->getAttribute('url'), [
"TemplateId" => "S00000001-200000",
"OutputObject" => UploadHelper::getFileName('video') . '.mp4',
"UserData" => json_encode(['event_id' => $dynamic->getKey(), 'event_type' => class_basename($dynamic), 'event_attribute' => 'properties->url'], JSON_THROW_ON_ERROR)
]);
}
}
}
}