public function beforeMethod(RequestInterface $request, ResponseInterface $response) { // verify that the owner didn't have his share permissions revoked if ($this->fileInfo && !$this->fileInfo->isShareable()) { throw new NotFound(); } }
/** * @param \OCP\Files\FileInfo $dir * @param \OC\Files\View $view * @return array */ function getChildInfo($dir, $view) { $children = $view->getDirectoryContent($dir->getPath()); $result = array(); foreach ($children as $child) { $formated = \OCA\Files\Helper::formatFileInfo($child); if ($child->getType() === 'dir') { $formated['children'] = getChildInfo($child, $view); } $formated['mtime'] = $formated['mtime'] / 1000; $result[] = $formated; } return $result; }
/** * Formats the file info to be returned as OPDS to the client * * @param \OCP\Files\FileInfo $i * @return array formatted file info */ public static function formatFileInfo(\OCP\Files\FileInfo $i) { $entry = array(); $entry['id'] = $i['fileid']; $entry['mtime'] = $i['mtime']; $entry['name'] = $i->getName(); $entry['type'] = $i['type']; if ($i['type'] === 'file') { $entry['mimetype'] = $i['mimetype']; $entry['humansize'] = \OC_Helper::humanFileSize($i['size']); $entry['meta'] = Meta::get($i['fileid']); } return $entry; }
/** * @return string|null */ public function getDavPermissions() { $p = ''; if ($this->info->isShared()) { $p .= 'S'; } if ($this->info->isShareable()) { $p .= 'R'; } if ($this->info->isMounted()) { $p .= 'M'; } if ($this->info->isDeletable()) { $p .= 'D'; } if ($this->info->isDeletable()) { $p .= 'NV'; // Renameable, Moveable } if ($this->info->getType() === \OCP\Files\FileInfo::TYPE_FILE) { if ($this->info->isUpdateable()) { $p .= 'W'; } } else { if ($this->info->isCreatable()) { $p .= 'CK'; } } return $p; }
protected function verifyPath() { try { $fileName = basename($this->info->getPath()); $this->fileView->verifyPath($this->path, $fileName); } catch (\OCP\Files\InvalidPathException $ex) { throw new InvalidPath($ex->getMessage()); } }
/** * set the path of the file you want a thumbnail from * @param string $file * @return \OC\Preview $this */ public function setFile($file) { $this->file = $file; $this->info = null; if ($file !== '') { $this->getFileInfo(); if($this->info !== null && $this->info !== false) { $this->mimeType = $this->info->getMimetype(); } } return $this; }
/** * set the path of the file you want a thumbnail from * @param string $file * @return $this */ public function setFile($file) { $this->file = $file; $this->info = null; if ($file !== '') { $this->getFileInfo(); if ($this->info instanceof \OCP\Files\FileInfo) { $this->mimeType = $this->info->getMimetype(); } } return $this; }
/** * Create a new file search result * @param FileInfo $data file data given by provider */ public function __construct(FileInfo $data) { $path = $this->getRelativePath($data->getPath()); $info = pathinfo($path); $this->id = $data->getId(); $this->name = $info['basename']; $this->link = \OCP\Util::linkTo('files', 'index.php', array('dir' => $info['dirname'], 'file' => $info['basename'])); $this->permissions = $data->getPermissions(); $this->path = $path; $this->size = $data->getSize(); $this->modified = $data->getMtime(); $this->mime_type = $data->getMimetype(); }
/** * Create a new file search result * @param FileInfo $data file data given by provider */ public function __construct(FileInfo $data) { $path = $this->getRelativePath($data->getPath()); $info = pathinfo($path); $this->id = $data->getId(); $this->name = $info['basename']; $this->link = \OC::$server->getURLGenerator()->linkToRoute('files.view.index', ['dir' => $info['dirname'], 'scrollto' => $info['basename']]); $this->permissions = $data->getPermissions(); $this->path = $path; $this->size = $data->getSize(); $this->modified = $data->getMtime(); $this->mime = $data->getMimetype(); }
/** * Sends the preview, including the headers to client which requested it * * @param null|string $mimeTypeForHeaders the media type to use when sending back the reply * * @throws NotFoundException */ public function showPreview($mimeTypeForHeaders = null) { // Check if file is valid if ($this->isFileValid() === false) { throw new NotFoundException('File not found.'); } if ($cachedPath = $this->isCached($this->info->getId())) { header('Content-Type: ' . $this->info->getMimetype()); $this->userView->readfile($cachedPath); return; } if (is_null($this->preview)) { $this->getPreview(); } if ($this->preview instanceof \OCP\IImage) { if ($this->preview->valid()) { \OCP\Response::enableCaching(3600 * 24); // 24 hours } else { $this->getMimeIcon(); } $this->preview->show($mimeTypeForHeaders); } }
/** * Check if a preview can be generated for a file * * @param \OCP\Files\FileInfo $file * @return bool */ public function isAvailable(\OCP\Files\FileInfo $file) { if (!$this->config->getSystemValue('enable_previews', true)) { return false; } $this->registerCoreProviders(); if (!$this->isMimeSupported($file->getMimetype())) { return false; } $mount = $file->getMountPoint(); if ($mount and !$mount->getOption('previews', true)) { return false; } foreach ($this->providers as $supportedMimeType => $providers) { if (preg_match($supportedMimeType, $file->getMimetype())) { foreach ($providers as $closure) { $provider = $closure(); if (!$provider instanceof IProvider) { continue; } /** @var $provider IProvider */ if ($provider->isAvailable($file)) { return true; } } } } return false; }
/** * Comparator function to sort files by size * * @param \OCP\Files\FileInfo $a file * @param \OCP\Files\FileInfo $b file * @return int -1 if $a must come before $b, 1 otherwise */ public static function compareSize(FileInfo $a, FileInfo $b) { $aSize = $a->getSize(); $bSize = $b->getSize(); return $aSize < $bSize ? -1 : 1; }
/** * {@inheritDoc} */ public function isAvailable(\OCP\Files\FileInfo $file) { return $file->getSize() > 0; }
/** * Returns the ETag for a file * * An ETag is a unique identifier representing the current version of the * file. If the file changes, the ETag MUST change. The ETag is an * arbitrary string, but MUST be surrounded by double-quotes. * * Return null if the ETag can not effectively be determined * * @return mixed */ public function getETag() { return '"' . $this->info->getEtag() . '"'; }
/** * Comparator function to sort files by size * * @param \OCP\Files\FileInfo $a file * @param \OCP\Files\FileInfo $b file * @return int -1 if $a must come before $b, 1 otherwise */ public static function compareSize($a, $b) { $aSize = $a->getSize(); $bSize = $b->getSize(); return $aSize - $bSize; }
/** * Formats the file info to be returned as JSON to the client. * * @param \OCP\Files\FileInfo $i * @return array formatted file info */ public static function formatFileInfo(FileInfo $i) { $entry = array(); $entry['id'] = $i['fileid']; $entry['parentId'] = $i['parent']; $entry['mtime'] = $i['mtime'] * 1000; // only pick out the needed attributes $entry['name'] = $i->getName(); $entry['permissions'] = $i['permissions']; $entry['mimetype'] = $i['mimetype']; $entry['size'] = $i['size']; $entry['type'] = $i['type']; $entry['etag'] = $i['etag']; if (isset($i['tags'])) { $entry['tags'] = $i['tags']; } if (isset($i['displayname_owner'])) { $entry['shareOwner'] = $i['displayname_owner']; } if (isset($i['is_share_mount_point'])) { $entry['isShareMountPoint'] = $i['is_share_mount_point']; } $mountType = null; if ($i->isShared()) { $mountType = 'shared'; } else { if ($i->isMounted()) { $mountType = 'external'; } } if ($mountType !== null) { if ($i->getInternalPath() === '') { $mountType .= '-root'; } $entry['mountType'] = $mountType; } if (isset($i['extraData'])) { $entry['extraData'] = $i['extraData']; } return $entry; }