Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
9 / 9 |
| DownloadService | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
3 | |
100.00% |
9 / 9 |
| downloadFile | |
100.00% |
1 / 1 |
3 | |
100.00% |
9 / 9 |
|||
| <?php | |
| /** | |
| * Gallery | |
| * | |
| * This file is licensed under the Affero General Public License version 3 or | |
| * later. See the COPYING file. | |
| * | |
| * @author Olivier Paroz <galleryapps@oparoz.com> | |
| * | |
| * @copyright Olivier Paroz 2016 | |
| */ | |
| namespace OCA\Gallery\Service; | |
| use OCP\Files\File; | |
| /** | |
| * Prepares the file to download | |
| * | |
| * @package OCA\Gallery\Service | |
| */ | |
| class DownloadService extends Service { | |
| use Base64Encode; | |
| /** | |
| * Downloads the requested file | |
| * | |
| * @param File $file | |
| * @param bool $base64Encode | |
| * | |
| * @return array|false | |
| * @throws NotFoundServiceException | |
| */ | |
| public function downloadFile($file, $base64Encode = false) { | |
| try { | |
| $this->logger->debug( | |
| "[DownloadService] File to Download: {name}", ['name' => $file->getName()] | |
| ); | |
| $download = [ | |
| 'preview' => $file->getContent(), | |
| 'mimetype' => $file->getMimeType() | |
| ]; | |
| if ($base64Encode) { | |
| $download['preview'] = $this->encode($download['preview']); | |
| } | |
| return $download; | |
| } catch (\Exception $exception) { | |
| throw new NotFoundServiceException('There was a problem accessing the file'); | |
| } | |
| } | |
| } |