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 Jul 3, 2023
1 parent 97a72b1 commit 859552b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 26 deletions.
25 changes: 3 additions & 22 deletions apps/files_versions/lib/Sabre/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@

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;
use Sabre\DAV\INode;
use Sabre\DAV\PropFind;
Expand All @@ -48,8 +46,7 @@ class Plugin extends ServerPlugin {

public function __construct(
private IRequest $request,
private IVersionManager $versionManager,
private IUserSession $userSession,
private IPreview $previewManager,
) {
$this->request = $request;
}
Expand Down Expand Up @@ -94,25 +91,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
4 changes: 0 additions & 4 deletions apps/files_versions/lib/Sabre/VersionFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ public function get() {
}
}

public function getSourceFile(): FileInfo {
return $this->version->getSourceFile();
}

public function getContentType(): string {
return $this->version->getMimeType();
}
Expand Down

0 comments on commit 859552b

Please sign in to comment.