Skip to content

Commit b30bcd4

Browse files
committed
feat(internal-link): event on request
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
1 parent ced1c5b commit b30bcd4

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

apps/files/lib/Controller/ViewController.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use OCP\AppFramework\Services\IInitialState;
2929
use OCP\Collaboration\Resources\LoadAdditionalScriptsEvent as ResourcesLoadAdditionalScriptsEvent;
3030
use OCP\EventDispatcher\IEventDispatcher;
31+
use OCP\Files\Events\InternalLinkRequestEvent;
3132
use OCP\Files\Folder;
3233
use OCP\Files\IRootFolder;
3334
use OCP\Files\NotFoundException;
@@ -89,7 +90,10 @@ public function showFile(?string $fileid = null, ?string $opendetails = null, ?s
8990

9091
// This is the entry point from the `/f/{fileid}` URL which is hardcoded in the server.
9192
try {
92-
return $this->redirectToFile((int)$fileid, $opendetails, $openfile);
93+
$event = new InternalLinkRequestEvent($fileid);
94+
$this->eventDispatcher->dispatchTyped($event);
95+
96+
return $event->getResponse() ?? $this->redirectToFile((int)$fileid, $opendetails, $openfile);
9397
} catch (NotFoundException $e) {
9498
// Keep the fileid even if not found, it will be used
9599
// to detect the file could not be found and warn the user
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
namespace OCP\Files\Events;
10+
11+
use OCP\AppFramework\Http\Response;
12+
use OCP\EventDispatcher\Event;
13+
14+
/**
15+
* @since 32.0.0
16+
*/
17+
class InternalLinkRequestEvent extends Event {
18+
private ?Response $response = null;
19+
/**
20+
* @since 32.0.0
21+
*/
22+
public function __construct(
23+
private string &$fileId,
24+
) {
25+
parent::__construct();
26+
}
27+
28+
/**
29+
* @since 32.0.0
30+
*/
31+
public function setFileId(string $fileId): void {
32+
$this->fileId = $fileId;
33+
}
34+
35+
/**
36+
* @since 32.0.0
37+
*/
38+
public function getFileId(): string {
39+
return $this->fileId;
40+
}
41+
42+
/**
43+
* @since 32.0.0
44+
*/
45+
public function setResponse(Response $response): void {
46+
$this->response = $response;
47+
}
48+
49+
/**
50+
* @since 32.0.0
51+
*/
52+
public function getResponse(): ?Response {
53+
return $this->response;
54+
}
55+
}

0 commit comments

Comments
 (0)