]> source.dussan.org Git - nextcloud-server.git/commitdiff
Route for thumbnail generation
authortobiasKaminsky <tobias@kaminsky.me>
Sat, 9 Aug 2014 08:39:12 +0000 (10:39 +0200)
committerThomas Müller <thomas.mueller@tmit.eu>
Tue, 16 Sep 2014 13:00:58 +0000 (15:00 +0200)
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

apps/files/appinfo/application.php [new file with mode: 0644]
apps/files/appinfo/routes.php
apps/files/controller/apicontroller.php [new file with mode: 0644]
lib/private/preview.php

diff --git a/apps/files/appinfo/application.php b/apps/files/appinfo/application.php
new file mode 100644 (file)
index 0000000..7ca48ba
--- /dev/null
@@ -0,0 +1,31 @@
+<?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\Appinfo;
+
+use OC\AppFramework\Utility\SimpleContainer;
+use OCA\Files\Controller\ApiController;
+use OCP\AppFramework\App;
+
+class Application extends App {
+       public function __construct(array $urlParams=array()) {
+               parent::__construct('files', $urlParams);
+               $container = $this->getContainer();
+
+
+               /**
+                * Controllers
+                */
+               $container->registerService('APIController', function (SimpleContainer $c) {
+                       return new ApiController(
+                               $c->query('AppName'),
+                               $c->query('Request')
+                       );
+               });
+       }
+}
index 4d77065a347fb158afc883668dc97080bc2db867..a99b5de3af9131fbe9ca3852745a0fc20274dbba 100644 (file)
@@ -6,7 +6,15 @@
  * See the COPYING-README file.
  */
 
-/** @var $this OC\Route\Router */
+namespace OCA\Files\Appinfo;
+
+$application = new Application();
+$application->registerRoutes($this, array('routes' => array(
+       array('name' => 'API#getThumbnail', 'url' => '/api/v1/thumbnail/{x}/{y}/{file}', 'verb' => 'GET'),
+)));
+
+
+/** @var $this \OC\Route\Router */
 
 $this->create('files_index', '/')
        ->actionInclude('files/index.php');
@@ -38,4 +46,4 @@ $this->create('download', 'download{file}')
        ->actionInclude('files/download.php');
        
 // Register with the capabilities API
-OC_API::register('get', '/cloud/capabilities', array('OCA\Files\Capabilities', 'getCapabilities'), 'files', OC_API::USER_AUTH);
+\OC_API::register('get', '/cloud/capabilities', array('OCA\Files\Capabilities', 'getCapabilities'), 'files', \OC_API::USER_AUTH);
diff --git a/apps/files/controller/apicontroller.php b/apps/files/controller/apicontroller.php
new file mode 100644 (file)
index 0000000..01f9086
--- /dev/null
@@ -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);
+               }
+       }
+
+}
index d6bff961a7334de15c69deb8a4f63f6151973984..bc3eccbafb42dd96a832cb607e8e6bc7a89c7951 100755 (executable)
@@ -15,6 +15,7 @@ namespace OC;
 
 use OC\Files\Filesystem;
 use OC\Preview\Provider;
+use OCP\Files\NotFoundException;
 
 require_once 'preview/image.php';
 require_once 'preview/movies.php';
@@ -110,6 +111,11 @@ class Preview {
                        \OC_Log::write('core', 'No preview providers exist', \OC_Log::ERROR);
                        throw new \Exception('No preview providers');
                }
+
+               // Check if file is valid
+               if($this->isFileValid() === false) {
+                       throw new NotFoundException('File not found.');
+               }
        }
 
        /**