retro/lib/Controller/PageController.php

48 lines
1.3 KiB
PHP
Raw Normal View History

2024-12-26 21:15:05 +01:00
<?php
declare(strict_types=1);
namespace OCA\Retro\Controller;
2024-12-26 21:15:05 +01:00
use OCA\Retro\AppInfo\Application;
2024-12-26 21:15:05 +01:00
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\Attribute\FrontpageRoute;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
2025-01-04 22:12:47 +01:00
use OCP\AppFramework\Http\ContentSecurityPolicy;
2024-12-26 21:15:05 +01:00
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IRequest;
use OCP\Util;
2024-12-26 21:15:05 +01:00
class PageController extends Controller
{
2025-01-04 22:12:47 +01:00
public function __construct(IRequest $request) {
parent::__construct(Application::APP_ID, $request);
}
2024-12-26 21:15:05 +01:00
#[NoCSRFRequired]
#[NoAdminRequired]
2025-01-04 22:12:47 +01:00
#[FrontpageRoute(verb: 'GET', url: '/')]
public function run(): TemplateResponse {
Util::addScript(Application::APP_ID, Application::APP_ID.'-main');
Util::addStyle(Application::APP_ID, Application::APP_ID.'-main');
2025-01-04 22:12:47 +01:00
$csp = new ContentSecurityPolicy();
$csp->addAllowedConnectDomain('cdn.emulatorjs.org');
$csp->addAllowedConnectDomain('blob:');
$csp->addAllowedWorkerSrcDomain('blob:');
2025-01-03 22:50:29 +01:00
2025-01-04 22:12:47 +01:00
/** @psalm-suppress DeprecatedMethod */
$csp->allowEvalScript(true);
2025-01-03 22:50:29 +01:00
2025-01-04 22:12:47 +01:00
$response = new TemplateResponse(Application::APP_ID, 'index');
$response->setHeaders([
'Cross-Origin-Opener-Policy' => 'same-origin',
'Cross-Origin-Embedder-Policy' => 'require-corp',
]);
2025-01-04 22:12:47 +01:00
$response->setContentSecurityPolicy($csp);
2025-01-04 22:12:47 +01:00
return $response;
2024-12-26 21:15:05 +01:00
}
}