diff options
author | Louis Chemineau <louis@chmn.me> | 2023-06-19 17:51:53 +0200 |
---|---|---|
committer | Louis Chemineau <louis@chmn.me> | 2023-07-03 11:04:57 +0200 |
commit | b164af46c73387d05f5c67126de51e4d0fc2750f (patch) | |
tree | b87abf2d6a621da0be84b5a3172e1589b6829cb6 /apps/files_versions/lib | |
parent | 5fd29c6f50f56a41f7fbe15a8e85b6648b54bdda (diff) | |
download | nextcloud-server-b164af46c73387d05f5c67126de51e4d0fc2750f.tar.gz nextcloud-server-b164af46c73387d05f5c67126de51e4d0fc2750f.zip |
Provide hasPreview in files_versions DAV API
This allow to no request non existing previews
I also set some properties to the img element to reduce preview loading to what the browser think is necessary
Signed-off-by: Louis Chemineau <louis@chmn.me>
Diffstat (limited to 'apps/files_versions/lib')
-rw-r--r-- | apps/files_versions/lib/Sabre/Plugin.php | 26 | ||||
-rw-r--r-- | apps/files_versions/lib/Sabre/VersionFile.php | 5 |
2 files changed, 29 insertions, 2 deletions
diff --git a/apps/files_versions/lib/Sabre/Plugin.php b/apps/files_versions/lib/Sabre/Plugin.php index 4fd17194ba6..b53f21039be 100644 --- a/apps/files_versions/lib/Sabre/Plugin.php +++ b/apps/files_versions/lib/Sabre/Plugin.php @@ -27,7 +27,11 @@ declare(strict_types=1); namespace OCA\Files_Versions\Sabre; use OC\AppFramework\Http\Request; +use OCA\DAV\Connector\Sabre\FilesPlugin; +use OCA\Files_Versions\Versions\IVersionManager; +use OCP\Files\NotFoundException; use OCP\IRequest; +use OCP\IUserSession; use Sabre\DAV\Exception\NotFound; use Sabre\DAV\INode; use Sabre\DAV\PropFind; @@ -39,12 +43,13 @@ use Sabre\HTTP\ResponseInterface; class Plugin extends ServerPlugin { private Server $server; - private IRequest $request; public const VERSION_LABEL = '{http://nextcloud.org/ns}version-label'; public function __construct( - IRequest $request + private IRequest $request, + private IVersionManager $versionManager, + private IUserSession $userSession, ) { $this->request = $request; } @@ -89,8 +94,25 @@ class Plugin extends ServerPlugin { } public function propFind(PropFind $propFind, INode $node): void { + $user = $this->userSession->getUser(); + if ($node instanceof VersionFile) { $propFind->handle(self::VERSION_LABEL, fn() => $node->getLabel()); + + if ($user !== null) { + $propFind->handle(FilesPlugin::HAS_PREVIEW_PROPERTYNAME, function () use ($node, $user) { + try { + $this->versionManager->getVersionFile( + $user, + $node->getSourceFile(), + $node->getVersion()->getRevisionId() + ); + return true; + } catch (NotFoundException $ex) { + return false; + } + }); + } } } diff --git a/apps/files_versions/lib/Sabre/VersionFile.php b/apps/files_versions/lib/Sabre/VersionFile.php index 8fd97b0636f..bb05d66460a 100644 --- a/apps/files_versions/lib/Sabre/VersionFile.php +++ b/apps/files_versions/lib/Sabre/VersionFile.php @@ -31,6 +31,7 @@ use OCA\Files_Versions\Versions\INameableVersion; use OCA\Files_Versions\Versions\INameableVersionBackend; use OCA\Files_Versions\Versions\IVersion; use OCA\Files_Versions\Versions\IVersionManager; +use OCP\Files\FileInfo; use OCP\Files\NotFoundException; use Sabre\DAV\Exception\Forbidden; use Sabre\DAV\Exception\NotFound; @@ -60,6 +61,10 @@ class VersionFile implements IFile { } } + public function getSourceFile(): FileInfo { + return $this->version->getSourceFile(); + } + public function getContentType(): string { return $this->version->getMimeType(); } |