Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/gallery.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier Paroz <github@oparoz.com>2015-08-18 04:16:49 +0300
committerOlivier Paroz <github@oparoz.com>2015-08-18 04:16:49 +0300
commita5c1eb0a9b46c2463011f27a3edd58fbf4f32876 (patch)
tree589bbde528de6a725669693847e4a63fc5e37c6d /controller
parentb9035581998136c19cf4bcb31fedd7f244d48bec (diff)
Add Thumbnails API
Diffstat (limited to 'controller')
-rw-r--r--controller/preview.php12
-rw-r--r--controller/previewapicontroller.php41
-rw-r--r--controller/previewcontroller.php9
3 files changed, 45 insertions, 17 deletions
diff --git a/controller/preview.php b/controller/preview.php
index d479ca99..e8345897 100644
--- a/controller/preview.php
+++ b/controller/preview.php
@@ -15,7 +15,6 @@
namespace OCA\Gallery\Controller;
use OCP\IURLGenerator;
-use OCP\IEventSource;
use OCP\ILogger;
use OCP\Files\File;
@@ -51,10 +50,6 @@ trait Preview {
*/
private $downloadService;
/**
- * @var IEventSource
- */
- private $eventSource;
- /**
* @var ILogger
*/
private $logger;
@@ -219,13 +214,14 @@ trait Preview {
/**
* Returns an URL based on the HTTP status code
*
- * @param $status
+ * @param string $appName
+ * @param int $status
*
* @return string
*/
- private function getErrorUrl($status) {
+ private function getErrorUrl($appName, $status) {
return $this->urlGenerator->linkToRoute(
- $this->appName . '.page.error_page',
+ $appName . '.page.error_page',
[
'message' => 'There was a problem accessing the file',
'code' => $status
diff --git a/controller/previewapicontroller.php b/controller/previewapicontroller.php
index 9c505c1e..d59548b7 100644
--- a/controller/previewapicontroller.php
+++ b/controller/previewapicontroller.php
@@ -14,7 +14,6 @@ namespace OCA\Gallery\Controller;
use OCP\IRequest;
use OCP\IURLGenerator;
-use OCP\IEventSource;
use OCP\ILogger;
use OCP\Files\File;
@@ -27,6 +26,7 @@ use OCA\Gallery\Http\ImageResponse;
use OCA\Gallery\Service\ThumbnailService;
use OCA\Gallery\Service\PreviewService;
use OCA\Gallery\Service\DownloadService;
+use OCA\Gallery\Utility\EventSource;
/**
* Class PreviewApiController
@@ -39,7 +39,7 @@ class PreviewApiController extends ApiController {
use JsonHttpError;
/**
- * @var IEventSource
+ * @var EventSource
*/
private $eventSource;
@@ -52,7 +52,7 @@ class PreviewApiController extends ApiController {
* @param ThumbnailService $thumbnailService
* @param PreviewService $previewService
* @param DownloadService $downloadService
- * @param IEventSource $eventSource
+ * @param EventSource $eventSource
* @param ILogger $logger
*/
public function __construct(
@@ -62,7 +62,7 @@ class PreviewApiController extends ApiController {
ThumbnailService $thumbnailService,
PreviewService $previewService,
DownloadService $downloadService,
- IEventSource $eventSource,
+ EventSource $eventSource,
ILogger $logger
) {
parent::__construct($appName, $request);
@@ -80,6 +80,37 @@ class PreviewApiController extends ApiController {
* @NoCSRFRequired
* @CORS
*
+ * Generates thumbnails
+ *
+ * @see PreviewController::getThumbnails()
+ *
+ * @param string $ids the ID of the files of which we need thumbnail previews of
+ * @param bool $square
+ * @param double $scale
+ *
+ * @return array<string,array|string|null>
+ */
+ public function getThumbnails($ids, $square, $scale) {
+ $idsArray = explode(';', $ids);
+
+ foreach ($idsArray as $id) {
+ // Casting to integer here instead of using array_map to extract IDs from the URL
+ list($thumbnail, $status) = $this->getThumbnail((int)$id, $square, $scale);
+ $thumbnail['fileid'] = $id;
+ $thumbnail['status'] = $status;
+
+ $this->eventSource->send('preview', $thumbnail);
+ }
+ $this->eventSource->close();
+
+ exit();
+ }
+
+ /**
+ * @NoAdminRequired
+ * @NoCSRFRequired
+ * @CORS
+ *
* Sends either a large preview of the requested file or the original file itself
*
* @param int $fileId the ID of the file of which we need a large preview of
@@ -98,7 +129,7 @@ class PreviewApiController extends ApiController {
if ($preview === null) {
if ($this->download) {
- $url = $this->getErrorUrl($status);
+ $url = $this->getErrorUrl($this->appName, $status);
return new RedirectResponse($url);
} else {
diff --git a/controller/previewcontroller.php b/controller/previewcontroller.php
index 01ac9a00..a25519b9 100644
--- a/controller/previewcontroller.php
+++ b/controller/previewcontroller.php
@@ -27,6 +27,7 @@ use OCA\Gallery\Http\ImageResponse;
use OCA\Gallery\Service\ThumbnailService;
use OCA\Gallery\Service\PreviewService;
use OCA\Gallery\Service\DownloadService;
+use OCA\Gallery\Utility\EventSource;
/**
* Class PreviewController
@@ -39,7 +40,7 @@ class PreviewController extends Controller {
use JsonHttpError;
/**
- * @var IEventSource
+ * @var EventSource
*/
private $eventSource;
@@ -52,7 +53,7 @@ class PreviewController extends Controller {
* @param ThumbnailService $thumbnailService
* @param PreviewService $previewService
* @param DownloadService $downloadService
- * @param IEventSource $eventSource
+ * @param EventSource $eventSource
* @param ILogger $logger
*/
public function __construct(
@@ -62,7 +63,7 @@ class PreviewController extends Controller {
ThumbnailService $thumbnailService,
PreviewService $previewService,
DownloadService $downloadService,
- IEventSource $eventSource,
+ EventSource $eventSource,
ILogger $logger
) {
parent::__construct($appName, $request);
@@ -132,7 +133,7 @@ class PreviewController extends Controller {
if ($preview === null) {
if ($this->download) {
- $url = $this->getErrorUrl($status);
+ $url = $this->getErrorUrl($this->appName, $status);
return new RedirectResponse($url);
} else {