/** * @NoAdminRequired * * Returns an app configuration array * * @param bool $extraMediaTypes * * @return array <string,null|array> */ private function getConfig($extraMediaTypes = false) { $features = $this->configService->getFeaturesList(); //$this->logger->debug("Features: {features}", ['features' => $features]); $nativeSvgSupport = $this->isNativeSvgActivated($features); $mediaTypes = $this->configService->getSupportedMediaTypes($extraMediaTypes, $nativeSvgSupport); return ['features' => $features, 'mediatypes' => $mediaTypes]; }
/** * @NoAdminRequired * * Returns a list of all media files available to the authenticated user * * * Authentication can be via a login/password or a token/(password) * * For private galleries, it returns all media files, with the full path from the root * folder For public galleries, the path starts from the folder the link gives access to * (virtual root) * * An exception is only caught in case something really wrong happens. As we don't test * files before including them in the list, we may return some bad apples * * @param string $location a path representing the current album in the app * @param array $features the list of supported features * @param string $etag the last known etag in the client * @param array $mediatypes the list of supported media types * * @return array <string,array<string,string|int>>|Http\JSONResponse */ private function getFiles($location, $features, $etag, $mediatypes) { $files = []; /** @var Folder $folderNode */ list($folderPathFromRoot, $folderNode, $locationHasChanged) = $this->searchFolderService->getCurrentFolder(rawurldecode($location), $features); $albumInfo = $this->configService->getAlbumInfo($folderNode, $folderPathFromRoot, $features); if ($albumInfo['etag'] !== $etag) { $files = $this->searchMediaService->getMediaFiles($folderNode, $mediatypes, $features); $files = $this->fixPaths($files, $folderPathFromRoot); } return $this->formatResults($files, $albumInfo, $locationHasChanged); }
/** * @dataProvider providesValidateMimeTypeWithForbiddenMimeData * * @param $mimeType * * @expectedException \OCA\GalleryPlus\Service\ForbiddenServiceException */ public function testValidateMimeTypeWithForbiddenMime($mimeType) { $supportedMimeTypes = ['image/png', 'image/jpeg', 'image/gif', 'image/x-xbitmap', 'image/bmp', 'application/postscript', 'application/x-font']; $this->assertSame($supportedMimeTypes, self::invokePrivate($this->service, 'baseMimeTypes', [$supportedMimeTypes])); $this->mockIsMimeSupported($nativeSvgSupport = true); $this->service->validateMimeType($mimeType); }
/** * Generates the download data * * @param int $fileId the ID of the file of which we need a large preview of * @param string|null $filename * * @return array|false */ private function getDownload($fileId, $filename) { /** @type File $file */ $file = $this->downloadService->getResourceFromId($fileId); $this->configService->validateMimeType($file->getMimeType()); $download = $this->downloadService->downloadFile($file); if (is_null($filename)) { $filename = $file->getName(); } $download['name'] = $filename; return $download; }
/** * Returns the file of which a preview will be generated * * @param int $fileId * * @return array<File|int|null> */ private function getFile($fileId) { $status = Http::STATUS_OK; try { /** @type File $file */ $file = $this->previewService->getResourceFromId($fileId); $this->configService->validateMimeType($file->getMimeType()); } catch (ServiceException $exception) { $file = null; $status = $this->getHttpStatusCode($exception); } return [$file, $status]; }
private function mockGetAlbumInfo($folderNode, $folderPathFromRoot, $features, $answer) { $this->configService->expects($this->once())->method('getAlbumInfo')->with($folderNode, $folderPathFromRoot, $features)->willReturn($answer); }
/** * Mocks PreviewService->getSupportedMediaTypes * * @param $slideshow * @param $nativeSvgSupport * @param $mimeTypes */ private function mockSupportedMediaTypes($slideshow, $nativeSvgSupport, $mimeTypes) { $this->configService->expects($this->any())->method('getSupportedMediaTypes')->with($this->equalTo($slideshow), $this->equalTo($nativeSvgSupport))->willReturn($mimeTypes); }
/** * Mocks ConfigService->getFeaturesList * * @param $features */ private function mockFeaturesList($features) { $this->configService->expects($this->any())->method('getFeaturesList')->willReturn($features); }