summaryrefslogtreecommitdiffstats
path: root/apps/files/controller
diff options
context:
space:
mode:
authortobiasKaminsky <tobias@kaminsky.me>2014-08-09 10:39:12 +0200
committerThomas Müller <thomas.mueller@tmit.eu>2014-09-16 15:00:58 +0200
commite62d5b7e55ea5eab098751146f6c49641574c7c9 (patch)
tree166c7ceedb173845b36858ce7e32b19f4ca09090 /apps/files/controller
parent1978d3d6a279a4c60371b2cf809bd57e70f4ed35 (diff)
downloadnextcloud-server-e62d5b7e55ea5eab098751146f6c49641574c7c9.tar.gz
nextcloud-server-e62d5b7e55ea5eab098751146f6c49641574c7c9.zip
Route for thumbnail generation
Thumbnail generation Removed Log Added requested changes Added requested changes. - Fix code style - Add exception if file does not exist - Switch route styling Replaces https://github.com/owncloud/core/pull/10805 Fix codestyle Fix codestyle Migrate to appframework Fix typo
Diffstat (limited to 'apps/files/controller')
-rw-r--r--apps/files/controller/apicontroller.php52
1 files changed, 52 insertions, 0 deletions
diff --git a/apps/files/controller/apicontroller.php b/apps/files/controller/apicontroller.php
new file mode 100644
index 00000000000..01f9086c27d
--- /dev/null
+++ b/apps/files/controller/apicontroller.php
@@ -0,0 +1,52 @@
+<?php
+/**
+ * Copyright (c) 2014 Lukas Reschke <lukas@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OCA\Files\Controller;
+
+use OCP\AppFramework\Http;
+use OCP\AppFramework\Controller;
+use OCP\IRequest;
+use OCP\AppFramework\Http\JSONResponse;
+use OCP\AppFramework\Http\DownloadResponse;
+use OC\Preview;
+
+class ApiController extends Controller {
+
+ public function __construct($appName, IRequest $request){
+ parent::__construct($appName, $request);
+ }
+
+
+ /**
+ * Gets a thumbnail of the specified file
+ *
+ * @since API version 1.0
+ *
+ * @NoAdminRequired
+ * @NoCSRFRequired
+ *
+ * @param int $x
+ * @param int $y
+ * @param string $file
+ * @return JSONResponse|DownloadResponse
+ */
+ public function getThumbnail($x, $y, $file) {
+ if($x < 1 || $y < 1) {
+ return new JSONResponse('Requested size must be numeric and a positive value.', Http::STATUS_BAD_REQUEST);
+ }
+
+ try {
+ $preview = new Preview('', 'files', $file, $x, $y, true);
+ echo($preview->showPreview('image/png'));
+ return new DownloadResponse($file.'.png', 'image/png');
+ } catch (\Exception $e) {
+ return new JSONResponse('File not found.', Http::STATUS_NOT_FOUND);
+ }
+ }
+
+}