Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@
'postfix' => 'welcome',
],
[
'name' => 'page#create',
'name' => 'page#createGet', // deprecated, use createPost instead
'url' => '/new',
'verb' => 'GET',
],
[
'name' => 'page#createPost',
'url' => '/new',
'verb' => 'POST',
],
[
'name' => 'page#index',
'url' => '/note/{id}',
Expand Down
3 changes: 2 additions & 1 deletion lib/Controller/NotesApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,8 @@ public function getAttachment(int $noteid, string $path): Http\Response {
$response = new StreamResponse($fileHandle);
$response->addHeader('Content-Disposition', 'attachment; filename="' . rawurldecode($targetimage->getName()) . '"');
$response->addHeader('Content-Type', $this->mimeTypeDetector->getSecureMimeType($targetimage->getMimeType()));
$response->addHeader('Cache-Control', 'public, max-age=604800');
$response->addHeader('Vary', 'Authorization, Cookie');
$response->cacheFor(3600);
return $response;
} catch (\Exception $e) {
$this->helper->logException($e);
Expand Down
3 changes: 2 additions & 1 deletion lib/Controller/NotesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,8 @@ public function getAttachment(int $noteid, string $path): Http\Response {
'Content-Type',
$this->mimeTypeDetector->getSecureMimeType($targetimage->getMimeType())
);
$response->addHeader('Cache-Control', 'public, max-age=604800');
$response->addHeader('Vary', 'Authorization, Cookie');
$response->cacheFor(3600);
return $response;
} catch (\Exception $e) {
$this->helper->logException($e);
Expand Down
24 changes: 21 additions & 3 deletions lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
use OCP\AppFramework\Http\Attribute\UserRateLimit;
use OCP\AppFramework\Http\ContentSecurityPolicy;
use OCP\AppFramework\Http\RedirectResponse;
use OCP\AppFramework\Http\TemplateResponse;
Expand All @@ -30,6 +31,7 @@
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\IUserSession;
use Psr\Log\LoggerInterface;

class PageController extends Controller {
private NotesService $notesService;
Expand All @@ -38,6 +40,7 @@ class PageController extends Controller {
private IURLGenerator $urlGenerator;
private IEventDispatcher $eventDispatcher;
private IInitialState $initialState;
private LoggerInterface $logger;

public function __construct(
string $AppName,
Expand All @@ -48,6 +51,7 @@ public function __construct(
IURLGenerator $urlGenerator,
IEventDispatcher $eventDispatcher,
IInitialState $initialState,
LoggerInterface $logger,
) {
parent::__construct($AppName, $request);
$this->notesService = $notesService;
Expand All @@ -56,6 +60,7 @@ public function __construct(
$this->urlGenerator = $urlGenerator;
$this->eventDispatcher = $eventDispatcher;
$this->initialState = $initialState;
$this->logger = $logger;
}


Expand Down Expand Up @@ -102,12 +107,25 @@ public function index() : TemplateResponse {
}

/**
*
* @deprecated Use createPost() instead. This endpoint will be removed in a future version.
*/
#[NoAdminRequired]
#[NoCSRFRequired]
public function create() : RedirectResponse {
$note = $this->notesService->create($this->userSession->getUser()->getUID(), '', '');
#[UserRateLimit(limit: 20, period: 60)]
public function createGet() : RedirectResponse {
$this->logger->debug('Deprecated GET /new endpoint used', [
'user' => $this->userSession->getUser()?->getUID(),
'remote_addr' => $this->request->getRemoteAddress(),
'user_agent' => $this->request->getHeader('User-Agent')
]);
return $this->createPost();
}

#[NoAdminRequired]
#[NoCSRFRequired]
#[UserRateLimit(limit: 20, period: 60)]
public function createPost() : RedirectResponse {
$note = $this->notesService->create($this->userSession->getUser()?->getUID() ?? '', '', '');
$note->setContent('');
$url = $this->urlGenerator->linkToRoute('notes.page.indexnote', [ 'id' => $note->getId() ]);
return new RedirectResponse($url . '?new');
Expand Down