diff options
author | Joas Schilling <213943+nickvergessen@users.noreply.github.com> | 2020-06-03 20:25:06 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-03 20:25:06 +0300 |
commit | 3469adacac1b831dca5cbf41ec73bd792f0561fd (patch) | |
tree | 0a1d1715a974e39f309aa8c15419e7fec39c707b | |
parent | cddc6b583d7c038c040884bc8cf57242ed1183bb (diff) | |
parent | e7171830a28ac9506e427534803261013c84db16 (diff) |
Merge pull request #58 from nextcloud/bugfix/57/log-viewer-access-as-download
Log viewer access as download
-rw-r--r-- | lib/AppInfo/Application.php | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 787ff8b..a5edf02 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -23,7 +23,10 @@ namespace OCA\FilesDownloadActivity\AppInfo; use OCA\FilesDownloadActivity\Activity\Listener; use OCP\AppFramework\App; +use OCP\Files\File; +use OCP\IPreview; use OCP\Util; +use Symfony\Component\EventDispatcher\GenericEvent; class Application extends App { @@ -36,6 +39,14 @@ class Application extends App { */ public function register() { Util::connectHook('OC_Filesystem', 'read', $this, 'listenReadFile'); + + $eventDispatcher = $this->getContainer()->getServer()->getEventDispatcher(); + $eventDispatcher->addListener( + IPreview::EVENT, + function (GenericEvent $event) { + $this->listenPreviewFile($event); + } + ); } /** @@ -46,4 +57,33 @@ class Application extends App { $hooks = $this->getContainer()->query(Listener::class); $hooks->readFile($params['path']); } + + /** + * @param GenericEvent $event + */ + public function listenPreviewFile(GenericEvent $event) { + $details = $event->getArguments(); + if ($details['width'] <= 150 && $details['height'] <= 150) { + // Ignore mini preview, but we need "big" previews because of the viewer app. + return; + } + + /** @var File $file */ + $file = $event->getSubject(); + + if (substr_count($file->getPath(), '/') < 3) { + // Invalid path + return; + } + + [,, $filesApp, $path] = explode('/', $file->getPath(), 4); + + if ($filesApp !== 'files') { + return; + } + + /** @var Listener $hooks */ + $hooks = $this->getContainer()->query(Listener::class); + $hooks->readFile($path); + } } |