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:
-rw-r--r--appinfo/application.php12
-rw-r--r--appinfo/routes.php6
-rw-r--r--controller/publicdownloadcontroller.php99
-rw-r--r--environment/environment.php1
-rw-r--r--service/downloadservice.php2
5 files changed, 119 insertions, 1 deletions
diff --git a/appinfo/application.php b/appinfo/application.php
index de96c4e2..2756d0df 100644
--- a/appinfo/application.php
+++ b/appinfo/application.php
@@ -26,6 +26,7 @@ use OCA\GalleryPlus\Controller\PreviewController;
use OCA\GalleryPlus\Controller\PublicConfigController;
use OCA\GalleryPlus\Controller\PublicFilesController;
use OCA\GalleryPlus\Controller\PublicPreviewController;
+use OCA\GalleryPlus\Controller\PublicDownloadController;
use OCA\GalleryPlus\Environment\Environment;
use OCA\GalleryPlus\Preview\Preview;
use OCA\GalleryPlus\Service\FilesService;
@@ -143,6 +144,17 @@ class Application extends App {
);
}
);
+ $container->registerService(
+ 'PublicDownloadController', function (IContainer $c) {
+ return new PublicDownloadController(
+ $c->query('AppName'),
+ $c->query('Request'),
+ $c->query('OCP\IURLGenerator'),
+ $c->query('DownloadService'),
+ $c->query('Logger')
+ );
+ }
+ );
/**
* Core
diff --git a/appinfo/routes.php b/appinfo/routes.php
index ee8930d2..bf2d97d1 100644
--- a/appinfo/routes.php
+++ b/appinfo/routes.php
@@ -36,6 +36,12 @@ return [
'url' => '/s/{token}',
'verb' => 'GET'
],
+ // Landing page for single media files
+ [
+ 'name' => 'public_download#download_file',
+ 'url' => '/s/{token}/{extension}',
+ 'verb' => 'GET'
+ ],
// Landing page after password entry, for public galleries
[
'name' => 'page#public_index',
diff --git a/controller/publicdownloadcontroller.php b/controller/publicdownloadcontroller.php
new file mode 100644
index 00000000..04e30adc
--- /dev/null
+++ b/controller/publicdownloadcontroller.php
@@ -0,0 +1,99 @@
+<?php
+/**
+ * ownCloud - galleryplus
+ *
+ * This file is licensed under the Affero General Public License version 3 or
+ * later. See the COPYING file.
+ *
+ * @author Olivier Paroz <owncloud@interfasys.ch>
+ *
+ * @copyright Olivier Paroz 2014-2015
+ */
+
+namespace OCA\GalleryPlus\Controller;
+
+use OCP\IRequest;
+use OCP\IURLGenerator;
+use OCP\ILogger;
+
+use OCP\AppFramework\Controller;
+use OCP\AppFramework\Http;
+use OCP\AppFramework\Http\RedirectResponse;
+
+use OCA\GalleryPlus\Http\ImageResponse;
+use OCA\GalleryPlus\Service\ServiceException;
+use OCA\GalleryPlus\Service\DownloadService;
+
+/**
+ * Class PublicDownloadController
+ *
+ * Note: Type casting only works if the "@param" parameters are also included in this class as
+ * their not yet inherited
+ *
+ * @package OCA\GalleryPlus\Controller
+ */
+class PublicDownloadController extends Controller {
+
+ /**
+ * @var IURLGenerator
+ */
+ private $urlGenerator;
+ /**
+ * @var DownloadService
+ */
+ private $downloadService;
+ /**
+ * @var ILogger
+ */
+ private $logger;
+
+ /**
+ * Constructor
+ *
+ * @param string $appName
+ * @param IRequest $request
+ * @param IURLGenerator $urlGenerator
+ * @param DownloadService $downloadService
+ * @param ILogger $logger
+ */
+ public function __construct(
+ $appName,
+ IRequest $request,
+ IURLGenerator $urlGenerator,
+ DownloadService $downloadService,
+ ILogger $logger
+ ) {
+ parent::__construct($appName, $request);
+
+ $this->urlGenerator = $urlGenerator;
+ $this->downloadService = $downloadService;
+ $this->logger = $logger;
+ }
+
+ /**
+ * @PublicPage
+ * @NoCSRFRequired
+ *
+ * Downloads the file associated with a token
+ *
+ * @return \OCA\GalleryPlus\Http\ImageResponse|Http\RedirectResponse
+ */
+ public function downloadFile() {
+ try {
+ $download = $this->downloadService->downloadFile();
+
+ return new ImageResponse($download);
+ } catch (ServiceException $exception) {
+ $url = $this->urlGenerator->linkToRoute(
+ $this->appName . '.page.error_page',
+ [
+ 'message' => $exception->getMessage(),
+ 'code' => Http::STATUS_NOT_FOUND
+ ]
+ );
+
+ return new RedirectResponse($url);
+ }
+ }
+
+}
diff --git a/environment/environment.php b/environment/environment.php
index 280fa785..e6fd5906 100644
--- a/environment/environment.php
+++ b/environment/environment.php
@@ -117,6 +117,7 @@ class Environment {
$origShareOwner = $rootLinkItem['uid_owner'];
$this->userFolder = $this->setupFilesystem($origShareOwner);
+ // This is actually the node ID
$fileSource = $linkItem['file_source'];
$this->fromRootToFolder = $this->buildFromRootToFolder($fileSource);
diff --git a/service/downloadservice.php b/service/downloadservice.php
index 585c194e..3a37ce09 100644
--- a/service/downloadservice.php
+++ b/service/downloadservice.php
@@ -34,7 +34,7 @@ class DownloadService extends Service {
*
* @throws NotFoundServiceException
*/
- public function downloadFile($image, $base64Encode = false) {
+ public function downloadFile($image = '', $base64Encode = false) {
$this->logger->debug("[DownloadService] File to Download: $image");
$file = null;
$download = false;