retro/lib/Controller/PageController.php

49 lines
1.2 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;
use OCP\AppFramework\Http\TemplateResponse;
2025-01-03 22:50:29 +01:00
use OCP\Files\IRootFolder;
use OCP\IRequest;
2025-01-03 22:50:29 +01:00
use OCP\IUserSession;
use OCP\Util;
2024-12-26 21:15:05 +01:00
class PageController extends Controller
{
2025-01-03 22:50:29 +01:00
public function __construct(
IRequest $request,
private readonly IRootFolder $rootFolder,
private readonly IUserSession $userSession
) {
parent::__construct(Application::APP_ID, $request);
}
2024-12-26 21:15:05 +01:00
#[NoCSRFRequired]
#[NoAdminRequired]
2025-01-03 22:50:29 +01:00
#[FrontpageRoute(verb: 'GET', url: '/{path}', requirements: ['path' => '.+'])]
public function run(string $path): TemplateResponse {
$user = $this->userSession->getUser();
2025-01-03 22:50:29 +01:00
if (!$user) {
throw new \Exception('User not logged in');
}
$folder = $this->rootFolder->getUserFolder($user->getUID());
$folder->get($path);
Util::addScript(Application::APP_ID, Application::APP_ID.'-main');
2024-12-26 21:15:05 +01:00
return new TemplateResponse(
Application::APP_ID,
'index',
);
}
}