refactor: files --> photos

Signed-off-by: Varun Patil <varunpatil@ucla.edu>
pull/563/head
Varun Patil 2023-03-22 16:55:20 -07:00
parent 094a4b32d7
commit 3f825073dc
10 changed files with 52 additions and 68 deletions

View File

@ -75,7 +75,7 @@ class AlbumsController extends GenericClusterController
return array_values($list); return array_values($list);
} }
protected function getFiles(string $name, ?int $limit = null): array protected function getPhotos(string $name, ?int $limit = null): array
{ {
// Get album // Get album
$album = $this->timelineQuery->getAlbumIfAllowed($this->getUID(), $name); $album = $this->timelineQuery->getAlbumIfAllowed($this->getUID(), $name);
@ -86,6 +86,6 @@ class AlbumsController extends GenericClusterController
// Get files // Get files
$id = (int) $album['album_id']; $id = (int) $album['album_id'];
return $this->timelineQuery->getAlbumFiles($id, $limit) ?? []; return $this->timelineQuery->getAlbumPhotos($id, $limit) ?? [];
} }
} }

View File

@ -69,19 +69,19 @@ abstract class GenericClusterController extends GenericApiController
try { try {
$this->init(); $this->init();
// Get list of some files in this cluster // Get list of some photos in this cluster
$files = $this->getFiles($name, 8); $photos = $this->getPhotos($name, 8);
// If no files found then return 404 // If no photos found then return 404
if (0 === \count($files)) { if (0 === \count($photos)) {
return new JSONResponse([], Http::STATUS_NOT_FOUND); return new JSONResponse([], Http::STATUS_NOT_FOUND);
} }
// Put the files in the correct order // Put the photos in the correct order
$this->sortFilesForPreview($files); $this->sortPhotosForPreview($photos);
// Get preview from image list // Get preview from image list
return $this->getPreviewFromImageList($files); return $this->getPreviewFromPhotoList($photos);
} catch (HttpResponseException $e) { } catch (HttpResponseException $e) {
return $e->response; return $e->response;
} catch (\Exception $e) { } catch (\Exception $e) {
@ -102,8 +102,8 @@ abstract class GenericClusterController extends GenericApiController
$this->init(); $this->init();
// Get list of all files in this cluster // Get list of all files in this cluster
$files = $this->getFiles($name); $photos = $this->getPhotos($name);
$fileIds = array_map([$this, 'getFileId'], $files); $fileIds = array_map([$this, 'getFileId'], $photos);
// Get download handle // Get download handle
$filename = $this->clusterName($name); $filename = $this->clusterName($name);
@ -134,13 +134,13 @@ abstract class GenericClusterController extends GenericApiController
abstract protected function getClusters(): array; 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. * Used for preview generation and download.
* *
* @param string $name Identifier for the cluster * @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. * 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. * 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. * Perform any post processing and get the blob from the preview file.
* *
* @param \OCP\Files\SimpleFS\ISimpleFile $file * @param \OCP\Files\SimpleFS\ISimpleFile $file Preview file
* @param array $object The file object * @param array $photo Photo object
* *
* @return [Blob, mimetype] of data * @return [Blob, mimetype] of data
*/ */
protected function getPreviewBlob($file, $object): array protected function getPreviewBlob($file, $photo): array
{ {
return [$file->getContent(), $file->getMimeType()]; 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 // Get preview manager
$previewManager = \OC::$server->get(\OCP\IPreview::class); $previewManager = \OC::$server->get(\OCP\IPreview::class);
// Try to get a preview // Try to get a preview
$userFolder = $this->rootFolder->getUserFolder($this->getUID()); $userFolder = $this->rootFolder->getUserFolder($this->getUID());
foreach ($list as $img) { foreach ($photos as $img) {
// Get the file // Get the file
$files = $userFolder->getById($this->getFileId($img)); $files = $userFolder->getById($this->getFileId($img));
if (0 === \count($files)) { 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');
} }
} }

View File

@ -70,7 +70,7 @@ trait PeopleControllerUtils
* *
* @throws \Exception if file could not be used * @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 */ /** @var \Imagick */
$image = null; $image = null;
@ -96,10 +96,10 @@ trait PeopleControllerUtils
$image->setInterlaceScheme(\Imagick::INTERLACE_PLANE); $image->setInterlaceScheme(\Imagick::INTERLACE_PLANE);
// Crop image // Crop image
$dw = (float) $object['width']; $dw = (float) $photo['width'];
$dh = (float) $object['height']; $dh = (float) $photo['height'];
$dcx = (float) $object['x'] + (float) $object['width'] / 2; $dcx = (float) $photo['x'] + (float) $photo['width'] / 2;
$dcy = (float) $object['y'] + (float) $object['height'] / 2; $dcy = (float) $photo['y'] + (float) $photo['height'] / 2;
$faceDim = max($dw * $iw, $dh * $ih) * $padding; $faceDim = max($dw * $iw, $dh * $ih) * $padding;
$image->cropImage( $image->cropImage(
(int) $faceDim, (int) $faceDim,

View File

@ -42,18 +42,18 @@ class PeopleRecognizeController extends GenericClusterController
return $this->timelineQuery->getPeopleRecognize($this->root, $this->getUID()); 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);
} }
} }

View File

@ -40,8 +40,8 @@ class PlacesController extends GenericClusterController
return $this->timelineQuery->getPlaces($this->root); 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) ?? [];
} }
} }

View File

@ -77,8 +77,8 @@ class TagsController extends GenericClusterController
return $this->timelineQuery->getTags($this->root); 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) ?? [];
} }
} }

View File

@ -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 = $this->connection->getQueryBuilder();
$query->select('file_id')->from('photos_albums_files', 'paf')->where( $query->select('file_id')->from('photos_albums_files', 'paf')->where(

View File

@ -105,7 +105,7 @@ trait TimelineQueryPeopleRecognize
return $faces; 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(); $query = $this->connection->getQueryBuilder();

View File

@ -54,7 +54,7 @@ trait TimelineQueryPlaces
return $places; 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(); $query = $this->connection->getQueryBuilder();
@ -69,20 +69,12 @@ trait TimelineQueryPlaces
// WHERE these photos are in the user's requested folder recursively // WHERE these photos are in the user's requested folder recursively
$query = $this->joinFilecache($query, $root, true, false); $query = $this->joinFilecache($query, $root, true, false);
// MAX number of files // MAX number of photos
if (null !== $limit) { if (null !== $limit) {
$query->setMaxResults($limit); $query->setMaxResults($limit);
} }
// FETCH tag previews // FETCH tag photos
$cursor = $this->executeQueryWithCTEs($query); return $this->executeQueryWithCTEs($query)->fetchAll();
$ans = $cursor->fetchAll();
// Post-process
foreach ($ans as &$row) {
$row['fileid'] = (int) $row['fileid'];
}
return $ans;
} }
} }

View File

@ -77,7 +77,7 @@ trait TimelineQueryTags
return $tags; return $tags;
} }
public function getTagFiles(string $tagName, TimelineRoot $root, ?int $limit) public function getTagPhotos(string $tagName, TimelineRoot $root, ?int $limit)
{ {
$query = $this->connection->getQueryBuilder(); $query = $this->connection->getQueryBuilder();
$tagId = $this->getSystemTagId($query, $tagName); $tagId = $this->getSystemTagId($query, $tagName);
@ -105,15 +105,7 @@ trait TimelineQueryTags
$query->setMaxResults($limit); $query->setMaxResults($limit);
} }
// FETCH tag previews // FETCH tag photos
$cursor = $this->executeQueryWithCTEs($query); return $this->executeQueryWithCTEs($query)->fetchAll();
$ans = $cursor->fetchAll();
// Post-process
foreach ($ans as &$row) {
$row['fileid'] = (int) $row['fileid'];
}
return $ans;
} }
} }