| @@ 33-79 (lines=47) @@ | ||
| 30 | use OCP\Files\NotFoundException; |
|
| 31 | use OCP\IRequest; |
|
| 32 | ||
| 33 | class CssController extends Controller { |
|
| 34 | ||
| 35 | /** @var IAppData */ |
|
| 36 | protected $appData; |
|
| 37 | ||
| 38 | /** @var ITimeFactory */ |
|
| 39 | protected $timeFactory; |
|
| 40 | ||
| 41 | /** |
|
| 42 | * @param string $appName |
|
| 43 | * @param IRequest $request |
|
| 44 | * @param IAppData $appData |
|
| 45 | * @param ITimeFactory $timeFactory |
|
| 46 | */ |
|
| 47 | public function __construct($appName, IRequest $request, IAppData $appData, ITimeFactory $timeFactory) { |
|
| 48 | parent::__construct($appName, $request); |
|
| 49 | ||
| 50 | $this->appData = $appData; |
|
| 51 | $this->timeFactory = $timeFactory; |
|
| 52 | } |
|
| 53 | ||
| 54 | /** |
|
| 55 | * @PublicPage |
|
| 56 | * @NoCSRFRequired |
|
| 57 | * |
|
| 58 | * @param string $fileName css filename with extension |
|
| 59 | * @param string $appName css folder name |
|
| 60 | * @return FileDisplayResponse|NotFoundResponse |
|
| 61 | */ |
|
| 62 | public function getCss($fileName, $appName) { |
|
| 63 | try { |
|
| 64 | $folder = $this->appData->getFolder($appName); |
|
| 65 | $cssFile = $folder->getFile($fileName); |
|
| 66 | } catch(NotFoundException $e) { |
|
| 67 | return new NotFoundResponse(); |
|
| 68 | } |
|
| 69 | ||
| 70 | $response = new FileDisplayResponse($cssFile, Http::STATUS_OK, ['Content-Type' => 'text/css']); |
|
| 71 | $response->cacheFor(86400); |
|
| 72 | $expires = new \DateTime(); |
|
| 73 | $expires->setTimestamp($this->timeFactory->getTime()); |
|
| 74 | $expires->add(new \DateInterval('PT24H')); |
|
| 75 | $response->addHeader('Expires', $expires->format(\DateTime::RFC1123)); |
|
| 76 | $response->addHeader('Pragma', 'cache'); |
|
| 77 | return $response; |
|
| 78 | } |
|
| 79 | } |
|
| 80 | ||
| @@ 34-80 (lines=47) @@ | ||
| 31 | use OCP\Files\NotFoundException; |
|
| 32 | use OCP\IRequest; |
|
| 33 | ||
| 34 | class JsController extends Controller { |
|
| 35 | ||
| 36 | /** @var IAppData */ |
|
| 37 | protected $appData; |
|
| 38 | ||
| 39 | /** @var ITimeFactory */ |
|
| 40 | protected $timeFactory; |
|
| 41 | ||
| 42 | /** |
|
| 43 | * @param string $appName |
|
| 44 | * @param IRequest $request |
|
| 45 | * @param IAppData $appData |
|
| 46 | * @param ITimeFactory $timeFactory |
|
| 47 | */ |
|
| 48 | public function __construct($appName, IRequest $request, IAppData $appData, ITimeFactory $timeFactory) { |
|
| 49 | parent::__construct($appName, $request); |
|
| 50 | ||
| 51 | $this->appData = $appData; |
|
| 52 | $this->timeFactory = $timeFactory; |
|
| 53 | } |
|
| 54 | ||
| 55 | /** |
|
| 56 | * @PublicPage |
|
| 57 | * @NoCSRFRequired |
|
| 58 | * |
|
| 59 | * @param string $fileName css filename with extension |
|
| 60 | * @param string $appName css folder name |
|
| 61 | * @return FileDisplayResponse|NotFoundResponse |
|
| 62 | */ |
|
| 63 | public function getJs($fileName, $appName) { |
|
| 64 | try { |
|
| 65 | $folder = $this->appData->getFolder($appName); |
|
| 66 | $jsFile = $folder->getFile($fileName); |
|
| 67 | } catch(NotFoundException $e) { |
|
| 68 | return new NotFoundResponse(); |
|
| 69 | } |
|
| 70 | ||
| 71 | $response = new FileDisplayResponse($jsFile, Http::STATUS_OK, ['Content-Type' => 'application/javascript']); |
|
| 72 | $response->cacheFor(86400); |
|
| 73 | $expires = new \DateTime(); |
|
| 74 | $expires->setTimestamp($this->timeFactory->getTime()); |
|
| 75 | $expires->add(new \DateInterval('PT24H')); |
|
| 76 | $response->addHeader('Expires', $expires->format(\DateTime::RFC1123)); |
|
| 77 | $response->addHeader('Pragma', 'cache'); |
|
| 78 | return $response; |
|
| 79 | } |
|
| 80 | } |
|
| 81 | ||