Skip to content
Snippets Groups Projects
Unverified Commit 3d6ee7ff authored by Roeland Jago Douma's avatar Roeland Jago Douma
Browse files

Update thumbnail endpoint to new generato

parent 5d110851
No related branches found
No related tags found
No related merge requests found
...@@ -31,11 +31,13 @@ namespace OCA\Files\Controller; ...@@ -31,11 +31,13 @@ namespace OCA\Files\Controller;
use OCP\AppFramework\Http; use OCP\AppFramework\Http;
use OCP\AppFramework\Controller; use OCP\AppFramework\Controller;
use OCP\Files\File;
use OCP\Files\Folder; use OCP\Files\Folder;
use OCP\Files\NotFoundException;
use OCP\IConfig; use OCP\IConfig;
use OCP\IRequest; use OCP\IRequest;
use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Http\DataDisplayResponse; use OCP\AppFramework\Http\FileDisplayResponse;
use OCP\AppFramework\Http\Response; use OCP\AppFramework\Http\Response;
use OCA\Files\Service\TagService; use OCA\Files\Service\TagService;
use OCP\IPreview; use OCP\IPreview;
...@@ -101,18 +103,27 @@ class ApiController extends Controller { ...@@ -101,18 +103,27 @@ class ApiController extends Controller {
* @param int $x * @param int $x
* @param int $y * @param int $y
* @param string $file URL-encoded filename * @param string $file URL-encoded filename
* @return DataResponse|DataDisplayResponse * @return DataResponse|FileDisplayResponse
*/ */
public function getThumbnail($x, $y, $file) { public function getThumbnail($x, $y, $file) {
if($x < 1 || $y < 1) { if($x < 1 || $y < 1) {
return new DataResponse(['message' => 'Requested size must be numeric and a positive value.'], Http::STATUS_BAD_REQUEST); 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); try {
if ($preview->valid()) { $file = $this->userFolder->get($file);
return new DataDisplayResponse($preview->data(), Http::STATUS_OK, ['Content-Type' => 'image/png']); if ($file instanceof Folder) {
} else { 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); return new DataResponse(['message' => 'File not found.'], Http::STATUS_NOT_FOUND);
} catch (\Exception $e) {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment