clusters: add type to response
Signed-off-by: Varun Patil <varunpatil@ucla.edu>pull/563/head
parent
24615ddd0d
commit
92781df0c1
|
@ -75,11 +75,11 @@ class Application extends App implements IBootstrap
|
|||
$context->registerEventListener(NodeDeletedEvent::class, PostDeleteListener::class);
|
||||
|
||||
// Register clusters backends
|
||||
ClustersBackend\Manager::register('albums', ClustersBackend\AlbumsBackend::class);
|
||||
ClustersBackend\Manager::register('tags', ClustersBackend\TagsBackend::class);
|
||||
ClustersBackend\Manager::register('places', ClustersBackend\PlacesBackend::class);
|
||||
ClustersBackend\Manager::register('recognize', ClustersBackend\RecognizeBackend::class);
|
||||
ClustersBackend\Manager::register('facerecognition', ClustersBackend\FaceRecognitionBackend::class);
|
||||
ClustersBackend\AlbumsBackend::register();
|
||||
ClustersBackend\TagsBackend::register();
|
||||
ClustersBackend\PlacesBackend::register();
|
||||
ClustersBackend\RecognizeBackend::register();
|
||||
ClustersBackend\FaceRecognitionBackend::register();
|
||||
}
|
||||
|
||||
public function boot(IBootContext $context): void
|
||||
|
|
|
@ -41,11 +41,16 @@ class AlbumsBackend extends Backend
|
|||
$this->request = $request;
|
||||
}
|
||||
|
||||
public function appName(): string
|
||||
public static function appName(): string
|
||||
{
|
||||
return 'Albums';
|
||||
}
|
||||
|
||||
public static function clusterType(): string
|
||||
{
|
||||
return 'albums';
|
||||
}
|
||||
|
||||
public function isEnabled(): bool
|
||||
{
|
||||
return Util::albumsIsEnabled();
|
||||
|
@ -105,6 +110,11 @@ class AlbumsBackend extends Backend
|
|||
return array_values($list);
|
||||
}
|
||||
|
||||
public static function getClusterId(array $cluster)
|
||||
{
|
||||
return $cluster['album_id'];
|
||||
}
|
||||
|
||||
public function getPhotos(string $name, ?int $limit = null): array
|
||||
{
|
||||
// Get album
|
||||
|
|
|
@ -31,7 +31,12 @@ abstract class Backend
|
|||
* A human-readable name for the app.
|
||||
* Used for error messages.
|
||||
*/
|
||||
abstract public function appName(): string;
|
||||
abstract static public function appName(): string;
|
||||
|
||||
/**
|
||||
* Get name of the cluster type.
|
||||
*/
|
||||
abstract static public function clusterType(): string;
|
||||
|
||||
/**
|
||||
* Whether the app is enabled for the current user.
|
||||
|
@ -58,6 +63,11 @@ abstract class Backend
|
|||
*/
|
||||
abstract public function getClusters(): array;
|
||||
|
||||
/**
|
||||
* Get a cluster ID for the given cluster.
|
||||
*/
|
||||
abstract static public function getClusterId(array $cluster);
|
||||
|
||||
/**
|
||||
* Get a list of photos with any extra parameters for the given cluster
|
||||
* Used for preview generation and download.
|
||||
|
@ -112,4 +122,12 @@ abstract class Backend
|
|||
{
|
||||
return (int) $photo['fileid'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the backend. Do not override.
|
||||
*/
|
||||
public static function register(): void
|
||||
{
|
||||
Manager::register(static::clusterType(), static::class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,11 +46,16 @@ class FaceRecognitionBackend extends Backend
|
|||
$this->config = $config;
|
||||
}
|
||||
|
||||
public function appName(): string
|
||||
public static function appName(): string
|
||||
{
|
||||
return 'Face Recognition';
|
||||
}
|
||||
|
||||
public static function clusterType(): string
|
||||
{
|
||||
return 'facerecognition';
|
||||
}
|
||||
|
||||
public function isEnabled(): bool
|
||||
{
|
||||
return Util::facerecognitionIsInstalled()
|
||||
|
@ -134,6 +139,11 @@ class FaceRecognitionBackend extends Backend
|
|||
return $faces;
|
||||
}
|
||||
|
||||
public static function getClusterId(array $cluster)
|
||||
{
|
||||
return $cluster['id'];
|
||||
}
|
||||
|
||||
public function getPhotos(string $name, ?int $limit = null): array
|
||||
{
|
||||
$query = $this->tq->getBuilder();
|
||||
|
|
|
@ -38,11 +38,16 @@ class PlacesBackend extends Backend
|
|||
$this->request = $request;
|
||||
}
|
||||
|
||||
public function appName(): string
|
||||
public static function appName(): string
|
||||
{
|
||||
return 'Places';
|
||||
}
|
||||
|
||||
public static function clusterType(): string
|
||||
{
|
||||
return 'places';
|
||||
}
|
||||
|
||||
public function isEnabled(): bool
|
||||
{
|
||||
return Util::placesGISType() > 0;
|
||||
|
@ -92,6 +97,11 @@ class PlacesBackend extends Backend
|
|||
return $places;
|
||||
}
|
||||
|
||||
public static function getClusterId(array $cluster)
|
||||
{
|
||||
return $cluster['osm_id'];
|
||||
}
|
||||
|
||||
public function getPhotos(string $name, ?int $limit = null): array
|
||||
{
|
||||
$query = $this->tq->getBuilder();
|
||||
|
|
|
@ -40,11 +40,16 @@ class RecognizeBackend extends Backend
|
|||
$this->request = $request;
|
||||
}
|
||||
|
||||
public function appName(): string
|
||||
public static function appName(): string
|
||||
{
|
||||
return 'Recognize';
|
||||
}
|
||||
|
||||
public static function clusterType(): string
|
||||
{
|
||||
return 'recognize';
|
||||
}
|
||||
|
||||
public function isEnabled(): bool
|
||||
{
|
||||
return Util::recognizeIsEnabled();
|
||||
|
@ -162,6 +167,11 @@ class RecognizeBackend extends Backend
|
|||
return $faces;
|
||||
}
|
||||
|
||||
public static function getClusterId(array $cluster)
|
||||
{
|
||||
return $cluster['id'];
|
||||
}
|
||||
|
||||
public function getPhotos(string $name, ?int $limit = null): array
|
||||
{
|
||||
$query = $this->tq->getBuilder();
|
||||
|
|
|
@ -39,11 +39,16 @@ class TagsBackend extends Backend
|
|||
$this->request = $request;
|
||||
}
|
||||
|
||||
public function appName(): string
|
||||
public static function appName(): string
|
||||
{
|
||||
return 'Tags';
|
||||
}
|
||||
|
||||
public static function clusterType(): string
|
||||
{
|
||||
return 'tags';
|
||||
}
|
||||
|
||||
public function isEnabled(): bool
|
||||
{
|
||||
return Util::tagsIsEnabled();
|
||||
|
@ -101,6 +106,11 @@ class TagsBackend extends Backend
|
|||
return $tags;
|
||||
}
|
||||
|
||||
public static function getClusterId(array $cluster)
|
||||
{
|
||||
return $cluster['name'];
|
||||
}
|
||||
|
||||
public function getPhotos(string $name, ?int $limit = null): array
|
||||
{
|
||||
$query = $this->tq->getBuilder();
|
||||
|
|
|
@ -47,6 +47,12 @@ class ClustersController extends GenericApiController
|
|||
|
||||
$list = $this->backend->getClusters();
|
||||
|
||||
// Set cluster_id and cluster_type for each cluster
|
||||
foreach ($list as &$cluster) {
|
||||
$cluster['cluster_id'] = $this->backend->getClusterId($cluster);
|
||||
$cluster['cluster_type'] = $this->backend->clusterType();
|
||||
}
|
||||
|
||||
return new JSONResponse($list, Http::STATUS_OK);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue