-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.php
91 lines (77 loc) · 2.99 KB
/
index.php
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
@include_once __DIR__ . '/vendor/autoload.php';
Dotenv\Dotenv::createImmutable(kirby()->root('base'))->load(); // TODO: Add configurable path for .env
Kirby::plugin('robinscholz/kirby-mux', [
'translations' => [
'en' => [
'field.blocks.mux-video.thumbnail' => 'Generate thumbnail from frame',
'field.blocks.mux-video.thumbnail.help' => 'In seconds',
],
'de' => [
'field.blocks.mux-video.thumbnail' => 'Thumbnail aus Frame generieren',
'field.blocks.mux-video.thumbnail.help' => 'In Sekunden',
],
],
'blueprints' => [
'files/mux-video' => __DIR__ . '/blueprints/files/mux-video.yml',
'blocks/mux-video' => __DIR__ . '/blueprints/blocks/mux-video.yml'
],
'hooks' => [
'file.create:after' => function (Kirby\Cms\File $file) {
if ($file->type() !== 'video') { return; }
// Authenticate
$assetsApi = KirbyMux\Auth::assetsApi();
// Upload the file to mux
$result = KirbyMux\Methods::upload($assetsApi, $file->url());
// Save mux data
try {
$file = $file->update([
'mux' => $result->getData()
]);
} catch(Exception $e) {
throw new Exception($e->getMessage());
}
},
'file.delete:before' => function (Kirby\Cms\File $file) {
if ($file->type() !== 'video') { return; }
// Authentication setup
$assetsApi = KirbyMux\Auth::assetsApi();
// Get mux Id
$muxId = json_decode($file->mux())->id;
// Delete Asset
try {
$assetsApi->deleteAsset($muxId);
} catch (Exception $e) {
throw new Exception($e->getMessage());
}
},
'file.replace:before' => function (Kirby\Cms\File $file, Kirby\Filesystem\File $upload) {
if ($upload->type() !== 'video') { return; }
// Authentication setup
$assetsApi = KirbyMux\Auth::assetsApi();
// Get old mux Id
$muxId = json_decode($file->mux())->id;
// Delete old asset
try {
$assetsApi->deleteAsset($muxId);
} catch (Exception $e) {
throw new Exception($e->getMessage());
}
},
'file.replace:after' => function (Kirby\Cms\File $newFile, Kirby\Cms\File $oldFile) {
if ($newFile->type() !== 'video') { return; }
// Authentication setup
$assetsApi = KirbyMux\Auth::assetsApi();
// Upload new file to mux
$result = KirbyMux\Methods::upload($assetsApi, $newFile->url());
// Save playback Id
try {
$newFile = $newFile->update([
'mux' => $result->getData()
]);
} catch(Exception $e) {
throw new Exception($e->getMessage());
}
}
]
]);