This repository has been archived by the owner on Nov 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
65 lines (61 loc) · 2.31 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
<?php
@include_once __DIR__ . '/vendor/autoload.php';
Kirby::plugin('bnomei/cloudconvert', [
'options' => [
'cache' => true,
'apikey' => null,
'convert' => function ($api, array $options, string $outputPath, bool $async) {
if ($async) {
return \Bnomei\CloudConvert::defaultConvertAsync($api, $options, $outputPath);
} else {
return \Bnomei\CloudConvert::defaultConvert($api, $options, $outputPath);
}
},
'async' => true,
'options' => [
'input' => 'download', // must be public else use 'upload'
// 'save' => true,
],
'log.enabled' => false,
'log.fn' => function (string $msg, string $level = 'info', array $context = []):bool {
if (option('bnomei.cloudconvert.log.enabled') && function_exists('kirbyLog')) {
kirbyLog('bnomei.cloudconvert.log')->log($msg, $level, $context);
return true;
}
return false;
},
],
'fileMethods' => [
'cloudconvert' => function (array $options, string $outputPath = null, $async = null) {
$options = array_merge(option('bnomei.cloudconvert.options'), $options);
if (!\Kirby\Toolkit\A::get($options, 'file')) {
$options['file'] = $this; // public url for download
}
return \Bnomei\CloudConvert::convert($options, $outputPath, $async);
}
],
'routes' => [
[
'pattern' => 'plugin-cloudconvert',
'action' => function () {
$id = strip_tags(kirby()->request()->get('id'));
$url = strip_tags(urldecode(kirby()->request()->get('url')));
if ($id && $url) {
if (\Bnomei\CloudConvert::callback($id, $url)) {
return Kirby\Http\Response::json([], 200);
}
}
return Kirby\Http\Response::json([], 500);
},
]
]
]);
if (!class_exists('Bnomei\CloudConvert')) {
require_once __DIR__ . '/classes/CloudConvert.php';
}
if (!function_exists('cloudconvert')) {
function cloudconvert(array $options, string $outputPath = null)
{
return \Bnomei\CloudConvert::convert($options, $outputPath);
}
}