Skip to content

Commit

Permalink
Base versions' has-preview on mimetype
Browse files Browse the repository at this point in the history
Signed-off-by: Louis Chemineau <louis@chmn.me>
  • Loading branch information
artonge committed Jun 29, 2023
1 parent 505a11b commit d7f87e7
Showing 1 changed file with 3 additions and 18 deletions.
21 changes: 3 additions & 18 deletions apps/files_versions/lib/Sabre/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
use OC\AppFramework\Http\Request;
use OCA\DAV\Connector\Sabre\FilesPlugin;
use OCA\Files_Versions\Versions\IVersionManager;
use OCP\Files\NotFoundException;
use OCP\IPreview;
use OCP\IRequest;
use OCP\IUserSession;
use Sabre\DAV\Exception\NotFound;
Expand All @@ -49,6 +49,7 @@ class Plugin extends ServerPlugin {
public function __construct(
private IRequest $request,
private IVersionManager $versionManager,
private IPreview $previewManager,
private IUserSession $userSession,
) {
$this->request = $request;
Expand Down Expand Up @@ -94,25 +95,9 @@ public function afterGet(RequestInterface $request, ResponseInterface $response)
}

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;
}
});
}
$propFind->handle(FilesPlugin::HAS_PREVIEW_PROPERTYNAME, fn () => $this->previewManager->isMimeSupported($node->getContentType()));
}
}

Expand Down

0 comments on commit d7f87e7

Please sign in to comment.