-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
75 lines (71 loc) · 2.46 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
<?php
# Use @include_once in case plugin is not installed through zip
# see https://getkirby.com/docs/guide/plugins/plugin-setup-composer#support-for-plugin-installation-without-composer
@include_once __DIR__ . '/vendor/autoload.php';
use Kirby\Exception\Exception;
use Kirby\Http\Response;
use Zephir\Contentsync\AuthProvider;
use Zephir\Contentsync\FileProvider;
use Zephir\Contentsync\Helpers\Logger;
use Zephir\Contentsync\SyncProvider;
Kirby::plugin('zephir/contentsync', [
'routes' => function ($kirby) {
return [
[
'pattern' => 'contentsync/files',
'method' => 'GET',
'action' => function () {
try {
AuthProvider::validate();
return FileProvider::fileList();
} catch (Exception $e) {
return Response::json($e->toArray(), $e->getHttpCode());
}
}
],
[
'pattern' => 'contentsync/file/(:any)',
'method' => 'GET',
'action' => function (string $fileId) {
try {
AuthProvider::validate();
FileProvider::fileDownload($fileId);
// Not really a nice solution, but we need to exit before
// kirby tries to set headers
exit;
} catch (Exception $e) {
return Response::json($e->toArray(), $e->getHttpCode());
}
}
]
];
},
'commands' => [
'content:sync' => [
'description' => 'Sync content.',
'args' => [
'verbose' => [
'prefix' => 'v',
'longPrefix' => 'verbose',
'description' => 'Verbose output.',
'noValue' => true
]
],
'command' => function ($cli) : void {
Logger::setCli($cli);
Logger::setLogLevel($cli->arg('verbose') ? 'verbose' : 'info');
$syncProvider = new SyncProvider($cli);
$syncProvider->sync();
}
]
],
'options' => [
'source' => null,
'token' => null,
'enabledRoots' => [
'content' => true,
'accounts' => true,
'license' => true
]
]
]);