Base versions' has-preview on mimetype

Signed-off-by: Louis Chemineau <louis@chmn.me>
This commit is contained in:
Louis Chemineau 2023-06-29 11:00:25 +02:00
parent 505a11b3e7
commit 05acd916b5
2 changed files with 3 additions and 26 deletions

View file

@ -28,10 +28,8 @@ 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\IPreview;
use OCP\IRequest;
use OCP\IUserSession;
use Sabre\DAV\Exception\NotFound;
use Sabre\DAV\INode;
use Sabre\DAV\PropFind;
@ -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;
}
@ -94,25 +91,9 @@ 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;
}
});
}
$propFind->handle(FilesPlugin::HAS_PREVIEW_PROPERTYNAME, fn () => $this->previewManager->isMimeSupported($node->getContentType()));
}
}

View file

@ -61,10 +61,6 @@ class VersionFile implements IFile {
}
}
public function getSourceFile(): FileInfo {
return $this->version->getSourceFile();
}
public function getContentType(): string {
return $this->version->getMimeType();
}