From 3f825073dc4cc67ed9b53e1f8a848b0e7d8cc82f Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Wed, 22 Mar 2023 16:55:20 -0700 Subject: [PATCH] refactor: files --> photos Signed-off-by: Varun Patil --- lib/Controller/AlbumsController.php | 4 +- lib/Controller/GenericClusterController.php | 50 ++++++++++---------- lib/Controller/PeopleControllerUtils.php | 10 ++-- lib/Controller/PeopleRecognizeController.php | 12 ++--- lib/Controller/PlacesController.php | 4 +- lib/Controller/TagsController.php | 4 +- lib/Db/TimelineQueryAlbums.php | 4 +- lib/Db/TimelineQueryPeopleRecognize.php | 2 +- lib/Db/TimelineQueryPlaces.php | 16 ++----- lib/Db/TimelineQueryTags.php | 14 ++---- 10 files changed, 52 insertions(+), 68 deletions(-) diff --git a/lib/Controller/AlbumsController.php b/lib/Controller/AlbumsController.php index b5f2704b..ada3b986 100644 --- a/lib/Controller/AlbumsController.php +++ b/lib/Controller/AlbumsController.php @@ -75,7 +75,7 @@ class AlbumsController extends GenericClusterController return array_values($list); } - protected function getFiles(string $name, ?int $limit = null): array + protected function getPhotos(string $name, ?int $limit = null): array { // Get album $album = $this->timelineQuery->getAlbumIfAllowed($this->getUID(), $name); @@ -86,6 +86,6 @@ class AlbumsController extends GenericClusterController // Get files $id = (int) $album['album_id']; - return $this->timelineQuery->getAlbumFiles($id, $limit) ?? []; + return $this->timelineQuery->getAlbumPhotos($id, $limit) ?? []; } } diff --git a/lib/Controller/GenericClusterController.php b/lib/Controller/GenericClusterController.php index 74ab657a..3dc639a0 100644 --- a/lib/Controller/GenericClusterController.php +++ b/lib/Controller/GenericClusterController.php @@ -69,19 +69,19 @@ abstract class GenericClusterController extends GenericApiController try { $this->init(); - // Get list of some files in this cluster - $files = $this->getFiles($name, 8); + // Get list of some photos in this cluster + $photos = $this->getPhotos($name, 8); - // If no files found then return 404 - if (0 === \count($files)) { + // If no photos found then return 404 + if (0 === \count($photos)) { return new JSONResponse([], Http::STATUS_NOT_FOUND); } - // Put the files in the correct order - $this->sortFilesForPreview($files); + // Put the photos in the correct order + $this->sortPhotosForPreview($photos); // Get preview from image list - return $this->getPreviewFromImageList($files); + return $this->getPreviewFromPhotoList($photos); } catch (HttpResponseException $e) { return $e->response; } catch (\Exception $e) { @@ -102,8 +102,8 @@ abstract class GenericClusterController extends GenericApiController $this->init(); // Get list of all files in this cluster - $files = $this->getFiles($name); - $fileIds = array_map([$this, 'getFileId'], $files); + $photos = $this->getPhotos($name); + $fileIds = array_map([$this, 'getFileId'], $photos); // Get download handle $filename = $this->clusterName($name); @@ -134,13 +134,13 @@ abstract class GenericClusterController extends GenericApiController abstract protected function getClusters(): array; /** - * Get a list of files with extra parameters for the given cluster + * Get a list of photos with any extra parameters for the given cluster * Used for preview generation and download. * * @param string $name Identifier for the cluster - * @param int $limit Maximum number of fileids to return + * @param int $limit Maximum number of photos to return */ - abstract protected function getFiles(string $name, ?int $limit = null): array; + abstract protected function getPhotos(string $name, ?int $limit = null): array; /** * Human readable name for the cluster. @@ -151,12 +151,12 @@ abstract class GenericClusterController extends GenericApiController } /** - * Put the file objects in priority list. + * Put the photo objects in priority list. * Works on the array in place. */ - protected function sortFilesForPreview(array &$files) + protected function sortPhotosForPreview(array &$photos) { - shuffle($files); + shuffle($photos); } /** @@ -170,22 +170,22 @@ abstract class GenericClusterController extends GenericApiController /** * Perform any post processing and get the blob from the preview file. * - * @param \OCP\Files\SimpleFS\ISimpleFile $file - * @param array $object The file object + * @param \OCP\Files\SimpleFS\ISimpleFile $file Preview file + * @param array $photo Photo object * * @return [Blob, mimetype] of data */ - protected function getPreviewBlob($file, $object): array + protected function getPreviewBlob($file, $photo): array { return [$file->getContent(), $file->getMimeType()]; } /** - * Get the file ID for a file object. + * Get the file ID for a photo object. */ - protected function getFileId(array $file): int + protected function getFileId(array $photo): int { - return (int) $file['fileid']; + return (int) $photo['fileid']; } /** @@ -221,16 +221,16 @@ abstract class GenericClusterController extends GenericApiController } /** - * Given a list of file objects, return the first preview image possible. + * Given a list of photo objects, return the first preview image possible. */ - private function getPreviewFromImageList(array $list): Http\Response + private function getPreviewFromPhotoList(array $photos): Http\Response { // Get preview manager $previewManager = \OC::$server->get(\OCP\IPreview::class); // Try to get a preview $userFolder = $this->rootFolder->getUserFolder($this->getUID()); - foreach ($list as $img) { + foreach ($photos as $img) { // Get the file $files = $userFolder->getById($this->getFileId($img)); if (0 === \count($files)) { @@ -260,6 +260,6 @@ abstract class GenericClusterController extends GenericApiController } } - return Errors::NotFound('preview from list'); + return Errors::NotFound('preview from photos list'); } } diff --git a/lib/Controller/PeopleControllerUtils.php b/lib/Controller/PeopleControllerUtils.php index 52ef08fd..b6ea3b8b 100644 --- a/lib/Controller/PeopleControllerUtils.php +++ b/lib/Controller/PeopleControllerUtils.php @@ -70,7 +70,7 @@ trait PeopleControllerUtils * * @throws \Exception if file could not be used */ - private function cropFace($file, array $object, float $padding) + private function cropFace($file, array $photo, float $padding) { /** @var \Imagick */ $image = null; @@ -96,10 +96,10 @@ trait PeopleControllerUtils $image->setInterlaceScheme(\Imagick::INTERLACE_PLANE); // Crop image - $dw = (float) $object['width']; - $dh = (float) $object['height']; - $dcx = (float) $object['x'] + (float) $object['width'] / 2; - $dcy = (float) $object['y'] + (float) $object['height'] / 2; + $dw = (float) $photo['width']; + $dh = (float) $photo['height']; + $dcx = (float) $photo['x'] + (float) $photo['width'] / 2; + $dcy = (float) $photo['y'] + (float) $photo['height'] / 2; $faceDim = max($dw * $iw, $dh * $ih) * $padding; $image->cropImage( (int) $faceDim, diff --git a/lib/Controller/PeopleRecognizeController.php b/lib/Controller/PeopleRecognizeController.php index 82b7bb1d..e38bf219 100644 --- a/lib/Controller/PeopleRecognizeController.php +++ b/lib/Controller/PeopleRecognizeController.php @@ -42,18 +42,18 @@ class PeopleRecognizeController extends GenericClusterController return $this->timelineQuery->getPeopleRecognize($this->root, $this->getUID()); } - protected function getFiles(string $name, ?int $limit = null): array + protected function getPhotos(string $name, ?int $limit = null): array { - return $this->timelineQuery->getPeopleRecognizeFiles((int) $name, $this->root, $limit) ?? []; + return $this->timelineQuery->getPeopleRecognizePhotos((int) $name, $this->root, $limit) ?? []; } - protected function sortFilesForPreview(array &$files) + protected function sortPhotosForPreview(array &$photos) { - $this->sortByScores($files); + $this->sortByScores($photos); } - protected function getPreviewBlob($file, $object): array + protected function getPreviewBlob($file, $photo): array { - return $this->cropFace($file, $object, 1.5); + return $this->cropFace($file, $photo, 1.5); } } diff --git a/lib/Controller/PlacesController.php b/lib/Controller/PlacesController.php index f48393a6..11c278ee 100644 --- a/lib/Controller/PlacesController.php +++ b/lib/Controller/PlacesController.php @@ -40,8 +40,8 @@ class PlacesController extends GenericClusterController return $this->timelineQuery->getPlaces($this->root); } - protected function getFiles(string $name, ?int $limit = null): array + protected function getPhotos(string $name, ?int $limit = null): array { - return $this->timelineQuery->getPlaceFiles((int) $name, $this->root, $limit) ?? []; + return $this->timelineQuery->getPlacePhotos((int) $name, $this->root, $limit) ?? []; } } diff --git a/lib/Controller/TagsController.php b/lib/Controller/TagsController.php index e553bebf..6b0a2a5e 100644 --- a/lib/Controller/TagsController.php +++ b/lib/Controller/TagsController.php @@ -77,8 +77,8 @@ class TagsController extends GenericClusterController return $this->timelineQuery->getTags($this->root); } - protected function getFiles(string $name, ?int $limit = null): array + protected function getPhotos(string $name, ?int $limit = null): array { - return $this->timelineQuery->getTagFiles($name, $this->root, $limit) ?? []; + return $this->timelineQuery->getTagPhotos($name, $this->root, $limit) ?? []; } } diff --git a/lib/Db/TimelineQueryAlbums.php b/lib/Db/TimelineQueryAlbums.php index 03d68768..37c4171f 100644 --- a/lib/Db/TimelineQueryAlbums.php +++ b/lib/Db/TimelineQueryAlbums.php @@ -256,9 +256,9 @@ trait TimelineQueryAlbums } /** - * Get full list of fileIds in album. + * Get list of photos in album. */ - public function getAlbumFiles(int $albumId, ?int $limit) + public function getAlbumPhotos(int $albumId, ?int $limit) { $query = $this->connection->getQueryBuilder(); $query->select('file_id')->from('photos_albums_files', 'paf')->where( diff --git a/lib/Db/TimelineQueryPeopleRecognize.php b/lib/Db/TimelineQueryPeopleRecognize.php index 36024ce3..d48c7487 100644 --- a/lib/Db/TimelineQueryPeopleRecognize.php +++ b/lib/Db/TimelineQueryPeopleRecognize.php @@ -105,7 +105,7 @@ trait TimelineQueryPeopleRecognize return $faces; } - public function getPeopleRecognizeFiles(int $id, TimelineRoot $root, ?int $limit): array + public function getPeopleRecognizePhotos(int $id, TimelineRoot $root, ?int $limit): array { $query = $this->connection->getQueryBuilder(); diff --git a/lib/Db/TimelineQueryPlaces.php b/lib/Db/TimelineQueryPlaces.php index b9fd7aa0..1971fbb4 100644 --- a/lib/Db/TimelineQueryPlaces.php +++ b/lib/Db/TimelineQueryPlaces.php @@ -54,7 +54,7 @@ trait TimelineQueryPlaces return $places; } - public function getPlaceFiles(int $id, TimelineRoot $root, ?int $limit) + public function getPlacePhotos(int $id, TimelineRoot $root, ?int $limit): array { $query = $this->connection->getQueryBuilder(); @@ -69,20 +69,12 @@ trait TimelineQueryPlaces // WHERE these photos are in the user's requested folder recursively $query = $this->joinFilecache($query, $root, true, false); - // MAX number of files + // MAX number of photos if (null !== $limit) { $query->setMaxResults($limit); } - // FETCH tag previews - $cursor = $this->executeQueryWithCTEs($query); - $ans = $cursor->fetchAll(); - - // Post-process - foreach ($ans as &$row) { - $row['fileid'] = (int) $row['fileid']; - } - - return $ans; + // FETCH tag photos + return $this->executeQueryWithCTEs($query)->fetchAll(); } } diff --git a/lib/Db/TimelineQueryTags.php b/lib/Db/TimelineQueryTags.php index 9714d261..387e91c2 100644 --- a/lib/Db/TimelineQueryTags.php +++ b/lib/Db/TimelineQueryTags.php @@ -77,7 +77,7 @@ trait TimelineQueryTags return $tags; } - public function getTagFiles(string $tagName, TimelineRoot $root, ?int $limit) + public function getTagPhotos(string $tagName, TimelineRoot $root, ?int $limit) { $query = $this->connection->getQueryBuilder(); $tagId = $this->getSystemTagId($query, $tagName); @@ -105,15 +105,7 @@ trait TimelineQueryTags $query->setMaxResults($limit); } - // FETCH tag previews - $cursor = $this->executeQueryWithCTEs($query); - $ans = $cursor->fetchAll(); - - // Post-process - foreach ($ans as &$row) { - $row['fileid'] = (int) $row['fileid']; - } - - return $ans; + // FETCH tag photos + return $this->executeQueryWithCTEs($query)->fetchAll(); } }