Skip to content

Commit

Permalink
Add the view and the fileId too
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Oct 11, 2018
1 parent 5818f2a commit 19fc5e4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
19 changes: 12 additions & 7 deletions docs/endpoint-v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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"
}
}
},
Expand All @@ -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
}
]
}
Expand Down
10 changes: 7 additions & 3 deletions lib/Controller/APIv2.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,14 +353,16 @@ 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 = [
'link' => $this->getPreviewLink($info['path'], $info['is_dir'], $info['view']),
'source' => '',
'mimeType' => 'application/octet-stream',
'isMimeTypeIcon' => true,
'fileId' => $fileId,
'view' => $info['view'] ?: 'files',
];

// show a preview image if the file still exists
Expand All @@ -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'],
Expand All @@ -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',
];
}

Expand Down

0 comments on commit 19fc5e4

Please sign in to comment.