mirror of https://github.com/nextcloud/server.git
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 typoremotes/origin/fix-10825
parent
1978d3d6a2
commit
e62d5b7e55
@ -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')
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue