diff options
author | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2016-11-09 13:39:08 +0100 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2017-01-06 09:42:13 +0100 |
commit | 1caaa7f4cd05e45a02ead069adf8625d7b192dcc (patch) | |
tree | 0bd4950f9f5fdc38c897498a374c631cc98f9b18 /core | |
parent | 3a7d6846facec4e03966ab8e03f0fcbd946a8ef0 (diff) | |
download | nextcloud-server-1caaa7f4cd05e45a02ead069adf8625d7b192dcc.tar.gz nextcloud-server-1caaa7f4cd05e45a02ead069adf8625d7b192dcc.zip |
Appdata integration 2
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'core')
-rw-r--r-- | core/Controller/CssController.php | 83 | ||||
-rw-r--r-- | core/routes.php | 1 |
2 files changed, 84 insertions, 0 deletions
diff --git a/core/Controller/CssController.php b/core/Controller/CssController.php new file mode 100644 index 00000000000..45a188adba6 --- /dev/null +++ b/core/Controller/CssController.php @@ -0,0 +1,83 @@ +<?php +/** + * @copyright Copyright (c) 2016, John Molakvoæ (skjnldsv@protonmail.com) + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OC\Core\Controller; + +use OC\AppFramework\Utility\TimeFactory; +use OCP\AppFramework\Controller; +use OCP\AppFramework\Http; +use OCP\AppFramework\Http\NotFoundResponse; +use OCP\AppFramework\Http\FileDisplayResponse; +use OCP\ICssManager; +use OCP\IRequest; + + +class CssController extends Controller { + + /** @var ICssManager */ + protected $cssManager; + + /** @var TimeFactory */ + protected $timeFactory; + + + + /** + * @param string $appName + * @param IRequest $request + * @param ICssManager $cssManager + * @param TimeFactory $timeFactory + */ + public function __construct($appName, IRequest $request, ICssManager $cssManager, TimeFactory $timeFactory) { + parent::__construct($appName, $request); + + $this->cssManager = $cssManager; + $this->timeFactory = $timeFactory; + } + + /** + * @NoAdminRequired + * @NoCSRFRequired + * + * @param string $fileName css filename with extension + * @return text/css + */ + public function getCss($fileName) { + try { + $cssFile = $this->cssManager->getCss($fileName); + } catch(NotFoundException $e) { + return new NotFoundResponse(); + } + + if ($cssFile !== false) { + $response = new FileDisplayResponse($cssFile, Http::STATUS_OK, ['Content-Type' => 'text/css']); + $response->cacheFor(86400); + $expires = new \DateTime(); + $expires->setTimestamp($this->timeFactory->getTime()); + $expires->add(new \DateInterval('PT24H')); + $response->addHeader('Expires', $expires->format(\DateTime::RFC2822)); + $response->addHeader('Pragma', 'cache'); + return $response; + } else { + return new NotFoundResponse(); + } + } +} diff --git a/core/routes.php b/core/routes.php index 2b8080a3b7b..dec979c8ce2 100644 --- a/core/routes.php +++ b/core/routes.php @@ -55,6 +55,7 @@ $application->registerRoutes($this, [ ['name' => 'OCJS#getConfig', 'url' => '/core/js/oc.js', 'verb' => 'GET'], ['name' => 'Preview#getPreview', 'url' => '/core/preview', 'verb' => 'GET'], ['name' => 'Preview#getPreview', 'url' => '/core/preview.png', 'verb' => 'GET'], + ['name' => 'Css#getCss', 'url' => '/css/{fileName}', 'verb' => 'GET'], ], 'ocs' => [ ['root' => '/cloud', 'name' => 'OCS#getCapabilities', 'url' => '/capabilities', 'verb' => 'GET'], |