diff --git a/docs/endpoint-v2.md b/docs/endpoint-v2.md index 0ccbe24ac..2c87650cc 100644 --- a/docs/endpoint-v2.md +++ b/docs/endpoint-v2.md @@ -99,6 +99,8 @@ Field name | Type | Value description `source` | string | Full URL of the image to be displayed `link` | string | Full URL the preview should be wrapped in `mimeType` | string | The mime type of the file (not the preview) +`fileId` | int | The if of the actual file +`view` | string | The view where the file can be found (either `files` or `trashbin`) `isMimeTypeIcon` | bool | True if `source` points to a mime type icon instead of a real preview In case the endpoint returns more fields, they should be ignored and are deprecated (only for backwards compatibility usage) or internal. @@ -113,15 +115,15 @@ In case the endpoint returns more fields, they should be ignored and are depreca "type": "file_created", "user": "test1", "affecteduser": "admin", - "subject": "test1 created hello.jpg", + "subject": "test1 created hello.txt", "subject_rich": { "0": "test1 created {file1}", "1": { "file1": { "type": "file", "id": 23, - "name": "hello.jpg", - "path": "\/test\/hello.jpg" + "name": "hello.txt", + "path": "\/test\/hello.txt" } } }, @@ -134,12 +136,15 @@ In case the endpoint returns more fields, they should be ignored and are depreca "link": "", "object_type": "files", "object_id": 23, - "object_name": "\/test\/hello.jpg", + "object_name": "\/test\/hello.txt", "previews": [ { - "link": "https:\/\/localhost\/index.php\/apps\/files\/?dir=\/test&scrollto=hello.jpg", - "source": "https:\/\/localhost\/index.php\/core\/preview.png?file=\/hello.jpg&x=150&y=150", - "isMimeTypeIcon": false + "link": "https:\/\/localhost\/index.php\/apps\/files\/?dir=\/test&scrollto=hello.txt", + "source": "https:\/\/localhost\/index.php\/core\/preview.png?file=\/hello.txt&x=150&y=150", + "mimeType": "text/plain", + "view": "files", + "fileId": 23, + "isMimeTypeIcon": false } ] } diff --git a/lib/Controller/APIv2.php b/lib/Controller/APIv2.php index 4f3dc2b48..88b3c9f86 100644 --- a/lib/Controller/APIv2.php +++ b/lib/Controller/APIv2.php @@ -353,7 +353,7 @@ protected function getPreview(string $owner, int $fileId, string $filePath): arr $info = $this->infoCache->getInfoById($owner, $fileId, $filePath); if (!$info['exists'] || $info['view'] !== '') { - return $this->getPreviewFromPath($filePath, $info); + return $this->getPreviewFromPath($fileId, $filePath, $info); } $preview = [ @@ -361,6 +361,8 @@ protected function getPreview(string $owner, int $fileId, string $filePath): arr 'source' => '', 'mimeType' => 'application/octet-stream', 'isMimeTypeIcon' => true, + 'fileId' => $fileId, + 'view' => $info['view'] ?: 'files', ]; // show a preview image if the file still exists @@ -371,7 +373,7 @@ protected function getPreview(string $owner, int $fileId, string $filePath): arr $this->view->chroot('/' . $owner . '/files'); $fileInfo = $this->view->getFileInfo($info['path']); if (!$fileInfo instanceof FileInfo) { - $preview = $this->getPreviewFromPath($filePath, $info); + $preview = $this->getPreviewFromPath($fileId, $filePath, $info); } else if ($this->preview->isAvailable($fileInfo)) { $preview['source'] = $this->urlGenerator->linkToRouteAbsolute('core.Preview.getPreview', [ 'file' => $info['path'], @@ -390,13 +392,15 @@ protected function getPreview(string $owner, int $fileId, string $filePath): arr return $preview; } - protected function getPreviewFromPath(string $filePath, array $info): array { + protected function getPreviewFromPath(int $fileId, string $filePath, array $info): array { $mimeType = $info['is_dir'] ? 'dir' : $this->mimeTypeDetector->detectPath($filePath); return [ 'link' => $this->getPreviewLink($info['path'], $info['is_dir'], $info['view']), 'source' => $this->getPreviewPathFromMimeType($mimeType), 'mimeType' => $mimeType, 'isMimeTypeIcon' => true, + 'fileId' => $fileId, + 'view' => $info['view'] ?: 'files', ]; }