summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2016-10-17 10:16:56 +0200
committerRoeland Jago Douma <roeland@famdouma.nl>2016-11-03 14:00:33 +0100
commit3d6ee7ffc97af5c426ae7553bcb40f3c28064f93 (patch)
treedf00093fcb0a1fbbd6d52a424a5ca759bcdc97a7 /apps
parent5d1108519030668cae45d8691b2de7e5629523dc (diff)
downloadnextcloud-server-3d6ee7ffc97af5c426ae7553bcb40f3c28064f93.tar.gz
nextcloud-server-3d6ee7ffc97af5c426ae7553bcb40f3c28064f93.zip
Update thumbnail endpoint to new generato
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'apps')
-rw-r--r--apps/files/lib/Controller/ApiController.php23
1 files changed, 17 insertions, 6 deletions
diff --git a/apps/files/lib/Controller/ApiController.php b/apps/files/lib/Controller/ApiController.php
index 138b68601cb..790da4a184a 100644
--- a/apps/files/lib/Controller/ApiController.php
+++ b/apps/files/lib/Controller/ApiController.php
@@ -31,11 +31,13 @@ namespace OCA\Files\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Controller;
+use OCP\Files\File;
use OCP\Files\Folder;
+use OCP\Files\NotFoundException;
use OCP\IConfig;
use OCP\IRequest;
use OCP\AppFramework\Http\DataResponse;
-use OCP\AppFramework\Http\DataDisplayResponse;
+use OCP\AppFramework\Http\FileDisplayResponse;
use OCP\AppFramework\Http\Response;
use OCA\Files\Service\TagService;
use OCP\IPreview;
@@ -101,18 +103,27 @@ class ApiController extends Controller {
* @param int $x
* @param int $y
* @param string $file URL-encoded filename
- * @return DataResponse|DataDisplayResponse
+ * @return DataResponse|FileDisplayResponse
*/
public function getThumbnail($x, $y, $file) {
if($x < 1 || $y < 1) {
return new DataResponse(['message' => 'Requested size must be numeric and a positive value.'], Http::STATUS_BAD_REQUEST);
}
- $preview = $this->previewManager->createPreview('files/'.$file, $x, $y, true);
- if ($preview->valid()) {
- return new DataDisplayResponse($preview->data(), Http::STATUS_OK, ['Content-Type' => 'image/png']);
- } else {
+ try {
+ $file = $this->userFolder->get($file);
+ if ($file instanceof Folder) {
+ throw new NotFoundException();
+ }
+
+ /** @var File $file */
+ $preview = $this->previewManager->getPreview($file, $x, $y, true);
+
+ return new FileDisplayResponse($preview, Http::STATUS_OK, ['Content-Type' => $preview->getMimeType()]);
+ } catch (NotFoundException $e) {
return new DataResponse(['message' => 'File not found.'], Http::STATUS_NOT_FOUND);
+ } catch (\Exception $e) {
+ return new DataResponse([], Http::STATUS_BAD_REQUEST);
}
}