assetMapper = $assetMapper; $this->rootFolder = $rootFolder; $this->userId = $userId; $this->userScopeService = $userScopeService; $this->urlGenerator = $urlGenerator; } /** * @NoAdminRequired * @NoCSRFRequired * * @param string $path * @return JSONResponse */ public function create($path) { $userFolder = $this->rootFolder->getUserFolder($this->userId); try { $node = $userFolder->get($path); } catch (NotFoundException $e) { return new JSONResponse([], Http::STATUS_NOT_FOUND); } $asset = $this->assetMapper->newAsset($this->userId, $node->getId()); return new JSONResponse([ 'url' => $this->urlGenerator->linkToRouteAbsolute('richdocuments.assets.get', [ 'token' => $asset->getToken(), ]) ]); } /** * @PublicPage * @NoCSRFRequired * * @param string $token * @return Http\Response */ #[RestrictToWopiServer] public function get($token) { try { $asset = $this->assetMapper->getAssetByToken($token); } catch (DoesNotExistException $e) { return new DataResponse([], Http::STATUS_NOT_FOUND); } // Do not clear the asset on HEAD requests if ($this->request->getMethod() === 'GET') { // Clear the assets so we can only fetch it once $this->assetMapper->delete($asset); } $this->userScopeService->setUserScope($asset->getUid()); $userFolder = $this->rootFolder->getUserFolder($asset->getUid()); $nodes = $userFolder->getById($asset->getFileid()); if ($nodes === []) { return new DataResponse([], Http::STATUS_NOT_FOUND); } $node = array_pop($nodes); if (!($node instanceof File)) { return new DataResponse([], Http::STATUS_NOT_FOUND); } $response = new StreamResponse($node->fopen('rb')); $response->addHeader('Content-Disposition', 'attachment'); $response->addHeader('Content-Type', 'application/octet-stream'); return $response; } }