protected function addSharing(Request $request) { if (!$request->request->has('path')) { return $this->abort(400); } $fileManager = FileManager::getByUser($this->getUserId()); $path = $fileManager->getAbsolutePath($request->request->get('path')); if (!file_exists($path)) { return $this->abort(404); } $sharing = new Sharing(null, $this->getUserId(), $fileManager->getRelativePath($path)); $sharing->save(); return $this->success($this->url('listFiles', array('token' => $sharing->getToken()), 'sharings_')); }
protected function getDirectLink(Request $request, FileManager $fileManager) { if (!$request->query->has('path')) { return $this->abort(400); } $path = $fileManager->getAbsolutePath($request->query->get('path')); if (!is_file($path)) { return $this->abort(404); } if (!$fileManager->isWritable()) { return $this->abort(500); } $relativePath = $fileManager->getRelativePath($path); list($parentPath) = explode('/', $relativePath); $sharings = Sharing::loadByPathRecursively($parentPath, $fileManager->getOwnerId()); if (count($sharings) > 0) { $sharing = $sharings[0]; } else { $sharing = new Sharing(null, $fileManager->getOwnerId(), $relativePath); $sharing->save(); } $sharingPath = $sharing->getPath(); if (is_file($fileManager->getAbsolutePath($sharingPath))) { $sharingPath = dirname($sharingPath); if ($sharingPath === '.') { $sharingPath = ''; } } $finalPath = str_replace($sharingPath, '', $relativePath); $url = $this->url('openFile', ['token' => $sharing->getToken(), 'path' => $finalPath], 'sharings_'); return $this->success($url); }