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);
}
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) ?? [];
}
}

View File

@ -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');
}
}

View File

@ -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,

View File

@ -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);
}
}

View File

@ -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) ?? [];
}
}

View File

@ -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) ?? [];
}
}

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->select('file_id')->from('photos_albums_files', 'paf')->where(

View File

@ -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();

View File

@ -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();
}
}

View File

@ -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();
}
}