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;
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;
}
}
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;
+ }
+ });
+ }
}
}
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;
}
}
+ public function getSourceFile(): FileInfo {
+ return $this->version->getSourceFile();
+ }
+
public function getContentType(): string {
return $this->version->getMimeType();
}
:force-display-actions="true"
data-files-versions-version>
<template #icon>
- <img v-if="!previewError"
+ <img v-if="(isCurrent || version.hasPreview) && !previewError"
:src="previewURL"
alt=""
+ decoding="async"
+ fetchpriority="low"
+ loading="lazy"
class="version__image"
@error="previewError = true">
<div v-else
* @property {string} size - Human readable size
* @property {string} type - 'file'
* @property {number} mtime - Version creation date as a timestamp
+ * @property {boolean} hasPreview - Whether the version has a preview
* @property {string} preview - Preview URL of the version
* @property {string} url - Download URL of the version
* @property {string|null} fileVersion - The version id, null for the current version
size: version.size,
type: version.type,
mtime: moment(version.lastmod).unix() * 1000,
+ hasPreview: version.props['has-preview'] === 1,
preview: generateUrl('/apps/files_versions/preview?file={file}&version={fileVersion}', {
file: joinPaths(fileInfo.path, fileInfo.name),
fileVersion: version.basename,