server = $server; $this->server->on('propFind', [$this, 'propFind']); } public function propFind(PropFind $propFind, INode $node) { if (!in_array(self::WORKSPACE_PROPERTY, $propFind->getRequestedProperties()) && !in_array(self::WORKSPACE_FILE_PROPERTY, $propFind->getRequestedProperties())) { return; } if (!$node instanceof Directory && !$node instanceof FilesHome) { return; } $workspaceAvailable = $this->config->getAppValue(Application::APP_NAME, 'workspace_available', '1') === '1'; $workspaceEnabled = $this->config->getUserValue($this->userId, Application::APP_NAME, 'workspace_enabled', '1') === '1'; if (!$workspaceAvailable || !$workspaceEnabled) { return; } $node = $node->getNode(); try { $file = $this->workspaceService->getFile($node); } catch (\Exception $e) { $file = null; } // Only return the property for the parent node and ignore it for further in depth nodes $propFind->handle(self::WORKSPACE_PROPERTY, function () use ($file) { $cachedContent = ''; if ($file instanceof File) { $cache = $this->cacheFactory->createDistributed('text_workspace'); $cacheKey = $file->getFileInfo()->getId() . '_' . $file->getFileInfo()->getEtag(); if (($cachedContent = $cache->get($cacheKey)) !== null) { return $cachedContent; } try { $cachedContent = $file->getContent(); $cache->set($cacheKey, $cachedContent, 3600); } catch (GenericFileException|NotPermittedException|LockedException $e) { // Ignore but log when debugging $this->logger->debug($e->getMessage(), [ 'exception' => $e, ]); } catch (Exception $e) { $this->logger->error($e->getMessage(), [ 'exception' => $e, ]); } } return $cachedContent; }); $propFind->handle(self::WORKSPACE_FILE_PROPERTY, function () use ($file) { if ($file instanceof File) { return $file->getFileInfo()->getId(); } return ''; }); } }