generated from FriendsOfREDAXO/rex_repo_template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboot.php
64 lines (54 loc) · 2.36 KB
/
boot.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
<?php
namespace Klxm\Nextcloud;
// Nur im Backend ausführen
if (\rex::isBackend() && \rex::getUser()) {
// Assets nur auf der NextCloud-Seite einbinden
if (\rex_be_controller::getCurrentPage() == 'nextcloud/main') {
\rex_view::addJsFile($this->getAssetsUrl('nextcloud.js'));
}
// AJAX Handler für NextCloud API
if (\rex_request('nextcloud_api', 'bool', false)) {
try {
$action = \rex_request('action', 'string');
$path = \rex_request('path', 'string', '/');
$categoryId = \rex_request('category_id', 'integer', 0);
$api = new NextCloud();
switch ($action) {
case 'list':
$files = $api->listFiles($path);
\rex_response::sendJson(['success' => true, 'data' => $files]);
break;
case 'preview':
// Für Bildvorschau senden wir direkt das Bild
$content = $api->getImageContent($path);
$filename = basename($path);
$extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
// Content-Type setzen
$mimeTypes = [
'jpg' => 'image/jpeg',
'jpeg' => 'image/jpeg',
'png' => 'image/png',
'gif' => 'image/gif',
'webp' => 'image/webp'
];
$contentType = $mimeTypes[$extension] ?? 'application/octet-stream';
header('Content-Type: ' . $contentType);
echo $content;
exit;
case 'import':
$result = $api->importToMediapool($path, $categoryId);
\rex_response::sendJson(['success' => true, 'data' => $result]);
break;
default:
throw new \rex_exception('Invalid action');
}
} catch (\Exception $e) {
\rex_logger::factory()->log('error', 'NextCloud AddOn Error', [
'error' => $e->getMessage(),
'trace' => $e->getTraceAsString()
]);
\rex_response::sendJson(['success' => false, 'error' => $e->getMessage()]);
}
exit;
}
}